last part of the chat script
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

last part of the chat script

Started by Habatsu, 08 March, 2005, 13:44:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Habatsu

this is the  last part of the chat stats..



   for a,b in ChatUserStat do
      if (ChatUserStat[a]>userkey1) then
         user10=user9
         userkey10=userkey9
         user9=user8
         userkey9=userkey8
         user8=user7
         userkey8=userkey7
         user7=user6
         userkey7=userkey6
         user6=user5
         userkey6=userkey5
         user5=user4
         userkey5=userkey4
         user4=user3
         userkey4=userkey3
         user3=user2
         userkey3=userkey2
         user2=user1
         userkey2=userkey1
         user1=a
         userkey1=ChatUserStat[a]
      else
         if (ChatUserStat[a]>userkey2) then
            user10=user9
            userkey10=userkey9
            user9=user8
            userkey9=userkey8
            user8=user7
            userkey8=userkey7
            user7=user6
            userkey7=userkey6
            user6=user5
            userkey6=userkey5
            user5=user4
            userkey5=userkey4
            user4=user3
            userkey4=userkey3
            user3=user2
            userkey3=userkey2
            user2=a
            userkey2=ChatUserStat[a]
         else
            if (ChatUserStat[a]>userkey3) then
               user10=user9
               userkey10=userkey9
               user9=user8
               userkey9=userkey8
               user8=user7
               userkey8=userkey7
               user7=user6
               userkey7=userkey6
               user6=user5
               userkey6=userkey5
               user5=user4
               userkey5=userkey4
               user4=user3
               userkey4=userkey3
               user3=a
               userkey3=ChatUserStat[a]
            else
               if (ChatUserStat[a]>userkey4) then
                  user10=user9
                  userkey10=userkey9
                  user9=user8
                  userkey9=userkey8
                  user8=user7
                  userkey8=userkey7
                  user7=user6
                  userkey7=userkey6
                  user6=user5
                  userkey6=userkey5
                  user5=user4
                  userkey5=userkey4
                  user4=a
                  userkey4=ChatUserStat[a]
               else
                  if (ChatUserStat[a]>userkey5) then
                     user10=user9
                     userkey10=userkey9
                     user9=user8
                     userkey9=userkey8
                     user8=user7
                     userkey8=userkey7
                     user7=user6
                     userkey7=userkey6
                     user6=user5
                     userkey6=userkey5
                     user5=a
                     userkey5=ChatUserStat[a]
                  else
                     if (ChatUserStat[a]>userkey6) then
                        user10=user9
                        userkey10=userkey9
                        user9=user8
                        userkey9=userkey8
                        user8=user7
                        userkey8=userkey7
                        user7=user6
                        userkey7=userkey6
                        user6=a
                        userkey6=ChatUserStat[a]
                     else
                        if (ChatUserStat[a]>userkey6) then
                           user10=user9
                           userkey10=userkey9
                           user9=user8
                           userkey9=userkey8
                           user8=user7
                           userkey8=userkey7
                           user7=a
                           userkey7=ChatUserStat[a]
                        else
                           if (ChatUserStat[a]>userkey6) then
                              user10=user9
                              userkey10=userkey9
                              user9=user8
                              userkey9=userkey8
                              user8=a
                              userkey8=ChatUserStat[a]
                           else
                              if (ChatUserStat[a]>userkey6) then
                                 user10=user9
                                 userkey10=userkey9
                                 user9=a
                                 userkey9=ChatUserStat[a]
                              else
                                 if (ChatUserStat[a]>userkey6) then
                                    user10=a
                                    userkey10=ChatUserStat[a]
                                 end
                              end
                           end
                        end
                     end
                  end
               end
            end
         end
      end
   end

   userstats1 = ""
   userstats2 = ""
   userstats3 = ""
   userstats4 = ""
   userstats5 = ""
   userstats6 = ""
   userstats7 = ""
   userstats8 = ""
   userstats9 = ""
   userstats10 = ""

   if (user1~=nil) then
      userstats1 = ("* 1.\t"..ChatUserStat[user1]..":\t"..user1)
   end

   if (user2~=nil) then
      userstats2 = ("\r\n* 2.\t"..ChatUserStat[user2]..":\t"..user2)
   end

   if (user3~=nil) then
      userstats3 = ("\r\n* 3.\t"..ChatUserStat[user3]..":\t"..user3)
   end

   if (user4~=nil) then
      userstats4 = ("\r\n* 4.\t"..ChatUserStat[user4]..":\t"..user4)
   end

   if (user5~=nil) then
      userstats5 = ("\r\n* 5.\t"..ChatUserStat[user5]..":\t"..user5)
   end

   if (user6~=nil) then
      userstats6 = ("\r\n* 6.\t"..ChatUserStat[user6]..":\t"..user6)
   end

   if (user7~=nil) then
      userstats7 = ("\r\n* 7.\t"..ChatUserStat[user7]..":\t"..user7)
   end

   if (user8~=nil) then
      userstats8 = ("\r\n* 8.\t"..ChatUserStat[user8]..":\t"..user8)
   end

   if (user9~=nil) then
      userstats9 = ("\r\n* 9.\t"..ChatUserStat[user9]..":\t"..user9)
   end

   if (user10~=nil) then
      userstats10 = ("\r\n*10.\t"..ChatUserStat[user10]..":\t"..user10)
   end

   userstats = userstats1..userstats2..userstats3..userstats4..userstats5..userstats6..userstats7..userstats8..userstats9..userstats10

   chars,words,smilies=nil,nil,nil

   if user.bOperator then
      local table = getitem(tabOpStats, user.sName)
      if not table then table = mkOpStats(user) end
      local stat = getkey(table, "stats")
      s, e, chars, words, smilies = strfind(stat, "(%d+)|(%d+)|(%d+)", 1)
   else
      local table = getitem(tabUserStats, user.sName)
      if not table then table = mkUserStats(user) end
      local stat = getkey(table, "stats")
      s, e, chars, words, smilies = strfind(stat, "(%d+)|(%d+)|(%d+)", 1)
   end

   if pm == 0 then
      if user.bOperator then
         SendToAll( "Stats","\r\nTop 5 ops posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..opstats.."\r\nTop 10 users posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..userstats.."\r\n\r\nUr current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
      else
         user:SendPM(Bot,"\r\nTop 5 ops posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..opstats.."\r\nTop 10 users posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..userstats.."\r\n\r\nUr current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
         SendToAll(Bot,"Ur current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
      end
   elseif pm == 1 then
      user:SendPM(Bot,"\r\nTop 5 ops posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..opstats.."\r\nTop 10 users posters in this hub : \r\n* Nr.\tPosts:\tName\t\r\n"..userstats.."\r\n\r\nUr current Stats:\r\n"..user.sName.." "..chars.." characters "..words.." words "..smilies.." smilies")
   end
end

--------- Tables Functions ---------

function mkOpStats(user)
   local stats = { sName = user.sName, tItems = {n=0} }
   putvalue(stats.tItems, "stats", "0|0|0" )
   putitem(tabOpStats, stats) return stats
end

function mkUserStats(user)
   local stats = { sName = user.sName, tItems = {n=0} }
   putvalue(stats.tItems, "stats", "0|0|0" )
   putitem(tabUserStats, stats) return stats
end

function getvalue(table, name)
   local id = getid(table, name)
   if id then
      return table[id].sValue
   end
end

function getid(table, name)
   return foreachi(table, function(id, item) if item.sName == %name then return id end end)
end

function cntargs(str, rule, len)
   local tmp = getargs(str, rule, len) return tmp.n
end

function getargs(str, rule, len)
   local tmp = {n=0}
   gsub(str, rule, function(s) if strlen(s) >= %len then tinsert(%tmp, s) end end)
   return tmp
end

function getkey(table,  key)
   local id = getid(table.tItems, key)
   assert(id, "getkey() ["..table.sName.."] "..key)
   return table.tItems[id].sValue
end

function getsection(table, section)
   local id = getid(table, section)
   assert(id, "getkey() ["..section.."]")
   return table[id]
end

function getitem(table, name)
   local id = getid(table, name)
   if id then return table[id] end
end

function parsekeys(keys)
   local table = {n=0}
   gsub(keys, "%s*(%C-)=(%C*)%c*", function(key, value) putvalue(%table, key, value) end)
   return table
end

function putitem(table, item)
   if not item then return end
   local id = getid(table, item.sName)
   if id then
      table[id] = item
   else
      tinsert(table, item)
      id = table.n
   end return id
end

function putvalue(table, name, value)
   if not value then return end
   local id = getid(table, name)
   if id then
      table[id].sValue = value
   else
      tinsert(table, { sName = name, sValue = value })
      id = table.n
   end return id
end

function writeINI(fName, struc)
   if not struc then return end
   local fHandle = openfile(fName, "w")
   if fHandle then for i = 1, struc.n do
      local section = struc write(fHandle, "\n["..section.sName.."]\n")
      for j = 1, section.tItems.n do write(fHandle, section.tItems[j].sName.."="..section.tItems[j].sValue.."\n") end
      write(fHandle, "\n")
   end closefile(fHandle) end
end

function parseINI(fName)
   local table = {n=0}
   local config = readfile(fName)
   assert(config, "parseINI() "..fName)
   local s, e, sec = strfind(config, "%[(%S+)%]%c", 1)
   while sec do local section = { sName = sec, tItems = {n=0} }
      s, ke, keys, sec = strfind(config, "(.-)%c%[(%S+)%]%c", e+1)
      if not s then s, ke, keys = strfind(config, "(.*)", e+1) else e = ke end
      section.tItems = parsekeys(keys) putitem(table, section)
   end return table
end

function InitTable(fName,ctable,tname)
   local config = readfile(fName)
   local s, e, sec = strfind(config, "%[(%S+)%]%c", 1)
      if sec then
         local table = getitem(ctable, sec)
         local stats = getvalue(table.tItems, "stats")
         local s, e, chars = strfind(stats, "(%d+)")
         tname[sec]=tonumber(chars)
      end
   while sec do local section = { sName = sec, tItems = {n=0} }
      s, ke, keys, sec = strfind(config, "(.-)%c%[(%S+)%]%c", e+1)
      if sec then
         local table = getitem(ctable, sec)
         local stats = getvalue(table.tItems, "stats")
         local s, e, chars = strfind(stats, "(%d+)")
         tname[sec]=tonumber(chars)
      end
      if not s then
         s, ke, keys = strfind(config, "(.*)", e+1)
      else
         e = ke
      end
   end
end

function cntsmilies(str)
   local tmp = {n=0}
      gsub(str, "(["..smEyes.."])(["..smNose.."]?)(["..smMouth.."])", function(e, n, m) tinsert(%tmp, e..n..m) end)
   gsub(str, "(["..smMouth.."])(["..smNose.."]?)(["..smEyes.."])", function(m, n, e) tinsert(%tmp, m..n..e) end)
   return tmp.n
end

function readfile(fName)
   local fHandle = openfile(fName, "r")
   if fHandle then local file = read(fHandle, "*a") closefile(fHandle) return file end
end

function iscommand(str)
   return strsub(str, 1, 1) == "!" or strsub(str, 1, 1) == "?" or strsub(str, 1, 1) == "+" or strsub(str, 1, 1) == "#"
end

function OnTimer()
   writeINI("Stats/OpStats.ini", tabOpStats)
   writeINI("Stats/UserStats.ini", tabUserStats)
end


-----------------------------------------------------------------------
 Thanx,,, if someone can config this .
:]  haba :]

SMF spam blocked by CleanTalk