-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
sBot = "????hÆ??Æ?????" -- Name of Bot
SendComm = 1 -- Send UserCommands 1 = On 0 = Off
pMenu = "????hÆ??Æ?????" -- Name of Menu
Chatstats = {}
Sortstats = 2 -- 1=words / 2=posts
ChatStatsFile = "chatstats.tbl"
EnableChatStats = {
- = 1, -- Master
[1] = 1, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 1, -- Moderators
[5] = 1, -- NetFounders
[-1] = 1, -- Users (UnRegged)
}
AllowedProfiles = {
- = 1, -- Masters
[1] = 0, -- Operators
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
}
function Main()
frmHub:RegBot(sBot)
loadTableFromFile(ChatStatsFile)
end
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[user.sName] then
user:SendData(sBot, "??? Le tue statistiche di Chat: Hai scritto "..Chatstats[user.sName]["post"].." frasi in main usando "..Chatstats[user.sName]["chars"].." parole,e "..Chatstats[user.sName]["words"].." lettere ???")
end
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
end
end
OpConnected = NewUserConnected
function OnExit()
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
function ChatArrival(user, data)
if (string.sub(data, 1, 1) == "<" ) then
if EnableChatStats[user.iProfile] == 1 then
local s,e,str = string.find(data, "^%b<> (.*)%|$")
updStats(user.sName, str)
end
data=string.sub(data,1,string.len(data)-1)
s,e,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd == "!mychatstat") then
if Chatstats[user.sName] then
user:SendData(sBot, "??? Le tue statistiche di Chat: Hai scritto "..Chatstats[user.sName]["post"].." frasi in main usando "..Chatstats[user.sName]["chars"].." parole,e "..Chatstats[user.sName]["words"].." lettere ???")
return 1
else
user:SendData(sBot, "*** No chat statics found!")
return 1
end
elseif (cmd=="!topchatters") then
TCopy={}
if Chatstats then
for i,v in Chatstats do
table.insert(TCopy,{i,v.post,v.chars,v.words})
end
table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
local chat = "Current Top Chatters:\r\n\r\n"
chat = chat.."\t ------------------------------------------------------------------------\r\n"
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
chat = chat.."\t ------------------------------------------------------------------------\r\n"
for i = 1,25 do
if TCopy
then
-- Nr: Posts: Chars: Words: Name:
chat = chat.."\t "..i..".\t "..TCopy[2].."\t "..TCopy[3].."\t "..TCopy[4].."\t"..TCopy[1].."\r\n"
end
end
user:SendData(sBot, chat)
TCopy={}
end
return 1
elseif (cmd == "!delchatter") and AllowedProfiles[user.iProfile] == 1 then
local s,e,cmd,name = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
if name then
if Chatstats[name] then
Chatstats[name] = nil
user:SendData(sBot, "Chatstats from user "..name.." are now removed!")
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
else
user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
end
else
user:SendData(sBot, "*** Usage: !delchatter ")
end
return 1
elseif (cmd == "!clearchatstats") and AllowedProfiles[user.iProfile] == 1 then
Chatstats = {}
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
user:SendData(sBot, "Chatstats are cleared by "..user.sName)
return 1
end
end
end
function updStats(nick, str)
local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x")}
tmp["post"], tmp["chars"], tmp["words"], tmp["time"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x")
Chatstats[nick] = tmp
-- saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
function cntargs(str, rule)
local s,n = string.gsub(str, rule, "")
return n
end
----------------------------------------------
-- load & save Tables
----------------------------------------------
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
-----------------------------------------------------------
function saveTableToFile(file, table, tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
>>
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
This two command don't work e don't appear on right click... ?(
Change this function:
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[user.sName] then
user:SendData(sBot, "??? Le tue statistiche di Chat: Hai scritto "..Chatstats[user.sName]["post"].." frasi in main usando "..Chatstats[user.sName]["chars"].." parole,e "..Chatstats[user.sName]["words"].." lettere ???")
end
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..sMenu.."\\????hÆ??Æ?????\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
end
end
to:
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[user.sName] then
user:SendData(sBot, "??? Le tue statistiche di Chat: Hai scritto "..Chatstats[user.sName]["post"].." frasi in main usando "..Chatstats[user.sName]["chars"].." parole,e "..Chatstats[user.sName]["words"].." lettere ???")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
end
end
Best regards
Don't go...
are u sure u are using the right profile? i just tested it its working perfectly!
I'm NetFounder... do you is this the problem?And if it is,how change profile to netfounder??
change this :
AllowedProfiles = {
[0] = 1, -- Masters
[1] = 0, -- Operators
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
}
to this :
AllowedProfiles = {
[0] = 1, -- Masters
[1] = 0, -- Operators
[4] = 0, -- Moderator
[5] = 1, -- NetFounder
}
Tkx now work ! ^_^
QuoteOriginally posted by CaSaNoVa
Tkx now work ! ^_^
ur welcome !
hi!
i use that same script in my hub (that already have to rightclick menus:1 from radioscript and other from zrightclicker of robocop)...the comands work's fine.
the only probl. is that the rightclick menu don't apeear like the other to...
anyone know why???
here's my config.
-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten
---- Modded by Madman
-- Added so it's creates ChatStatsFile, if it's missing
-- Fixed so it dont counts commands
-- Added a IgnoreTable, users in that wont be counted
----
sBot = "?M?X-???????" -- Name of Bot
SendComm = 1 -- Send UserCommands 1 = On 0 = Off
pMenu = "? ? ?????? - M ? ? ? ? ?" -- Name of Menu
ChatStatsTo = "user" -- Send TopChatters to? user or all
Chatstats = {}
Sortstats = 2 -- 1=words / 2=posts
ChatStatsFile = "chatstats.tbl"
IgnoreTable = {
-- 0=dont ignore/1=ignore
["Re@SoN"] = 0,
["aCiD_LoOp"] = 0,
}
EnableChatStats = {
[0] = 1, -- Master
[1] = 1, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 1, -- Moderators
[5] = 1, -- NetFounders
[-1] = 1, -- Users (UnRegged)
}
AllowedProfiles = {
[0] = 0, -- Masters
[1] = 1, -- Operators
[4] = 0, -- Moderator
[5] = 1, -- NetFounder
}
function Main()
frmHub:RegBot(sBot)
local file = io.open(ChatStatsFile, "r")
if file then
file:close()
else
local file = io.open(ChatStatsFile, "w+")
file:write()
file:close()
end
dofile(ChatStatsFile)
end
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[user.sName] then
user:SendData(sBot, "---===[ Your Chat Stats: You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
end
end
OpConnected = NewUserConnected
function OnExit()
if isEmpty(Chatstats) then
else
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
end
function IsCmd(str)
return string.sub(str, 1, 1) == "!" or string.sub(str, 1, 1) == "?" or string.sub(str, 1, 1) == "+" or string.sub(str, 1, 1) == "#"
end
function ChatArrival(user, data)
if EnableChatStats[user.iProfile] == 1 then
local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
if IsCmd(cmd) then
elseif IgnoreTable[user.sName] == 1 then
else
local s,e,str = string.find(data, "^%b<> (.*)%|$")
updStats(user.sName, str)
end
end
data=string.sub(data,1,string.len(data)-1)
s,e,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd == "!mychatstat") then
if Chatstats[user.sName] then
user:SendData(sBot, "---===[ Your Chat Stats: You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
return 1
else
user:SendData(sBot, "*** No chat statics found!")
return 1
end
elseif (cmd=="!topchatters") then
TCopy={}
if Chatstats then
for i,v in Chatstats do
table.insert(TCopy,{i,v.post,v.chars,v.words})
end
table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
local chat = "Current Top Chatters:\r\n\r\n"
chat = chat.."\t ------------------------------------------------------------------------\r\n"
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
chat = chat.."\t ------------------------------------------------------------------------\r\n"
for i = 1,25 do
if TCopy[i] then
-- Nr: Posts: Chars: Words: Name:
chat = chat.."\t "..i..".\t "..TCopy[i][2].."\t "..TCopy[i][3].."\t "..TCopy[i][4].."\t"..TCopy[i][1].."\r\n"
end
end
if ChatStatsTo == "user" then
user:SendData(sBot, chat)
elseif ChatStatsTo == "all" then
SendToAll(sBot, chat)
end
TCopy={}
end
return 1
elseif (cmd == "!delchatter") and AllowedProfiles[user.iProfile] == 1 then
local s,e,cmd,name = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
if name then
if Chatstats[name] then
Chatstats[name] = nil
user:SendData(sBot, "Chatstats from user "..name.." are now removed!")
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
else
user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
end
else
user:SendData(sBot, "*** Usage: !delchatter ")
end
return 1
elseif (cmd == "!clearchatstats") and AllowedProfiles[user.iProfile] == 1 then
Chatstats = {}
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
user:SendData(sBot, "Chatstats are cleared by "..user.sName)
return 1
end
end
function updStats(nick, str)
local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x")}
tmp["post"], tmp["chars"], tmp["words"], tmp["time"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x")
Chatstats[nick] = tmp
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
function cntargs(str, rule)
local s,n = string.gsub(str, rule, "")
return n
end
----------------------------------------------
-- load & save Tables
----------------------------------------------
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
-----------------------------------------------------------
function saveTableToFile(file, table, tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
for i,v in t do
return false;
end
return true;
end;
best regards,
Re@SoN
QuoteOriginally posted by Re@SoN
hi!
i use that same script in my hub (that already have to rightclick menus:1 from radioscript and other from zrightclicker of robocop)...the comands work's fine.
the only probl. is that the rightclick menu don't apeear like the other to...
Have you checked this table? If the right value is "0", then, the Operator commands aren't sent to that profile. If not, they are. So, have a closer look at it.
AllowedProfiles = {
[0] = 0, -- Masters
[1] = 1, -- Operators
[4] = 0, -- Moderator
[5] = 1, -- NetFounder
}
Cheers
compare this :
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
to this :
user:SendData("$UserCommand 1 3 "..sMenu.."\\?•??h?†?†?†?™?•?\\TopChatters$<%[mynick]> !topchatters|")
thats the error, ur missing the "escape"(|) and u have an extra end pipe --> |
know works!
tks jiten for the help, once again :)
[[]]
Re@SoN
QuoteOriginally posted by Re@SoN
know works!
Not really. My hint was incomplete as I didn't see that endpipe repetition and the missing escape that Dessamator mentioned. So, without changing that, it won't work ;)
Cheers
Dessamator i changed that line and the script don't work...give me a sintax error at line 130.
if i don't change, works :)
best regards,
Re@SoN
hm, it should work try this
user:SendData("$UserCommand 1 3 "..sMenu.."\\TopChatters$<%[mynick]> !topchatters|")
if it still doesnt work post that line with the error .
with that line give me this error:
scripts\ChatStats.lua:130: attempt to concatenate global `sMenu' (a nil value)
i'm changing this:
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
to this:
end
user:SendData("$UserCommand 1 3 "..sMenu.."\\TopChatters$<%[mynick]> !topchatters|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
Try this:
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat|")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats|")
end
Best regards
nop.
the only way that make menu apeear on rightclick is this:
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
the name of script apears in user list, rightclick also apears, but the comands don't respond...simply nothing apeans...and that's is the probl.
best regards,
Re@SoN
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[user.sName] then
user:SendData(sBot, "---===[ Your Chat Stats: You Made "..Chatstats[user.sName]["post"].." Posts In Main Used "..Chatstats[user.sName]["chars"].." Characters, And "..Chatstats[user.sName]["words"].." Words ]===---")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat|")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]|")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats|")
end
end
end
This works for me....
QuoteOriginally posted by Re@SoN
nop.
the name of script apears in user list, rightclick also apears, but the comands don't respond...simply nothing apeans...and that's is the probl.
Maybe you've done something wrong there as yesterday it was working fine for me.
Regards
know works! :)
the error was a space that i have in 1 line...lol
and haven't notice
tks guys for all the help...
respectfully,
Re@SoN
I too searched for this script:))) All many thanks. Here where it is possible to find the present help)
:D
-- ChatStats v3 Made By Optimus
-- Based on Tezlo chats
-- Added Send Commands By TiMeTrAVelleR
-- Madman fixed some in commands
-- Converted to lua5 by Madman with very little help by Jelf
-- with some help by ?
-- fixed stats saving on exit by jiten
-- Added TopChatters list sending every 30 minutes
sBot = "???????hÆ??Æ???????" -- Name of Bot
SendComm = 1 -- Send UserCommands 1 = On 0 = Off
pMenu = "???????hÆ??Æ???????" -- Name of Menu
Chatstats = {}
Sortstats = 2 -- 1=words / 2=posts
ChatStatsFile = "chatstats.tbl"
EnableChatStats = {
- = 1, -- Master
[1] = 1, -- Operators
[2] = 1, -- Vips
[3] = 1, -- Regs
[4] = 1, -- Moderators
[5] = 1, -- NetFounders
[-1] = 1, -- Users (UnRegged)
}
AllowedProfiles = {
- = 1, -- Masters
[1] = 0, -- Operators
[4] = 0, -- Moderator
[5] = 0, -- NetFounder
}
function Main()
frmHub:RegBot(sBot)
dofile(ChatStatsFile)
SetTimer(60*60000)
StartTimer()
end
function NewUserConnected(user)
if SendComm == 1 and EnableChatStats[user.iProfile] == 1 then
if Chatstats[user.sName] then
user:SendData(sBot, "??? Le tue statistiche di Chat: Hai scritto "..Chatstats[user.sName]["post"].." frasi in main usando "..Chatstats[user.sName]["chars"].." parole,e "..Chatstats[user.sName]["words"].." lettere ???")
end
user:SendData("$UserCommand 1 3 "..pMenu.."\\TopChatters$<%[mynick]> !topchatters||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\My Chat Stat$<%[mynick]> !mychatstat||")
if AllowedProfiles[user.iProfile] == 1 then
user:SendData("$UserCommand 1 3 "..pMenu.."\\Del Chatter$<%[mynick]> !delchatter %[line:Nick]||")
user:SendData("$UserCommand 1 3 "..pMenu.."\\Clear Chat Stats$<%[mynick]> !clearchatstats||")
end
end
end
OpConnected = NewUserConnected
function OnExit()
if isEmpty(Chatstats) then
else
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
end
function ChatArrival(user, data)
if (string.sub(data, 1, 1) == "<" ) then
if EnableChatStats[user.iProfile] == 1 then
local s,e,str = string.find(data, "^%b<> (.*)%|$")
updStats(user.sName, str)
end
data=string.sub(data,1,string.len(data)-1)
s,e,cmd=string.find(data, "%b<>%s+(%S+)")
if (cmd == "!mychatstat") then
if Chatstats[user.sName] then
user:SendData(sBot, "??? Le tue statistiche di Chat: Hai scritto "..Chatstats[user.sName]["post"].." frasi in main usando "..Chatstats[user.sName]["chars"].." parole,e "..Chatstats[user.sName]["words"].." lettere ???")
return 1
else
user:SendData(sBot, "*** No chat statics found!")
return 1
end
elseif (cmd=="!topchatters") then
TCopy={}
if Chatstats then
for i,v in Chatstats do
table.insert(TCopy,{i,v.post,v.chars,v.words})
end
table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
local chat = "Current Top Chatters:\r\n\r\n"
chat = chat.."\t ??????????????????????????????????????????????????????\r\n"
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
chat = chat.."\t ??????????????????????????????????????????????????????\r\n"
for i = 1,25 do
if TCopy
then
-- Nr: Posts: Chars: Words: Name:
chat = chat.."\t "..i..".\t "..TCopy[2].."\t "..TCopy[3].."\t "..TCopy[4].."\t"..TCopy[1].."\r\n"
end
end
user:SendData(sBot, chat)
TCopy={}
end
return 1
elseif (cmd == "!delchatter") and AllowedProfiles[user.iProfile] == 1 then
local s,e,cmd,name = string.find( data, "%b<>%s+(%S+)%s+(%S+)" )
if name then
if Chatstats[name] then
Chatstats[name] = nil
user:SendData(sBot, "Chatstats from user "..name.." are now removed!")
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
else
user:SendData(sBot, "*** Chatstats from user "..name.." not found!")
end
else
user:SendData(sBot, "*** Usage: !delchatter ")
end
return 1
elseif (cmd == "!clearchatstats") and AllowedProfiles[user.iProfile] == 1 then
Chatstats = {}
saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
user:SendData(sBot, "Chatstats are cleared by "..user.sName)
return 1
end
end
end
function updStats(nick, str)
local tmp = Chatstats[nick] or {["post"]=0, ["chars"]=0, ["words"]=0, ["time"]=os.date("%x")}
tmp["post"], tmp["chars"], tmp["words"], tmp["time"] = tmp["post"]+1, tmp["chars"]+string.len(str), tmp["words"]+cntargs(str,"(%a+)"), os.date("%x")
Chatstats[nick] = tmp
-- saveTableToFile(ChatStatsFile, Chatstats, "Chatstats")
end
function cntargs(str, rule)
local s,n = string.gsub(str, rule, "")
return n
end
----------------------------------------------
-- load & save Tables
----------------------------------------------
function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");
assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");
sTab = sTab or "";
sTmp = ""
sTmp = sTmp..sTab..sTableName.." = {\n"
for key, value in tTable do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end
sTmp = sTmp..",\n"
end
sTmp = sTmp..sTab.."}"
return sTmp
end
-----------------------------------------------------------
function saveTableToFile(file, table, tablename)
local handle = io.open(file,"w+")
handle:write(Serialize(table, tablename))
handle:flush()
handle:close()
end
-----------------------------------------------------------
function loadTableFromFile(file)
local handle = io.open(file,"r")
if (handle ~= nil) then
loadstring(handle:read("*all"))
handle:flush()
handle:close()
end
end
-------------table checker by herodes
--- for an associative table, like ["smth"] = "smth else",
function isEmpty(t)
for i,v in t do
return false;
end
return true;
end;
function OnTimer()
TCopy={}
if Chatstats then
for i,v in Chatstats do
table.insert(TCopy,{i,v.post,v.chars,v.words})
end
table.sort(TCopy,function(a,b) return (a[Sortstats] > b[Sortstats]) end)
local chat = "Current Top Chatters:\r\n\r\n"
chat = chat.."\t ??????????????????????????????????????????????????????\r\n"
chat = chat.."\t Nr.\tPosts:\tChars:\tWords:\tName:\r\n"
chat = chat.."\t ??????????????????????????????????????????????????????\r\n"
for i = 1,25 do
if TCopy then
chat = chat.."\t "..i..".\t "..TCopy[2].."\t "..TCopy[3].."\t "..TCopy[4].."\t"..TCopy[1].."\r\n"
end
end
SendToAll(sBot, chat)
TCopy={}
end
end