--| Chat Logger for YnHub by hjpotter92 and Brick
--| Please add this script to be run in DCDM++
--| Client. Then chose to connect the client to
--| any YnHub maintained hub address. :)
dofile("scripts/libsimplepickle.lua")
function bbsort(tbl, tabletwo)
for i = 1, table.getn( tbl ) do --> array start to end
for j = 2, table.getn( tbl ) do
if tabletwo[tbl[j]] > tabletwo[tbl[j-1]] then
temp = tbl[j-1]
tbl[j-1] = tbl[j]
tbl[j] = temp
end
end
end
return
end
function tokens( str )
local ret = {}
string.gsub( str, "([^%s]+)", function( s ) table.insert( ret, s ) end )
return ret
end
if not count then
count ={}
end
local p = io.open( "scripts/ChatLogs/count.txt", "r" )
if p then
dofile("scripts/ChatLogs/count.txt")
p:close()
end
local f = io.open( "scripts/ChatLogs/list.txt", "r" )
if f then
dofile("scripts/Chatlogs/list.txt")
f:close()
end
local ar={}
for n in pairs(count) do table.insert(ar, n) end
bbsort(ar,count)
dcpp:setListener( "chat", "logger",
function( hub,user,text)
local name = "scripts/ChatLogs/"..os.date( "%Y" ).."/"..os.date( "%m" ).."/"..os.date( "%d" ).."_"..os.date( "%m" ).."_"..os.date( "%Y" )..".txt"
local f = io.open (name,"a")
local user =user:getNick()
if string.len( text ) < 800 then
local a= "["..os.date("%I")..":"..os.date("%M").." "..os.date("%p").."] ".."<"..user.."> "..text
f:write(a.."\n")
f:flush()
f:close()
end
if user ~= "-Hub-" then
if not count[user] then
count[user] =0
table.insert(ar,user)
end
count[user] = count[user] + 1
end
local pos
for i,v in pairs(ar) do
if v == user then
pos =i
end
end
local tempVar = count[user]
local cent = tempVar - math.floor( tempVar/500 ) * 500
if cent == 0 then
hub:sendChat(".say hjpotter92 The user "..user.." just punched 500th line on mainchat. The current count being: "..count[user] )
end
if pos > 1 then
if count[ar[pos]] > count[ar[pos-1]] then
local temp = ar[pos-1]
ar[pos-1] = ar[pos]
ar[pos] = temp
end
end
pickle.store("scripts/ChatLogs/count.txt", {count=count} )
pickle.store("scripts/list.txt", {ar=ar} )
end
)
dcpp:setListener( "pm", "response",
function( hub, user, text )
local s = string.lower( text )
local params = tokens( s )
if string.sub( s, 1, 1 )~="+" then
user:sendPrivMsgFmt( "Wrong method to call. Use \"+help\" as command.", 1 )
return
end
if string.find( s, "+score" ) then
user:sendPrivMsgFmt( "\r\t"..user:getNick()..", your score is "..count[user:getNick()]..".\n\tBot designed by Brick and hjpotter92.", 1 )
elseif string.find( s, "+help" ) then
local h = io.open( "scripts/ChatLogs/chatLogHelp.txt", "r" )
local totcounts = h:read( "*a" )
h:close()
user:sendPrivMsgFmt( totcounts, 1)
elseif string.find( s, "+tcount" ) then
local cnt = io.open( "scripts/ChatLogs/count.txt", "r" )
local fileData = cnt:read( "*a" )
cnt:close()
user:sendPrivMsgFmt( fileData, 1)
elseif string.find( s,"+top" ) then
local listtop = " "
local cnted = params[2]
if params[2] then
for i=1, params[2] do
listtop = listtop.."\n\t "..i..". "..ar[i].." -> "..count[ ar[i] ]
end
else
for i=1, 5 do
listtop = listtop.."\n\t "..i..". "..ar[i].." -> "..count[ ar[i] ]
end
end
user:sendPrivMsgFmt( listtop, 1 )
end
end
)
DC():PrintDebug( " ** Loaded Chat Log.lua **" )