hi i have got a problem with a chatstats bot i use
when the stats are asked it says:
<Stats>
Top 5 ops posters in this hub :
* Nr. Posts: Name
* 1. 1301: [NL]The_Rat
Top 10 users posters in this hub :
* Nr. Posts: Name
* 1. 566: [NL][VIP]Masterload
* 2. 230: [DsL]MoSkAl[Pl]
* 3. 167: [NL]-DiGARiX
* 4. 134: (NL)Janto
* 5. 32: [NL][VIP]Jackie
* 6. 32: [NL]reina
put instead of counting posts he counts characters
can some1 help me with this???
this is the script:
function Main()
ChatOpStat={}
ChatUserStat={}
frmHub:RegBot(Bot)
tabConfig = parseINI("Stats/Bigstats.ini")
tabOpStats = parseINI("Stats/OpStats.ini")
tabUserStats = parseINI("Stats/UserStats.ini")
cfgStats = getsection(tabConfig,"stats")
InitTable ("Stats/OpStats.ini",tabOpStats,ChatOpStat)
InitTable ("Stats/UserStats.ini",tabUserStats,ChatUserStat)
smEyes = getkey(cfgStats, "eyes")
smNose = getkey(cfgStats, "nose")
smMouth = getkey(cfgStats, "mouth")
SetTimer(TimeSpanInMinutes*60000)
StartTimer()
end
function DataArrival(user,data)
local tmp = strsub(data,1,1)
if tmp == "<" then
local s, e, str = strfind(data,"%b<> (.*)|")
if not iscommand(str) then
if (user.bOperator) then
DoUpdOpStats(user,str)
else
DoUpdUserStats(user,str)
end
end
end
if (strsub(data,1,1) == "<" ) then
data=strsub(data,1,strlen(data)-1)
s,e,cmd = strfind( data,"%b<>%s+(%S+)" )
if (cmd=="!chatstats")then
pm = 0
ShowTop15(user)
elseif (cmd=="!helps")then
if user.bOperator then
ShowHelpStats(user)
returndata = 1
end
end
end
if(strsub(data,1,4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == Bot) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
if (user.bOperator) then
if (cmd=="!helps")then
ShowHelpStats(user)
elseif (cmd=="!savestats") then
SaveStats(user)
elseif (cmd=="!loadstats") then
LoadStats(user)
elseif (cmd=="!clearstats") then
Reset(user)
elseif (cmd=="!mystats") then
ShowYourStats(user,cmd,args)
elseif (cmd=="!chatstats")then
pm = 1
ShowTop15(user)
elseif (cmd=="!userstats") then
s,e,cmd,userName= strfind(data,"%b<>%s+(%S+)%s+(.+)")
if not userName then
user:SendPM(Bot,"***Wrong synthax: ?userstats <user>")
else
ShowUserStats(user,cmd,userName)
end
end
end
end
end
end
--------- Update Chat Stats ---------
function DoUpdUserStats(user, str)
local table = getitem(tabUserStats, user.sName)
if not table then table = mkUserStats(user) end
local stats = getvalue(table.tItems, "stats")
local s, e, chars, words, smilies = strfind(stats, "(%d+)|(%d+)|(%d+)")
chars = tonumber(chars)+strlen(str)
words = tonumber(words)+cntargs(str, "(%a+)", 2)
smilies = tonumber(smilies)+cntsmilies(str)
ChatUserStat[user.sName]=chars
putvalue(table.tItems, "stats", chars.."|"..words.."|"..smilies)
end
function DoUpdOpStats(user, str)
local table = getitem(tabOpStats, user.sName)
if not table then table = mkOpStats(user) end
local stats = getvalue(table.tItems, "stats")
local s, e, chars, words, smilies = strfind(stats, "(%d+)|(%d+)|(%d+)")
chars = tonumber(chars)+strlen(str)
words = tonumber(words)+cntargs(str, "(%a+)", 2)
smilies = tonumber(smilies)+cntsmilies(str)
ChatOpStat[user.sName]=chars
putvalue(table.tItems, "stats", chars.."|"..words.."|"..smilies)
end
--------- Show Chat Stats Commands ---------
function ShowHelpStats(user)
user:SendPM(Bot,"\r\n\===============================================\r\nUsers Commands in main chat:\r\n¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\r\n!chatstats\t\t- Show the Top 15 Chatters, and the stats user's\r\n\r\nOps Commands in pm for the stats:\r\n¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\r\n!chatstats\t\t- Show the Top 15 Chatters and the stats user's\r\n!userstats <user>\t- Show stats user's\r\n!mystats\t\t- Show ur current stats\r\n!loadstats\t- Load stats\r\n!savestats\t- Saves stats\r\n!clearstats\t- All stats initialized\r\n!chathelp\t\t- This help again\r\n===============================================")
end
--------- Load Chat Stats ---------
function LoadStats(user)
tabConfig = parseINI("Stats/Bigstats.ini")
tabOpStats = parseINI("Stats/OpStats.ini")
tabUserStats = parseINI("Stats/UserStats.ini")
cfgStats = getsection(tabConfig,"stats")
InitTable ("Stats/OpStats.ini",tabOpStats,ChatOpStat)
InitTable ("Stats/UserStats.ini",tabUserStats,ChatUserStat)
smEyes = getkey(cfgStats, "eyes")
smNose = getkey(cfgStats, "nose")
smMouth = getkey(cfgStats, "mouth")
user:SendPM(Bot,"Chatstat has been successfully loaded ...")
end
--------- Reset Chat Stats ---------
function Reset(user)
ChatOpStat={}
ChatUserStat={}
remove("Stats/OpStats.ini")
local handle=openfile("Stats/OpStats.ini","a")
write(handle,"\n")
closefile(handle)
remove("Stats/UserStats.ini")
local handle=openfile("Stats/UserStats.ini","a")
write(handle,"\n")
closefile(handle)
tabConfig = parseINI("Stats/Bigstats.ini")
tabOpStats = parseINI("Stats/OpStats.ini")
tabUserStats = parseINI("Stats/UserStats.ini")
user:SendPM(Bot,"Chat-Stats initialized!")
end
--------- Save Chat Stats ---------
function SaveStats(user)
writeINI("Stats/OpStats.ini",tabOpStats)
writeINI("Stats/UserStats.ini",tabUserStats)
user:SendPM(Bot,"Chatstat has been successfully saved ...")
end
--------- Your Chat Stats ---------
function ShowYourStats(user, cmd, args)
local table = getitem(tabOpStats, user.sName)
if not table then table = mkOpStats(user, "") end
local stats = getkey(table, "stats")
local s, e, chars, words, smilies = strfind(stats, "(%d+)|(%d+)|(%d+)", 1)
user:SendPM(Bot,user.sName.." "..chars.." characters "..words.." words ".. smilies.." smilies")
end
--------- User Chat Stats ---------
function ShowUserStats(user, cmd, userName)
local table = getitem(tabUserStats, userName)
UserError=0
OpError=0
if not table then
UserError=1
else
local stats = getkey(table, "stats")
local s, e, chars, words, smilies = strfind(stats, "(%d+)|(%d+)|(%d+)", 1)
user:SendPM(Bot,userName.." "..chars.." characters "..words.." words ".. smilies.." smilies")
end
local table = getitem(tabOpStats, userName)
if not table then
OpError=1
else
local stats = getkey(table, "stats")
local s, e, chars, words, smilies = strfind(stats, "(%d+)|(%d+)|(%d+)", 1)
user:SendPM(Bot,userName.." "..chars.." characters "..words.." words ".. smilies.." smilies")
end
if UserError==1 and OpError==1 then
user:SendPM(Bot,userName.." is not in my stats file...")
end
end
--------- Show Top 15 Chatters ---------
function ShowTop15(user)
local user1, userkey1
local user2, userkey2
local user3, userkey3
local user4, userkey4
local user5, userkey5
local user6, userkey6
local user7, userkey7
local user8, userkey8
local user9, userkey9
local user10, userkey10
local op1, opkey1
local op2, opkey2
local op3, opkey3
local op4, opkey4
local op5, opkey5
userkey1=0
userkey2=0
userkey3=0
userkey4=0
userkey5=0
userkey6=0
userkey7=0
userkey8=0
userkey9=0
userkey10=0
opkey1=0
opkey2=0
opkey3=0
opkey4=0
opkey5=0
for a,b in ChatOpStat do
if (ChatOpStat[a]>opkey1) then
op5=op4
opkey5=opkey4
op4=op3
opkey4=opkey3
op3=op2
opkey3=opkey2
op2=op1
opkey2=opkey1
op1=a
opkey1=ChatOpStat[a]
else
if (ChatOpStat[a]>opkey2) then
op5=op4
opkey5=opkey4
op4=op3
opkey4=opkey3
op3=op2
opkey3=opkey2
op2=a
opkey2=ChatOpStat[a]
else
if (ChatOpStat[a]>opkey3) then
op5=op4
opkey5=opkey4
op4=op3
opkey4=opkey3
op3=a
opkey3=ChatOpStat[a]
else
if (ChatOpStat[a]>opkey4) then
op5=op4
opkey5=opkey4
op4=a
opkey4=ChatOpStat[a]
else
if (ChatOpStat[a]>opkey5) then
op5=a
opkey5=ChatOpStat[a]
end
end
end
end
end
end
opstats1 = ""
opstats2 = ""
opstats3 = ""
opstats4 = ""
opstats5 = ""
if (op1~=nil) then
opstats1 = ("* 1.\t"..ChatOpStat[op1]..":\t"..op1)
end
if (op2~=nil) then
opstats2 = ("\r\n* 2.\t"..ChatOpStat[op2]..":\t"..op2)
end
if (op3~=nil) then
opstats3 = ("\r\n* 3.\t"..ChatOpStat[op3]..":\t"..op3)
end
if (op4~=nil) then
opstats4 = ("\r\n* 4.\t"..ChatOpStat[op4]..":\t"..op4)
end
if (op5~=nil) then
opstats5 = ("\r\n* 5.\t"..ChatOpStat[op5]..":\t"..op5)
end
opstats = opstats1..opstats2..opstats3..opstats4..opstats5
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[i] 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
Big problem with chatstats script
Moderator: Moderators
-
[NL]The_Rat
- Posts: 3
- Joined: 2003-08-08 13:33
- Location: Netherlands
Big problem with chatstats script
Being in love is like taking a shit in your pants, everybody sees it but only you have that special warm feeling
-
[NL]The_Rat
- Posts: 3
- Joined: 2003-08-08 13:33
- Location: Netherlands
-
Sedulus
- Forum Moderator
- Posts: 687
- Joined: 2003-01-04 14:32
1) where's the indentation? please post code with indents
2) I think I saw this script on http://lua.bcs-solutions.de/ (the ptokax lua board), and that's where you'll find a lot of ptokax lua scripters
3) everything that rolls out of that board has credits on the top.. and if they're missing, the user should append them. I see no credits? hm
2) I think I saw this script on http://lua.bcs-solutions.de/ (the ptokax lua board), and that's where you'll find a lot of ptokax lua scripters
3) everything that rolls out of that board has credits on the top.. and if they're missing, the user should append them. I see no credits? hm
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
-
Sedulus
- Forum Moderator
- Posts: 687
- Joined: 2003-01-04 14:32
here.. post there instead.. and put those credits back
http://lua.bcs-solutions.de/thread.php? ... &boardid=7
http://lua.bcs-solutions.de/thread.php? ... &boardid=7
http://dc.selwerd.nl/hublist.xml.bz2
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
http://www.b.ali.btinternet.co.uk/DCPlusPlus/index.html (TheParanoidOne's DC++ Guide)
http://www.dslreports.com/faq/dc (BSOD2600's Direct Connect FAQ)
-
[NL]The_Rat
- Posts: 3
- Joined: 2003-08-08 13:33
- Location: Netherlands
Who is online
Users browsing this forum: Google [Bot] and 0 guests