READ THE RULES
0 Members and 1 Guest are viewing this topic.
--[[ TopTen 1.0 LUA 5.1x [Strict][API 2] By Mutor 03/07/08 Display top ten stats for your hub with a 'bargraph' type display. - Provides permission by profile - Provides context menu [right click] - Provides option to change bargraph character - Currently provides the following: •HubShare -- Total Hub Share •Users -- Total Users •UpTimes -- User session times [time logged in] •UserShare -- User Shares •Logins -- User connections •Chat -- Number of chat messages by user •ChatChars -- Number of chat characters by user •Pms -- Number of private messages [pm's] by user •PmChars -- Number of pm characters by user •Cmds -- Number of commands [Chat received in command format with Hub prefixes] •Smilies -- Number of 'smiley' codes. ie.':)' Settable in table below •Lols -- Number of chat acronyms ie lol, rofl. Settable in table below •CTMs -- Number of CTM, RCTM requests, indicates transfer activity •Searches -- Number of user searches •Kicks -- Number of kick commands [$Kick protocol command only] •Redirs -- Number of redirections [$OpForceMove] •Pingers -- Number of BotINFOArrival requests •Unknowns -- Number of unknown commands sent to the hub and by whom]]--//-- Start User Settings --//---- Subfolder of scripts to store table data [will be created if non-existant]local Folder = "TopTen"-- File to store table data [within Folder path, as set above]local File = "Tops.txt"-- Name for the bot [SetMan.GetString(21) = pulled from the hub or use "Custom-Name"]local Bot = "[TopTen]"-- Admins nick for status / error messageslocal OpNick = "Mutor"-- Report all stats to OpNick in pm at script start? true/falselocal Report = true-- Bargraph character table, add/edit/delete as you wish. Set specific char belowlocal Chars = { [1]="|", -- | [2]=string.char(149), -- • [3]=string.char(155), -- › [4]=string.char(164), -- ¤ [5]=string.char(166), -- ¦ [7]=string.char(167), -- § [8]=string.char(181), -- µ [9]=string.char(182), -- ¶ [10]=string.char(254), -- þ [11]="¦|", -- ¦| }-- Set Bargraph character: Chars[x] Where 'x' is the index number from Chars table abovelocal GraphChar = Chars[1]-- Table of ASCII characters to be considered 'smilies'local Asc = {":-)",":)",":o)","=)",":-(",":(",";-)",";)",":-o",":o",":-O",":O",":-/",":/",":-p",":p",":Þ",":->",":>","B-)",":@)",":-~)","(-:",":-|",":|","<:-)","<):-)","*<):-)","[:]",":-x",":x",":-&",":-{)",":-B",":B",":-C",":C","':-)","8-)",":-9","3:-o",":O)",":-[",":-E",":-*",":'-(",":((",":'-)",":-@","I-)","|-O","0:-)","[:-)",":@)","**==","=:-)"}-- Table of Acronyms to be considered 'lols'local Acr = {"lol","lmao","lmfao","rofl","rotfl","pmsl","cya","wb","l8r","omg","rtfm","afaik","imho","ty","yw"}-- User Profiles-- [#] = true/false, (true = Commands enabled, false = Commands disabled)local Profiles = { [-1] = false, --Unregistered User [0] = true, --Master [1] = true, --Operator [2] = true, --Vip [3] = true, --Registered User }--//-- End User Settings --//--local Path = Core.GetPtokaXPath().."scripts/"local Scp,UserCmds,Cnt,Save,Pause = "TopTen 1.0","",0,0,0OnStartup = function() Save = TmrMan.AddTimer(5*60000) if not Folder:find("^"..Path) then Folder = Path.."/"..Folder end local ren,err = os.rename(Folder,Folder) if err and not err:lower():find("permission denied") then os.execute("md "..Folder) end File = Folder.."/"..File if loadfile(File) then dofile(File) Top.HubShare = HubRefresh(Core.GetCurrentSharedSize(),Top.HubShare,os.time()) Top.Users = HubRefresh(Core.GetMaxUsersPeak(),Top.Users,os.time()) Top.UserShare = GetValue(16,1024) Top.UpTimes = GetValue(25,60) else local t,tb = {},Core.GetOnlineUsers() Top = { HubShare = {{os.time(),Core.GetCurrentSharedSize()},}, Users = {{os.time(),Core.GetUsersCount()},}, UserShare = GetValue(16,1024), UpTimes = GetValue(25,60), Logins = GetLogins(), Chat = {}, ChatChars = {}, Pms = {}, PmChars = {}, Cmds = {}, Smilies = {}, Lols = {}, CTMs = {}, Searches = {}, Kicks = {}, Redirs = {}, Pingers = {}, Unknowns = {}, } end local Order = {"HubShare","Users","UpTimes","UserShare","Logins","Chat","ChatChars","Pms","PmChars","Cmds", "Smilies","Lols","CTMs","Searches","Kicks","Redirs","Pingers","Unknowns"} local Pfx,Hub = SetMan.GetString(29):sub(1,1),SetMan.GetString(0) assert(Pfx) assert(Hub) Cnt = #Order local om = "" for _,s in ipairs(Order) do if Report then om = om..GetTen(Top[s],s) end if not Top[s] then Top[s] = {} end UserCmds = UserCmds.."$UserCommand 1 3 "..Hub.."\\"..Scp.."\\"..s.."$<%[mynick]> "..Pfx..s.."||" end SaveFile(File,Top,"Top") if Report and om:len() > 0 then OnError(om,true) endendOnExit = function() SaveFile(File,Top,"Top") endOnError = function(msg,pm) local user = Core.GetUser(OpNick) if user then if pm then Core.SendPmToUser(user,Bot,msg.."|") else Core.SendToUser(user,"<"..Bot.."> "..msg.."|") end endendOnTimer = function(Id) if Id == Save then SaveFile(File,Top,"Top") end if Id == Pause then Top.Users = HubRefresh(Core.GetMaxUsersPeak(),Top.Users,os.time()) Top.UserShare,Top.UpTimes = GetValue(16,1024),GetValue(25,60) TmrMan.RemoveTimer(Pause) Pause = 0 endendUserConnected = function(user) Pause = TmrMan.AddTimer(2000) Refresh(user,Top.Logins,1) if Profiles[user.iProfile] then local Prof,Plural = "Unregistered User","" if user.iProfile ~= -1 then Prof = ProfMan.GetProfile(user.iProfile).sProfileName end if Cnt > 1 then Plural = "s" end local msg = "<"..Bot.."> "..Prof.."'s "..Scp.." commands enabled. Right click ".. "hub tab or user list for menu. "..tostring(Cnt).." listing"..Plural.." available.|" Core.SendToUser(user,UserCmds..msg) endendOpConnected,RegConnected = UserConnected,UserConnectedChatArrival = function(user,data) local _,_,cmd = data:find("%b<> ["..SetMan.GetString(29).."](%w+)") local _,_,to = data:find("^$To: (%S+) From:") local _,_,msg = data:find("%b<> ([^|]+)|") local x = msg:len() if cmd then Refresh(user,Top.Cmds,1) if Profiles[user.iProfile] and Top[cmd] then return Core.SendToUser(user,"<"..Bot.."> "..GetTen(Top[cmd],cmd).."|"),true end end if to then Refresh(user,Top.Pms,1) if x > 0 then Refresh(user,Top.PmChars,x) end else Refresh(user,Top.Chat,1) if x > 0 then Refresh(user,Top.ChatChars,x) end end Update(user,data,Asc,Top.Smilies) Update(user,data,Acr,Top.Lols)endToArrival = ChatArrivalKickArrival = function(user,data) Refresh(user,Top.Kicks,1)endUnknownArrival = function(user,data) Refresh(user,Top.Unknowns,1)endOpForceMoveArrival = function(user,data) Refresh(user,Top.Redirs,1)endConnectToMeArrival = function(user,data) Refresh(user,Top.CTMs,1)endRevConnectToMeArrival,MultiConnectToMeArrival = ConnectToMeArrival,ConnectToMeArrivalSearchArrival = function(user,data) Refresh(user,Top.Searches,1)endMultiSearchArrival = SearchArrivalBotINFOArrival = function(user,data) Refresh(user,Top.Pingers,1)endGetLogins = function() local t,tb = {},Core.GetOnlineUsers() if next(tb) then for _,u in ipairs(tb) do table.insert(t,{u.sNick,1}) end end return tendHubRefresh = function(count,tab,date) if tab then local chg,min,tot = false,0,0 if next(tab) then for i,v in ipairs(tab) do min = math.max(min,v[2]) tot = tot + v[2] end end if not date then return math.max(count,min),tot end if count > min then table.insert(tab,{os.time(),count}) table.sort(tab,function(a,b) return a[2] > b[2] end) while #tab > 10 do table.remove(tab,#tab) table.sort(tab,function(a,b) return a[2] > b[2] end) end end end return tabendRefresh = function(user,tab,x) if tab then local chg = false if next(tab) then for i,v in ipairs(tab) do if v[1]:lower() == user.sNick:lower() then v[2] = v[2] + x chg = true break end end end if not chg then table.insert(tab,{user.sNick,x}) end table.sort(tab,function(a,b) return a[2] > b[2] end) while #tab > 10 do table.remove(tab,#tab) table.sort(tab,function(a,b) return a[2] > b[2] end) end endendUpdate = function(user,data,arr,tab) local bool,x = false,0 data = data:sub(1,-2):lower() for _,code in ipairs(arr) do code = code:gsub("[%p]","%%%1") local chr,count = data:gsub(code,"%1") if count and count > 0 then x = x + count end end if x > 0 then Refresh(user,tab,x) bool = true end return boolendGetValue = function(val,min) local t = {} for _,user in ipairs(Core.GetOnlineUsers()) do local x = Core.GetUserValue(user,val) if x > min then table.insert(t,{user.sNick,tonumber(x)}) end end if next(t) then table.sort(t,function(a,b) return a[2] > b[2] end) while #t > 10 do table.remove(t,#t) end end return tendGetTen = function(t,h) local s,x,y,c,m,f,hdr,bar,art,col = "",0,0,0,"","40.50","",GraphChar,"¯","User Nick" if t and next(t) then if h:lower():find("^uptimes$") then table.sort(t, function(a,b) return a[2] < b[2] end) else table.sort(t, function(a,b) return a[2] > b[2] end) end for i,v in ipairs(t) do x = x + v[2] end y = x for i,v in ipairs(t) do if i < 11 and v[2] > 0 then local n,z,k,sp = v[1],v[2],v[2],"" if h:lower():find("^hubshare$") or h:lower():find("^users$") then if h:lower():find("^hubshare$") then x,c = HubRefresh(Core.GetCurrentSharedSize(),Top.HubShare) m,y,z = FmtSz(c/#t,3),FmtSz(x,3),FmtSz(v[2],3) else _,c = HubRefresh(Core.GetMaxUsersPeak(),Top.Users) x,m,y,z = Core.GetMaxUsersPeak(),tostring(math.ceil(c/#t)),tostring(x),tostring(v[2]) end f,n,col = "20.15",os.date("%m/%d/%Y",v[1]),"Date" elseif h:lower():find("^uptimes$") then x,m,y,z,f,k = Core.GetUpTime(),Convert(os.time() - (x/10),6),Convert(os.time() - x,6),Convert(v[2],6),"40.50",os.time()-k if z and z:len() < 10 then sp = sp.."\t" end elseif h:lower():find("^usershare$") then m,y,z,f = FmtSz(x/#t),FmtSz(x),FmtSz(v[2]),"20.15" else m = tostring(math.ceil(x/#t)) end local pct,mod = (k/x) * 100,"" if pct > 100 then mod = "+" end pct = math.min(pct,100) s = s.."\t"..i..")\t"..string.format("%-"..f.."s ",z)..sp.."\t"..mod.. string.format("%-15.7s ",string.format("%.2f%%",pct)).."\t"..n.."\n\t".. bar..bar:rep(pct).."\n" end end hdr = "\n\n\tTop Ten "..h.." Total: `\t\tMean: "..m.."\n\t"..bar:rep(101).."\n\t"..art:rep(65).."\n".. "\t#)\t"..string.format("%-"..f.."s ",h).."\tPercent Total\t"..col.."\n\n\t"..art:rep(65).."\n" return hdr:gsub("`",y)..s else return "Sorry, there isn't any "..string.format("%q",h).." data available at this time.\n" endendFmtSz = function(int,dec) dec = dec or 2 local i,u,x= int or 0,{"","K","M","G","T","P"},1 while i > 1024 do i,x = i/1024,x+1 end return string.format("%."..dec.."f %sB.",i,u[x])endConvert = function(time,inc) local s,x,n = "",0,os.time() local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"}, {86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}} inc = inc or #tab if time > 0 and time < n then time = n - time for i,v in ipairs(tab) do if i <= inc and time > v[1] then x = math.floor(time/v[1]) if x > 1 then v[2] = v[2].."s" end if x > 0 then s = s..x.." "..v[2]..", " time = time-x*v[1] end end end return s:sub(1,-3) else local a,b = os.date("%m/%d/%Y",86400),os.date("%m/%d/%Y",2145876658) return "Invalid time supplied. [must be > "..a.." and < "..b.."]" endendSaveFile = function(file,table, tablename ) local hFile = io.open (file , "wb") Serialize(table, tablename, hFile) hFile:close() collectgarbage("collect")endSerialize = function(tTable, sTableName, hFile, sTab) local x = pairs sTab = sTab or ""; if type(sTab) == "table" and next(sTab) then x = ipairs end hFile:write(sTab..sTableName.." = {\n" ) for key, value in x(tTable) do local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key) if(type(value) == "table") then Serialize(value, sKey, hFile, sTab.."\t") else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value) hFile:write( sTab.."\t"..sKey.." = "..sValue) end hFile:write( ",\n") end hFile:write( sTab.."}")end
[18:17:48] <[TopTen]> top10.lua:101: attempt to call global 'GetShares' (a nil value)[18:17:48] *** DiXBoT v2.0_RC2 Build 2657 for PtokaX 0.4.0.0 has been Loaded in 0.344 Second(s)[18:17:52] <[TopTen]> top10.lua:216: attempt to index global 'Top' (a nil value)[18:18:02] <[TopTen]> top10.lua:211: attempt to index global 'Top' (a nil value)[18:18:02] <[TopTen]> top10.lua:211: attempt to index global 'Top' (a nil value)[18:18:03] <[TopTen]> top10.lua:216: attempt to index global 'Top' (a nil value)[18:18:03] <[TopTen]> top10.lua:216: attempt to index global 'Top' (a nil value)[18:18:09] <[TopTen]> top10.lua:371: bad argument #1 to 'x' (table expected, got nil)I changed nothing!
[21:56:15] <[TopTen]> Top Ten UpTimes Total: 23 hours, 9 minutes Mean: 2 hours, 18 minutes ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ #) UpTimes Percent Total User Nick ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ 1) 3 weeks, 1 day, 3 hours, 48 minutes +100.00% Unregistered ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 2) 3 weeks, 1 day, 3 hours, 47 minutes +100.00% SolRosenberg ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 3) 3 weeks, 1 day, 3 hours, 47 minutes +100.00% [OP]Cheat_Assassin ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 4) 3 weeks, 1 day, 3 hours, 47 minutes +100.00% Mutor |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--[[ TopTen 1.0b LUA 5.1x [Strict][API 2] By Mutor 03/07/08 Display top ten stats for your hub with a 'bargraph' type display. - Provides permission by profile - Provides context menu [right click] - Provides option to change bargraph character - Currently provides the following: •HubShare -- Total Hub Share •Users -- Total Users •UpTimes -- User session times [time logged in] •UserShare -- User Shares •Logins -- User connections •ReConnections -- User reconnections •Chat -- Number of chat messages by user •ChatChars -- Number of chat characters by user •Pms -- Number of private messages [pm's] by user •PmChars -- Number of pm characters by user •Cmds -- Number of commands [Chat received in command format with Hub prefixes] •Smilies -- Number of 'smiley' codes. ie.':)' Settable in table below •Lols -- Number of chat acronyms ie lol, rofl. Settable in table below •CTMs -- Number of CTM, RCTM requests, indicates transfer activity •Searches -- Number of user searches •Kicks -- Number of kick commands [$Kick protocol command only] •Redirs -- Number of redirections [$OpForceMove] •Pingers -- Number of BotINFOArrival requests •Unknowns -- Number of unknown commands sent to the hub and by whom +Changes from 1.0 07/06/08 +Added clear command for all tables +Added Allstats command]]--//-- Start User Settings --//---- Subfolder of scripts to store table data [will be created if non-existant]local Folder = "TopTen"-- File to store table data [within Folder path, as set above]local File = "Tops.txt"-- Name for the bot [SetMan.GetString(21) = pulled from the hub or use "Custom-Name"]local Bot = "[TopTen]"-- Admins nick for status / error messageslocal OpNick = "Mutor"-- Report all stats to OpNick in pm at script start? true/falselocal Report = false-- Bargraph character table, add/edit/delete as you wish. Set specific char belowlocal Chars = { [1]="|", -- | [2]=string.char(149), -- • [3]=string.char(155), -- › [4]=string.char(164), -- ¤ [5]=string.char(166), -- ¦ [7]=string.char(167), -- § [8]=string.char(181), -- µ [9]=string.char(182), -- ¶ [10]=string.char(254), -- þ [11]="¦|", -- ¦| }-- Set Bargraph character: Chars[x] Where 'x' is the index number from Chars table abovelocal GraphChar = Chars[1]-- Table of ASCII characters to be considered 'smilies'local Asc = {":-)",":)",":o)","=)",":-(",":(",";-)",";)",":-o",":o",":-O",":O",":-/",":/",":-p",":p",":Þ",":->",":>","B-)",":@)",":-~)","(-:",":-|",":|","<:-)","<):-)","*<):-)","[:]",":-x",":x",":-&",":-{)",":-B",":B",":-C",":C","':-)","8-)",":-9","3:-o",":O)",":-[",":-E",":-*",":'-(",":((",":'-)",":-@","I-)","|-O","0:-)","[:-)",":@)","**==","=:-)"}-- Table of Acronyms to be considered 'lols'local Acr = {"lol","lmao","lmfao","rofl","rotfl","pmsl","cya","wb","l8r","omg","rtfm","afaik","imho","ty","yw"}-- User Profiles-- [#] = true/false, (true = Commands enabled, false = Commands disabled)local Profiles = { [-1] = false, --Unregistered User [0] = true, --Master [1] = true, --Operator [2] = true, --Vip [3] = true, --Registered User }--//-- End User Settings --//--local Path = Core.GetPtokaXPath().."scripts/"local Scp,ReConn,UserCmds,Cnt,Save,Pause = "TopTen 1.0b",{},"",0,0,0local Order = {"HubShare","Users","UpTimes","UserShare","Logins","ReConnections","Chat","ChatChars","Pms","PmChars","Cmds","Smilies","Lols","CTMs","Searches","Kicks","Redirs","Pingers","Unknowns","AllStats"}OnStartup = function() Save = TmrMan.AddTimer(5*60000) if not Folder:find("^"..Path,1,true) then Folder = Path..Folder end local ren,err = os.rename(Folder,Folder) if err and not err:lower():find("permission denied") then os.execute("md "..Folder:gsub("/","\\")) end if not File:find("^"..Folder,1,true) then File = Folder.."/"..File end if loadfile(File) then dofile(File) Top.HubShare = HubRefresh(Core.GetCurrentSharedSize(),Top.HubShare,os.time()) Top.Users = HubRefresh(Core.GetMaxUsersPeak(),Top.Users,os.time()) Top.UserShare = GetValue(16,1024) Top.UpTimes = GetValue(25,60) else local t,tb = {},Core.GetOnlineUsers() Top = { HubShare = {{os.time(),Core.GetCurrentSharedSize()},}, Users = {{os.time(),Core.GetUsersCount()},}, UserShare = GetValue(16,1024), UpTimes = GetValue(25,60), Logins = GetLogins(), ReConnections ={}, Chat = {}, ChatChars = {}, Pms = {}, PmChars = {}, Cmds = {}, Smilies = {}, Lols = {}, CTMs = {}, Searches = {}, Kicks = {}, Redirs = {}, Pingers = {}, Unknowns = {}, } end local Pfx,Hub = SetMan.GetString(29):sub(1,1),SetMan.GetString(0) assert(Pfx) assert(Hub) Cnt = #Order local om = "" for _,s in ipairs(Order) do if Report then om = om..GetTen(Top[s],s) end if not Top[s] then Top[s] = {} end UserCmds = UserCmds.."$UserCommand 1 3 "..Hub.."\\"..Scp.."\\Clear\\"..s.."$<%[mynick]> "..Pfx..s.."-||".. "$UserCommand 0 3 ||$UserCommand 1 3 "..Hub.."\\"..Scp.."\\"..s.."$<%[mynick]> "..Pfx..s.."||" end SaveFile(File,Top,"Top") if Report and om:len() > 0 then OnError(om,true) endendOnExit = function() SaveFile(File,Top,"Top") endOnError = function(msg,pm) local user = Core.GetUser(OpNick) if user then if pm then Core.SendPmToUser(user,Bot,msg.."|") else Core.SendToUser(user,"<"..Bot.."> "..msg.."|") end endendOnTimer = function(Id) Top.HubShare = HubRefresh(Core.GetCurrentSharedSize(),Top.HubShare,os.time()) Top.Users = HubRefresh(Core.GetMaxUsersPeak(),Top.Users,os.time()) if Id == Save then SaveFile(File,Top,"Top") end if Id == Pause then TmrMan.RemoveTimer(Pause) Pause = 0 endendUserConnected = function(user) Pause = TmrMan.AddTimer(2000) Refresh(user,Top.Logins,1) Top.UserShare = GetValue(16,1024,Top.UserShare) Top.HubShare = HubRefresh(Core.GetCurrentSharedSize(),Top.HubShare,os.time()) if Profiles[user.iProfile] then local Prof,Plural = "Unregistered User","" if user.iProfile ~= -1 then Prof = ProfMan.GetProfile(user.iProfile).sProfileName end if Cnt > 1 then Plural = "s" end local msg = "<"..Bot.."> "..Prof.."'s "..Scp.." commands enabled. Right click ".. "hub tab or user list for menu. "..tostring(Cnt).." listing"..Plural.." available.|" Core.SendToUser(user,UserCmds..msg) endendOpConnected,RegConnected = UserConnected,UserConnectedUserDisconnected = function(user) local x,n = TmrMan.AddTimer(10000,"ChkReConn"),user.sNick if x and n and x ~= -1 then table.insert(ReConn,{n,x}) end if next(Top["UpTimes"]) then for i,v in ipairs(Top["UpTimes"]) do if v[1] == user.sNick then if v[3] then v[3] = v[3] + os.time() - v[2] else v[3] = os.time() - v[2] end SaveFile(File,Top,"Top") end end endendRegDisconnected,OpDisconnected = UserDisconnected,UserDisconnectedChatArrival = function(user,data) local _,_,cmd,clr = data:find("%b<> ["..SetMan.GetString(29).."](%a+)([-]*)") local _,_,to = data:find("^$To: (%S+) From:") local _,_,msg = data:find("%b<> ([^|]+)|") local x = msg:len() if cmd then Refresh(user,Top.Cmds,1) if cmd:lower() == "allstats" then local Reply = "" for _,s in ipairs(Order) do if s:lower() ~= "allstats" then Reply = Reply..GetTen(Top[s],s) end end return Core.SendPmToUser(user,Bot,Reply.."|"),true end if Profiles[user.iProfile] and Top[cmd] then if clr and clr == "-" then if next(Top[cmd]) then Top[cmd] = {} if not next(Top[cmd]) then SaveFile(File,Top,"Top") return Core.SendToUser(user,"<"..Bot.."> ".. cmd.." has been cleared|"),true end else return Core.SendToUser(user,"<"..Bot.."> Error! The ".. cmd.." table is already empty.|"),true end else return Core.SendToUser(user,"<"..Bot.."> "..GetTen(Top[cmd],cmd).."|"),true end end end if to then Refresh(user,Top.Pms,1) if x > 0 then Refresh(user,Top.PmChars,x) end else Refresh(user,Top.Chat,1) if x > 0 then Refresh(user,Top.ChatChars,x) end end Update(user,data,Asc,Top.Smilies) Update(user,data,Acr,Top.Lols)endToArrival = ChatArrivalKickArrival = function(user,data) Refresh(user,Top.Kicks,1)endUnknownArrival = function(user,data) Refresh(user,Top.Unknowns,1)endOpForceMoveArrival = function(user,data) Refresh(user,Top.Redirs,1)endConnectToMeArrival = function(user,data) Refresh(user,Top.CTMs,1)endRevConnectToMeArrival,MultiConnectToMeArrival = ConnectToMeArrival,ConnectToMeArrivalSearchArrival = function(user,data) Refresh(user,Top.Searches,1)endMultiSearchArrival = SearchArrivalBotINFOArrival = function(user,data) Refresh(user,Top.Pingers,1)endChkReConn = function(Id) if ReConn then if next(ReConn) then for i = 1, #ReConn do if type(ReConn[i]) == "table" and #ReConn[i] == 2 then if ReConn[i][2] == Id then local user = Core.GetUser(ReConn[i][1]) if user then Refresh(user,Top.ReConnections,1) SaveFile(File,Top,"Top") end ReConn[i] = nil end else ReConn[i] = nil TmrMan.RemoveTimer(Id) end end end else ReConn = {} endendGetLogins = function() local t,tb = {},Core.GetOnlineUsers() if next(tb) then for _,u in ipairs(tb) do table.insert(t,{u.sNick,1}) end end return tendHubRefresh = function(count,tab,date) if tab then local chg,min,tot = false,0,0 if next(tab) then for i,v in ipairs(tab) do min = math.max(min,v[2]) tot = tot + v[2] end end if not date then return math.max(count,min),tot end if count > min then local chk = function(t,i) for i,v in ipairs(t) do if i == v[2] then return false end return true end end if chk(tab,count) then table.insert(tab,{os.time(),count}) end table.sort(tab,function(a,b) return a[2] > b[2] end) while #tab > 10 do table.remove(tab,#tab) table.sort(tab,function(a,b) return a[2] > b[2] end) end end end return tabendRefresh = function(user,tab,x) if tab then local chg = false if next(tab) then for i,v in ipairs(tab) do if v[1]:lower() == user.sNick:lower() then v[2] = v[2] + x chg = true break end end end if not chg then table.insert(tab,{user.sNick,x}) end table.sort(tab,function(a,b) return a[2] > b[2] end) while #tab > 10 do table.remove(tab,#tab) table.sort(tab,function(a,b) return a[2] > b[2] end) end endendUpdate = function(user,data,arr,tab) local bool,x = false,0 data = data:sub(1,-2):lower() for _,code in ipairs(arr) do code = code:gsub("[%p]","%%%1") local chr,count = data:gsub(code,"%1") if count and count > 0 then x = x + count end end if x > 0 then Refresh(user,tab,x) bool = true end return boolendGetValue = function(val,min,tab) local t = {} for _,user in ipairs(Core.GetOnlineUsers()) do local x = Core.GetUserValue(user,val) if x > min then local chk = function(t,i) for i,v in ipairs(t) do if i == v[2] then return false end return true end end if not tab or chk(tab,x) then table.insert(t,{user.sNick,tonumber(x)}) end end end if next(t) then table.sort(t,function(a,b) return a[2] > b[2] end) while #t > 10 do table.remove(t,#t) end end return tendGetTen = function(t,h) local s,x,y,c,m,f,hdr,bar,art,col = "",0,0,0,"","40.50","",GraphChar,"¯","User Nick" if t and next(t) then if h:lower():find("^uptimes$") then table.sort(t, function(a,b) return a[2] < b[2] end) else table.sort(t, function(a,b) return a[2] > b[2] end) end for i,v in ipairs(t) do x = x + v[2] end y = x for i,v in ipairs(t) do if i < 11 and v[2] > 0 then local n,z,k,sp = v[1],v[2],v[2],"" if h:lower():find("^hubshare$") or h:lower():find("^users$") then if h:lower():find("^hubshare$") then x,c = HubRefresh(Core.GetCurrentSharedSize(),Top.HubShare) m,y,z = FmtSz(c/#t,3),FmtSz(x,3),FmtSz(v[2],3) else _,c = HubRefresh(Core.GetMaxUsersPeak(),Top.Users) x,m,y,z = Core.GetMaxUsersPeak(),tostring(math.ceil(c/#t)),tostring(x),tostring(v[2]) end f,n,col = "20.15",os.date("%m/%d/%Y",v[1]),"Date" elseif h:lower():find("^uptimes$") then x,m,y,z,f,k = Core.GetUpTime(),Convert(os.time() - (x/10),6),Convert(os.time() - x,6),Convert(v[2],6),"40.50",os.time()-k if z and z:len() < 10 then sp = sp.."\t" end elseif h:lower():find("^usershare$") then m,y,z,f = FmtSz(x/#t),FmtSz(x),FmtSz(v[2]),"20.15" else m = tostring(math.ceil(x/#t)) end local pct,mod = (k/x) * 100,"" if pct > 100 then mod = "+" end pct = math.min(pct,100) s = s.."\t"..i..")\t"..string.format("%-"..f.."s ",z)..sp.."\t"..mod.. string.format("%-15.7s ",string.format("%.2f%%",pct)).."\t"..n.."\n\t".. bar..bar:rep(pct).."\n" end end hdr = "\n\n\tTop Ten "..h.." Total: `\t\tMean: "..m.."\n\t"..bar:rep(101).."\n\t"..art:rep(65).."\n".. "\t#)\t"..string.format("%-"..f.."s ",h).."\tPercent Total\t"..col.."\n\n\t"..art:rep(65).."\n" return hdr:gsub("`",y)..s else return "Sorry, there isn't any "..string.format("%q",h).." data available at this time.\n" endendFmtSz = function(int,dec) dec = dec or 2 local i,u,x= int or 0,{"","K","M","G","T","P"},1 while i > 1024 do i,x = i/1024,x+1 end return string.format("%."..dec.."f %sB.",i,u[x])endConvert = function(time,inc) local s,x,n = "",0,os.time() local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"}, {86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}} inc = inc or #tab if time > 0 and time < n then time = n - time for i,v in ipairs(tab) do if i <= inc and time > v[1] then x = math.floor(time/v[1]) if x > 1 then v[2] = v[2].."s" end if x > 0 then s = s..x.." "..v[2]..", " time = time-x*v[1] end end end return s:sub(1,-3) else local a,b = os.date("%m/%d/%Y",86400),os.date("%m/%d/%Y",2145876658) return "Invalid time supplied. [must be > "..a.." and < "..b.."]" endendSaveFile = function(file,table, tablename ) local hFile = io.open (file , "wb") Serialize(table, tablename, hFile) hFile:close() collectgarbage("collect")endSerialize = function(tTable, sTableName, hFile, sTab) local x = pairs sTab = sTab or ""; if type(sTab) == "table" and next(sTab) then x = ipairs end hFile:write(sTab..sTableName.." = {\n" ) for key, value in x(tTable) do local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key) if(type(value) == "table") then Serialize(value, sKey, hFile, sTab.."\t") else local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value) hFile:write( sTab.."\t"..sKey.." = "..sValue) end hFile:write( ",\n") end hFile:write( sTab.."}")end