Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. --| Chat Logger for YnHub by hjpotter92 and Brick
  2. --| Please add this script to be run in DCDM++
  3. --| Client. Then chose to connect the client to
  4. --| any YnHub maintained hub address. :)
  5.  
  6. dofile("scripts/libsimplepickle.lua")
  7.  
  8. function bbsort(tbl, tabletwo)
  9.     for i = 1, table.getn( tbl ) do --> array start to end
  10.         for j = 2, table.getn( tbl ) do
  11.             if tabletwo[tbl[j]] > tabletwo[tbl[j-1]] then
  12.                 temp = tbl[j-1]
  13.                 tbl[j-1] = tbl[j]
  14.                 tbl[j] = temp
  15.             end
  16.         end
  17.     end
  18.     return
  19. end
  20.  
  21. function tokens( str )
  22.     local ret = {}
  23.     string.gsub( str, "([^%s]+)", function( s ) table.insert( ret, s ) end )
  24.     return ret
  25. end
  26.  
  27. if not count then
  28.     count ={}
  29. end
  30.  
  31. local p = io.open( "scripts/ChatLogs/count.txt", "r" )
  32.  
  33. if p then
  34.     dofile("scripts/ChatLogs/count.txt")
  35.     p:close()
  36. end
  37.  
  38. local f = io.open( "scripts/ChatLogs/list.txt", "r" )
  39.     if f then
  40.     dofile("scripts/Chatlogs/list.txt")
  41.     f:close()
  42. end
  43.  
  44. local ar={}
  45.  
  46. for n in pairs(count) do table.insert(ar, n) end
  47.  
  48. bbsort(ar,count)
  49.  
  50. dcpp:setListener( "chat", "logger",
  51.     function( hub,user,text)
  52.         local name = "scripts/ChatLogs/"..os.date( "%Y" ).."/"..os.date( "%m" ).."/"..os.date( "%d" ).."_"..os.date( "%m" ).."_"..os.date( "%Y" )..".txt"
  53.         local f = io.open (name,"a")
  54.         local user =user:getNick()
  55.         if string.len( text ) < 800 then
  56.             local a= "["..os.date("%I")..":"..os.date("%M").." "..os.date("%p").."] ".."<"..user.."> "..text
  57.             f:write(a.."\n")
  58.                 f:flush()
  59.             f:close()
  60.         end
  61.         if user ~= "-Hub-" then
  62.             if not count[user] then
  63.                 count[user] =0
  64.                 table.insert(ar,user)
  65.             end
  66.             count[user]  = count[user] + 1
  67.         end
  68.         local pos
  69.         for i,v in pairs(ar) do
  70.             if v == user then
  71.             pos =i
  72.             end
  73.         end
  74.         local tempVar = count[user]
  75.         local cent = tempVar - math.floor( tempVar/500 ) * 500
  76.         if cent == 0 then
  77.             hub:sendChat(".say hjpotter92 The user "..user.." just punched 500th line on mainchat. The current count being: "..count[user] )
  78.         end
  79.         if pos > 1 then
  80.             if count[ar[pos]] > count[ar[pos-1]] then
  81.                 local temp = ar[pos-1]
  82.                 ar[pos-1] = ar[pos]
  83.                 ar[pos] = temp
  84.             end
  85.         end
  86.         pickle.store("scripts/ChatLogs/count.txt", {count=count} )
  87.         pickle.store("scripts/list.txt", {ar=ar} )
  88.     end
  89. )
  90.  
  91. dcpp:setListener( "pm", "response",
  92.     function( hub, user, text )
  93.         local s = string.lower( text )
  94.         local params = tokens( s )
  95.         if string.sub( s, 1, 1 )~="+" then
  96.             user:sendPrivMsgFmt( "Wrong method to call. Use \"+help\" as command.", 1 )
  97.             return
  98.         end
  99.         if string.find( s, "+score" ) then
  100.             user:sendPrivMsgFmt( "\r\t"..user:getNick()..", your score is "..count[user:getNick()]..".\n\tBot designed by Brick and hjpotter92.", 1 )
  101.         elseif string.find( s, "+help" ) then
  102.             local h = io.open( "scripts/ChatLogs/chatLogHelp.txt", "r" )
  103.             local totcounts = h:read( "*a" )
  104.             h:close()
  105.             user:sendPrivMsgFmt( totcounts, 1)
  106.         elseif string.find( s, "+tcount" ) then
  107.             local cnt = io.open( "scripts/ChatLogs/count.txt", "r" )
  108.             local fileData = cnt:read( "*a" )
  109.             cnt:close()
  110.             user:sendPrivMsgFmt( fileData, 1)
  111.         elseif string.find( s,"+top" ) then
  112.             local listtop = " "
  113.             local cnted = params[2]
  114.             if params[2] then
  115.                 for i=1, params[2] do
  116.                     listtop = listtop.."\n\t "..i..". "..ar[i].." -> "..count[ ar[i] ]
  117.                 end
  118.             else
  119.                 for i=1, 5 do
  120.                     listtop = listtop.."\n\t "..i..". "..ar[i].." -> "..count[ ar[i] ]
  121.                 end
  122.             end
  123.             user:sendPrivMsgFmt( listtop, 1 )
  124.         end
  125.     end
  126. )
  127.  
  128. DC():PrintDebug( "  ** Loaded Chat Log.lua **" )