PtokaX forum

Lua 5.3/5.2/5.1 Scripts (for PtokaX 0.4.0.0 and newer) => Finished Scripts => Topic started by: Daywalker? on 15 February, 2009, 15:40:43

Title: PM Counter [API 2]
Post by: Daywalker? on 15 February, 2009, 15:40:43
--// PM Counter v 0.02 by Daywalker?
--// updated some bugs reported by Sporos
--// fixed with help from Madman

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

local Owner = "Daywalker?" --// replace with your own name

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

local Max = 10 --// max shown list of users
--// Settings End

OnStartup = function()
Core.RegBot(Bot, Description, Email, true)
if loadfile(LPC) then dofile(LPC) else Save_File(LPC, PMC, "PMC") end
OnError("*** PM Counter v 0.02 for ".._VERSION.." made by Daywalker? has been started.")
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,from = string.find(data,"^$To: (%S+) From: (%S+)")
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 from then
if next(PMC) then
for i,v in pairs(PMC) do
if v[1]:lower() == user.sNick:lower() then
v[2] = v[2] + 1
table.remove(PMC,i)
table.insert(PMC,{user.sNick,v[2]})
Save_File(LPC, PMC, "PMC")
break
end
end
else
table.insert(PMC,{user.sNick,1})
Save_File(LPC, PMC, "PMC")
end
end
end

OnExit = function()
OnError("*** PM Counter v 0.02 for ".._VERSION.." made by Daywalker? has been stopped.")
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"
if next(PMC) then
table.sort(PMC, function(a,b) if a[2] > b[2] then return b[2] end end)
for i=1,Max do --// entered Max value for shown spam
if PMC[i] then
reply = reply.."\t["..i.."]\t"..string.format("%-15s",PMC[i][1]).."\t"..PMC[i][2].."\r\n"
end
end
return reply.."\n\t"..string.rep("?",40).."\r\n\r\n"
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()
collectgarbage("collect")
end


Hope it's works a little bit properly now  ;)
Title: Re: PM Counter [API 2]
Post by: ?StIfFLEr?? on 10 June, 2009, 21:20:46
Got the following error
Quote<AndAnotherOne> ...igabyte renewed ---by stiffler\scripts\pmcounter.lua:113: attempt to concatenate global 'Pfx' (a nil value)
Title: Re: PM Counter [API 2]
Post by: Daywalker? on 10 June, 2009, 22:17:15
you get this error in a running hub?
Title: Re: PM Counter [API 2]
Post by: ?StIfFLEr?? on 11 June, 2009, 12:18:12
Yep got that error in main chat In a running hub.The script started but it had the following error.
Title: Re: PM Counter [API 2]
Post by: Daywalker? on 11 June, 2009, 12:47:21
As Mutor allready mentioned can you give some more details about the version and OS it's running on? (GUI,service or posix)
Title: Re: PM Counter [API 2]
Post by: ?StIfFLEr?? on 12 June, 2009, 09:26:57
I am using GUI version.
Title: Re: PM Counter [API 2]
Post by: Daywalker? on 15 June, 2009, 12:01:39
When you use the GUI then the textbox where you can add/change the prefixes must be empty
to create such error.

change this:

Pfx = SetMan.GetString(29):sub(1,1)  into Pfx = "!" and let me know