PM Counter [API 2]
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

PM Counter [API 2]

Started by Daywalker?, 15 February, 2009, 15:40:43

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Daywalker?

--// 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  ;)

?StIfFLEr??

Got the following error
Quote<AndAnotherOne> ...igabyte renewed ---by stiffler\scripts\pmcounter.lua:113: attempt to concatenate global 'Pfx' (a nil value)

Daywalker?

you get this error in a running hub?

?StIfFLEr??

Yep got that error in main chat In a running hub.The script started but it had the following error.

Daywalker?

As Mutor allready mentioned can you give some more details about the version and OS it's running on? (GUI,service or posix)

?StIfFLEr??

I am using GUI version.

Daywalker?

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

SMF spam blocked by CleanTalk