Author Topic: pm counter  (Read 1406 times)

0 Members and 1 Guest are viewing this topic.

Offline Sporos

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
pm counter
« on: 14 February, 2009, 16:51:31 »
Code: [Select]
------ Code by Daywalker? ------


--// PM Counter by Daywalker?

--// Hub Settings
local Bot = "AndAnotherOne" --// botname
local Description = "ICountPmsForAliving" --// .
local Email = "wtfamidoinghere@hotmail.com" --// .
local Menu = "PM?" --// Menu name for RC

local Owner = "Sporos" --// replace with your own name

LPC = "LogPmCount.txt"
local Path = string.gsub(Core.GetPtokaXPath().."scripts/","/","\\")
LPC = Path..LPC

PMC = {}
local cPM = 0

OnStartup = function()
Core.RegBot(Bot, Description, Email, true)
if loadfile(LPC) then dofile(LPC) else Save_File(LPC, PMC, "PMC") end
Pfx = SetMan.GetString(29):sub(1,1)
collectgarbage("collect")
end

UserConnected = function(user) -- Is called when user finish login sequence.
EnterCmd(user)
end

OpConnected = UserConnected
RegConnected = UserConnected

ChatArrival = function(user, data)
local s,e,cmd = string.find( data, "%b<> %p(%w+)")
if cmd and tCom[cmd] then
local _,_,_,lev = tCom[cmd]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
local message = tCom[cmd](user,data,pre,cmd)
Core.SendToNick(user.sNick,"<"..Bot.."> "..message.."|")
collectgarbage("collect")
return true
end
end
end

ToArrival = function(user,data)
local s,e,to = string.find(data,"^$To: (%S+) From:")
local s,e,cmd = string.find( data, "%b<> %p(%w+)")
if cmd and tCom[cmd] then
local _,_,_,lev = tCom[cmd]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
if to and to == Bot then
Core.SendPmToNick(user.sNick,Bot,tCom[cmd](user,data,pre,cmd).."|")
end
collectgarbage("collect")
return true
end
end
if to then
cPM = cPM + 1
table.insert(PMC,{user.sNick,cPM})
Save_File(LPC, PMC, "PMC")
end
end

tCom = {
shpm = function(user,data)
if user then
local x
local reply = "\r\n\r\n\tTotal PM Calls\r\n\r\n\tList\tNick\t\tTotal\r\n"..
"\t"..string.rep("?",40).."\r\n"
for i,v in pairs(PMC) do
x = 1
reply = reply.."\t["..i.."]\t"..string.format("%-15s",v[1]).."\t"..v[2].."\r\n"
end
if x then
return reply.."\n\t"..string.rep("?",40).."\r\n\r\n"
else
return "Sorry "..user.sNick.." this command is disabled for your profile."
end
else
return "PM Count ", "Show All","", -- adjust this to your needs
-- Adjust To Your Profiles
{[-1] = 1,[0] = 1,[1] = 1,[2] = 1,[3] = 1,[4] = 1,[5] = 1,[6] = 1,}
end
end,
}

EnterCmd = function(user)
local x
for i,v in pairs(tCom) do
local menu,desc,arg,lev = tCom[i]()
if lev[user.iProfile] and lev[user.iProfile] == 1 then
x = 1
Core.SendToNick(user.sNick,"$UserCommand 1 3 "..Menu.."\\"..menu.."\\"..
desc.."$<%[mynick]> "..Pfx..i..arg.."&#124;|")
end
end
if x then
local Prof
if user.iProfile ~= -1 then
Prof = ProfMan.GetProfile(user.iProfile).sProfileName
else
Prof = "Unregistered User"
end
end
collectgarbage("collect")
end

OnError = function(sErrorMsg) -- Is called when error was found in script or whatever.
Core.SendToNick(Owner,"<"..Bot.."> "..sErrorMsg)
end

Save_Serialize = function(tTable, sTableName, hFile, sTab)
sTab = sTab or "";
hFile:write(sTab..sTableName.." = {\n" )
for key, value in pairs(tTable) do
local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
if(type(value) == "table") then
Save_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

Save_File = function(file,table, tablename )
local hFile = io.open (file , "wb")
Save_Serialize(table, tablename, hFile)
hFile:close()
end


------ End of Code ------



wonder if someone could help me with this script..... its working but i get this:



   Total PM Calls

   List   Nick      Total
   ????????????????????????????????????????
   [1]   Lost_in_Space     1
   [2]   Lost_in_Space     2
   [3]   Lost_in_Space     3
   [4]   Sporos            4
   [5]   Sporos            5
   [6]   Sporos            6
   [7]   Sporos            7
   [8]   Sporos            8

   ????????????????????????????????????????

But i want a summary of users pm and no a huge list with same nick like this one ...

? Top 100 private message talkers
---------------------------------------------------------------------------------------------------------
? Sporos         40 PM(s)      (after 15:105:41)


if anyone can help would be nice Thanks in advance :D
« Last Edit: 15 February, 2009, 15:26:10 by Mutor »

PtokaX forum

pm counter
« on: 14 February, 2009, 16:51:31 »

Offline Daywalker?

  • Scripter
  • Member
  • ******
  • Posts: 45
  • Karma: +9/-9
Re: pm counter
« Reply #1 on: 15 February, 2009, 15:42:04 »

PtokaX forum

Re: pm counter
« Reply #1 on: 15 February, 2009, 15:42:04 »