hello scripters :-)
i,m using a script voor keeping chatscores
Top 15 ChatStats v1 - Created by Guibs Apr-15, 2003
the problem hereby is it shows the amount of characters typed and not the lines so if you look good at it a user who has posted ones can get higher in the stats then a user who has typed more lines of txt and i think it is not fair.
So my question is :
is it possiblle to make the script so that it shows the amount of lines typed by a user and the number of characters and smilies and based upon that make a stat?
--------------------------------------------------------------------------------------
-- Top 15 ChatStats v1 - Created by Guibs Apr-15, 2003 --
--------------------------------------------------------------------------------------
---------------------
-- Version History --
---------------------
-- v1 Added Bigstats.ini, OpStats.ini, UserStats.ini, by Guibs Apr-14, 2003
-----------------
-- Description --
-----------------
-- Show the top 5 Ops posters & the top 10 users posters
-- Stats are saved all the 10 minutes
-- Users Commands in main chat: ?stats
-- Ops Commands in pm for the stats: ?stats, ?userstats , ?mystats, !loadstats, !savestats, !clearstats, !helps
-- Helped with the retrobot? v0.99? by tezlo
-- Thks to aMutex for his original ChatStat Script
-- Thks to A.C., [NL]Pur, Dazzler & MatrixX for their helps
------------------------------------
-- Sourcecode is below this point --
------------------------------------
Bot = "![Stats]?"
TimeSpanInMinutes = 10
-------------------
-- Main function --
-------------------
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=="?stats")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=="?stats")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 ")
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?stats\t\t- Show the Top 15 Chaters, and the stats user's\r\n\r\nOps Commands in pm for the stats:\r\n????????????????????????????\r\n?stats\t\t- Show the Top 15 Chaters and the stats user's\r\n?userstats \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!helps\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
---------------------------------------------------------------------------------
part1 (script was to big) :-)
dont use that script!
it will hurt your computer
i rewrote the whole thing :)
-- chatstats v2
-- by tezlo
eyes = ":;8B"
nose = "-o"
mouth = "%[%)%(%]D"
-- modify the above to fit your needs!
stats = {}
names = { posts = 1, chars = 2, words = 3, smilies = 4 }
-- can you think of something else to count? post up
function Main()
loadStats()
end
function OnExit()
saveStats()
end
function DataArrival(user, data)
if strsub(data, 1, 1) == "<" then
local s, e, str = strfind(data, "^%b<> (.*)%|$")
local s, e, cmd, args = strfind(str, "^([%!%?]%a+)%s*(.*)$")
if s then
cmd = strlower(cmd)
if cmd == "?mystats" then cmdStats(user, user.sName)
elseif cmd == "?userstats" then cmdStats(user, args)
elseif cmd == "?topstats" then cmdTopStats(user, args)
elseif cmd == "!savestats" and user.bOperator then saveStats(user)
elseif cmd == "!loadstats" and user.bOperator then loadStats(user)
elseif cmd == "!clearstats" and user.bOperator then clearStats(user)
else return end return 1
else updStats(user.sName, str)
end
end
end
function cmdStats(user, target)
local tmp = stats[target]
if tmp then user:SendData(">> chatstats for "..target..": "..tmp[1].." posts "..tmp[2].." characters "..tmp[3].." words "..tmp[4].." smilies")
else user:SendData(">> no record for "..target) end
end
function cmdTopStats(user, args)
local id = names[args] or 1
local index = sortStats(id)
user:SendData(">> topstats category "..id)
local n = getn(index)
if n > 10 then n = 10 end
for i = 1, n do
local nick = index[i]
local tmp = stats[nick]
user:SendData(">>\t"..i..". "..nick.." ["..tmp[id].."]")
end
end
function loadStats(user)
stats = dofile("chatstats.dat") or {}
if user then user:SendData(">> done") end
end
function saveStats(user)
local f = openfile("chatstats.dat", "w+")
assert(f, "chatstats.dat")
write(f, "return {\n")
for nick, table in stats do
write(f, "\t"..format("[%q]", nick).." = { "..table[1], ", "..table[2]..", "..table[3]..", "..table[4].." },\n")
end write(f, "}") closefile(f)
if user then user:SendData(">> done") end
end
function clearStats(user)
stats = {}
if user then user:SendData(">> done") end
end
function sortStats(id)
local index = {n=0}
foreach(stats, function(nick, tmp) tinsert(%index, nick) end)
local f = function(x, y) return stats[x][%id] > stats[y][%id] end
sort(index, f) return index
end
function updStats(nick, str)
local tmp = stats[nick] or {0,0,0,0}
tmp[1], tmp[2], tmp[3], tmp[4] = tmp[1]+1, tmp[2]+strlen(str), tmp[3]+cntargs(str, "(%a+)"), tmp[4]+cntsmilies(str)
stats[nick] = tmp
end
function cntargs(str, rule)
local s, n = gsub(str, rule, "")
return n
end
function cntsmilies(str)
return cntargs(str, "(["..eyes.."]["..nose.."]?["..mouth.."])") + cntargs(str, "(["..mouth.."]["..nose.."]?["..eyes.."])")
end
now it does what you asked for
and more..
everybody can..
?mystats
?userstats
?topstats [category] (there are 4 categories.. posts chars words smilies)
OPs also can..
!savestats and !loadstats (obsolete.. stats get saved automatically)
!clearstats
Nice One Tezlo... Think Am gonna implent it into my Bot... great work...
/NightLitch
wow, nice one, me implement too, very nice well done
Thnx Tezlo i will give it a go
when i type ?topstats i get :
[22:14:47] >> topstats category 1
[22:14:47] >> 1. [NL]trucker [1]
When i type ?chatstat i get :
[22:15:15] >> chatstats for [NL]trucker: 1 posts 10 characters 1 words 1 smilies
there is no listing to compare.
no listing like
Top 5 ops posters in this hub :
nr -- lines---- characters----smileys----- name
no1. -- 15 ---- 225 ---- 4 ---- [NL]trucker
no2. -- 12 ---- 275 ---- 3 ---- [NL]janeb
Top 10 posters in this hub :
nr-----lines----- characters---smileys--name
* 1. 2455 2658 00 : [NL]janeb
* 2. 13376 1200 : [NL]trucker
* 3. 5273 800 : [NL]trucker_2
* 4. 4641 376 : DoJiN
i would like a listing like this
that way the users can compare it
so i mean a total listing of it perhaps with the command ?stats cause thats the one users are used to use.
?topstats does that
if i type ?topstats i get this :
[23:03:55] >> topstats category 1
[23:03:55] >> 1. [NL]trucker [3]
[23:03:55] >> 2. charto [1]
it is just for cat1 i want it for all categories
like :
Top 5 ops posters in this hub :
nr -- lines---- characters----smileys----- name
no1. -- 15 ---- 225 ---- 4 ---- [NL]trucker
no2. -- 12 ---- 275 ---- 3 ---- [NL]janeb
Top 10 posters in this hub :
nr-----lines----- characters---smileys--name
* 1. 2455 2658 00 : [NL]janeb
* 2. 13376 1200 : [NL]trucker
* 3. 5273 800 : [NL]trucker_2
* 4. 4641 376 : DoJiN
is this possiblle?
you can get topstats in any category..
?topstats [posts/words/chars/smilies]
and yes.. it will only show the relevant values
tezlo
i dont think you did understand me completly
i wanted to show all of them together and not seperate
so i want it look like this :
nr -- lines---- characters----smileys----- name
no1. -- 15 ---- 225 ---- 4 ---- [NL]trucker
no2. -- 12 ---- 275 ---- 3 ---- [NL]janeb
and not seperate by category.
please please could you do that?
well i'm experimenting abit around with the code, and it's not hard to make those changes. hehe
I got it looking like this right now???
Code:
function cmdTopStats(user, args)
local id = names[args] or 1
local index = sortStats(id)
local chat = ""
chat = chat.."\r\n\r\n\t------------------------ ? Current Top Chatstats: ? ------------------------\r\n"
chat = chat.."\tNr:\tPosts:\tChartrs:\tWords:\tSmilies:\tNick:\r\n"
local n = getn(index)
if n > 10 then n = 10 end
for i = 1, n do
local nick = index
local tmp = stats[nick]
chat = chat.."\t"..i..".\t "..tmp[id].."\t "..tmp[2].."\t "..tmp[3].."\t "..tmp[4].."\t"..nick.."\r\n"
end
user:SendData(chat)
end
i think that's wath you looking for, just replace the old part with this new part.
Optimus
you hit the jackpot m8
we dutch understand each other :-)))
but indeed a bit restyling wouldnt be bad .
but had a nice talk to tezlo and he is going to put the altered script here.
i love this guy if he would be dutch :-))))
Btw, Tezlo i love this 1.
ow thx :)
this is what i did with topstats..
pretty much the same thing
function cmdTopStats(user, args)
local id = names[args] or 1
local index = sortStats(id)
user:SendData(">> topstats category "..id)
user:SendData(">>\tid\tposts\tchars\twords\tsmilies\tnick")
local n = getn(index)
if n > 10 then n = 10 end
for i = 1, n do
local nick = index[i]
local tmp = stats[nick]
user:SendData(">>\t"..i..".\t"..tmp[1].."\t"..tmp[2].."\t"..tmp[3].."\t"..tmp[4].."\t"..nick)
end
end
tja.. nederlanders :)
maar dat wist ik niet lol. slimme nederlanders haha
Btw, Updated code in some posts before just scroll back^^^^
lol ;)
Yeps Looks nice
TiM? :D
ben geen nederlander.. maar ik versta wel ;)
thanx tezlo and Optimus it works fine now.
if one way or another i can repay the favor just call me.
great job wel done .
the only thing i could wish for now is that there will be a diffrence between Op,s and users.
like a top 5 for Op,s and a top 10 for users :-))
in one listing ofcours :-)) just to make it a bit more challencing.
oftewel het enige wat ik nog zou kunnen wensen is een top5 voor Op,s en een top 10 voor users in een enkele listing natuurlijk.
alleen om het nog een beetje uitdagender te maken.
dit is wat ik nu heb Op,s en users door mekaar .
------------------------ ? Current Top Chatstats: ? ------------------------
Nr: Posts: Chartrs: Words: Smilies: Nick:
1. 89 2497 490 10 [NL]trucker
2. 41 1289 272 0 TheWickedRabbit
3. 4 151 25 0 [NL]janeb
4. 2 19 3 0 M@non
5. 1 3 1 0 tezlo
6. 1 14 2 0 [NL]M@non
7. 1 17 3 1 charto
8. 1 110 19 0 coulzee
9. 1 5 1 0 [INT]masterload
hmm er staat op de site wel een scheiding tussen de cijfers.
is there still someone looking into my last request?
the only thing i could wish for now is that there will be a diffrence between Op,s and users.
like a top 5 for Op,s and a top 10 for users :-))
in one listing ofcours :-)) just to make it a bit more challencing.
pleeeeeaaaasseee is there someone who can do this?
i think it is better looking this way [diffrent stats for user and OP,s]
Hi,
I just got my hands on CHATSTATS_v2, its really good, BUT im also running Hub-Link so the chatscript will also record the Hub-Link Bots typing (which is in topstats with couple of thousand more carachters than all others..lol). So i would need a exception, a table or whatever to put all nicks i dont want to be recorded. I appreciate all help
-- chatstats v2
-- by tezlo
-- modified by tezlo and Optimus
--everybody can..
--?mystats
--?userstats
--?topstats [category] (there are 4 categories.. posts chars --words smilies)
--OPs also can..
--!savestats and !loadstats (obsolete.. stats get saved --automatically)
--!clearstats
eyes = ":;8B"
nose = "-o"
mouth = "%[%)%(%]D"
-- modify the above to fit your needs!
stats = {}
names = { posts = 1, chars = 2, words = 3, smilies = 4 }
-- can you think of something else to count? post up
function Main()
loadStats()
end
function OnExit()
saveStats()
end
function DataArrival(user, data)
if strsub(data, 1, 1) == "<" then
local s, e, str = strfind(data, "^%b<> (.*)%|$")
local s, e, cmd, args = strfind(str, "^([%!%?]%a+)%s*(.*)$")
if s then
cmd = strlower(cmd)
if cmd == "?mystats" then cmdStats(user, user.sName)
elseif cmd == "?userstats" then cmdStats(user, args)
elseif cmd == "?topstats" then cmdTopStats(user, args)
elseif cmd == "!savestats" and user.bOperator then saveStats(user)
elseif cmd == "!loadstats" and user.bOperator then loadStats(user)
elseif cmd == "!clearstats" and user.bOperator then clearStats(user)
else return end return 1
else updStats(user.sName, str)
end
end
end
function cmdStats(user, target)
local tmp = stats[target]
if tmp then user:SendData(">> chatstats for "..target..": "..tmp[1].." posts "..tmp[2].." characters "..tmp[3].." words "..tmp[4].." smilies")
else user:SendData(">> no record for "..target) end
end
function cmdTopStats(user, args)
local id = names[args] or 1
local index = sortStats(id)
local chat = ""
chat = chat.."\r\n\r\n\t------------------------ ? Current Top Chatstats: ? ------------------------\r\n"
chat = chat.."\tNr:\tPosts:\tChartrs:\tWords:\tSmilies:\tNick:\r\n"
local n = getn(index)
if n > 10 then n = 10 end
for i = 1, n do
local nick = index[i]
local tmp = stats[nick]
chat = chat.."\t"..i..".\t "..tmp[id].."\t "..tmp[2].."\t "..tmp[3].."\t "..tmp[4].."\t"..nick.."\r\n"
end
user:SendData(chat)
end
function loadStats(user)
stats = dofile("chatstats.dat") or {}
if user then user:SendData(">> done") end
end
function saveStats(user)
local f = openfile("chatstats.dat", "w+")
assert(f, "chatstats.dat")
write(f, "return {\n")
for nick, table in stats do
write(f, "\t"..format("[%q]", nick).." = { "..table[1], ", "..table[2]..", "..table[3]..", "..table[4].." },\n")
end write(f, "}") closefile(f)
if user then user:SendData(">> done") end
end
function clearStats(user)
stats = {}
if user then user:SendData(">> done") end
end
function sortStats(id)
local index = {n=0}
foreach(stats, function(nick, tmp) tinsert(%index, nick) end)
local f = function(x, y) return stats[x][%id] > stats[y][%id] end
sort(index, f) return index
end
function updStats(nick, str)
local tmp = stats[nick] or {0,0,0,0}
tmp[1], tmp[2], tmp[3], tmp[4] = tmp[1]+1, tmp[2]+strlen(str), tmp[3]+cntargs(str, "(%a+)"), tmp[4]+cntsmilies(str)
stats[nick] = tmp
end
function cntargs(str, rule)
local s, n = gsub(str, rule, "")
return n
end
function cntsmilies(str)
return cntargs(str, "(["..eyes.."]["..nose.."]?["..mouth.."])") + cntargs(str, "(["..mouth.."]["..nose.."]?["..eyes.."])")
end
cheers // Dj_OcTaGoN