RecordBot
 

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

RecordBot

Started by Tw?sT?d-d?v, 01 December, 2007, 23:25:20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tw?sT?d-d?v

Can somebody finish converting this please   ....  i get so many errors now ,that i get lost looking for them
Here is what i got so far ... 

--[[

	RecordBot 1.6 - LUA 5.0/5.1 by jiten (11/8/2006)

	Based on RecordBot vKryFinal written by bonki 2003

	Description: Logs and displays a hub's all time share and user record.

	- Fixed: Huge users bug and some stuff (thx to T?M??r?V?lleR)
	- Fixed: Stats sending before MOTD
	- Added: Top Share and Sharer Record (requested by XPMAN)
	- Added: Reg Bot switch (requested by (uk)jay)
	- Fixed: Nil Max Sharer (thx Cosmos)
	- Added: Ignore List (requested by chettedeboeuf)
	- Fixed: User Record Time (11/26/2005)
	- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
	- Changed: Command Parsing and profile permission structure
	- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
	- Chaged: Some code rewritten
	- Added: Time/Date to each record message (requested by Troubadour)
	- Changed: Chat and ToArrival structure;
	- Removed: !rb.set command;
	- Merged: tSettings and Record table;
	- Changed: Some code bits and variables;
	- Updated: To LUA 5.1 (11/8/2006)

]]--

tSettings = {

	-- Bot Name
	sBot = "'([RECORD-BOT])'",

	-- Toggle automatically register Bot Name [true = on, false = off]
	bRegister = false,

	-- RecordBot DB
	fRecord = "tRecord.tbl",

	-- Ignore table
	tIgnore = { ["Tw?sT?d-d?v?l"] = 1, ["yournick"] = 1, },

	-- Top Sharer and Top Share validation delay (minutes)
	iDelay = 0,

	-- Message settings [ true = on, false = off ]

		-- Show report in Main
		bMain = true,

		-- Show report in PM
		bPM = false,

		-- Show report on Login
		bLogin = true,

	-- Commands
	sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"

}

tRecord, tDelay = {}, {}

OnStartup = function()
	if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
	if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end

end

ChatArrival = function(user,data)
	Core.GetUserAllData(user)
	-- Define vars
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot) or not to then
		-- Parse command
		local _,_, cmd = string.find(msg, "^%p(%S+)")
		-- Exists
		if cmd and tCommands[string.lower(cmd)] then
			cmd, user.SendMessage = string.lower(cmd), user.sData
			-- PM
			if to == tSettings.sBot then user.SendMessage = user.SendPM end
			-- If user has permission
			if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
				return tCommands[cmd].fFunction(user), 1
			else
				return user.SendMessage(tSettings.sBot, "*** Error: You are not allowed to use this command!"), 1
			end
		end
	end
end

ToArrival = ChatArrival

OnExit = function()
	SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end

tCommands = {
	[tSettings.sHelp] =	{ 
		fFunction = function(user)
			-- Header
			local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1 version by jiten "..
			"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
			-- Loop through table
			for i,v in pairs(tCommands) do
				-- If user has permission
				if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
					-- Populate
					sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
				end
			end
			-- Send
			user:SendMessage(tSettings.sBot, sMsg.."\t\t\t"..string.rep("-",160));
		end, 
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 0, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
		},
		tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
	},
	[tSettings.sShow] = { 
		fFunction = function(user)
			if next(tRecord) then
				local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
				"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
				"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
				"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
				")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
				user:SendMessage(tSettings.sBot, msg)
			else
				user:SendMessage(tSettings.sBot, "*** Error: No records have been saved.")
			end
		end,
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1, 
		},
		tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
	},
	[tSettings.sReset] = {
		fFunction = function(user)
			tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
		end, 
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1, 
		},
		tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
	},
};

UserConnected = function(user)
	Core.GetUserAllData(user)
	if not tSettings.tIgnore[user.sNick] then
		local iUserCount = Core.GetUsersCount()
		tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
		if (iUserCount > tRecord.iUsers) then
			tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
			if tSettings.bPM then
				Core.SendPmToNick(user.sNick, "*** Thanks, buddie. You've just raised the all-time share record!");
			end;
			if tSettings.bMain then
				Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
				tRecord.iUsers.." users at "..os.date().." :)");
			end;
		end
		tDelay[user] = {}
		tDelay[user]["iTime"] = tSettings.iDelay*60
	end
end

OpConnected = UserConnected

OnTimer = function(tmr)
	for nick,v in pairs(tDelay) do
		tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
		if tDelay[nick]["iTime"] <= 0 then
			if GetItemByName(nick.sNick) then
				local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), nick.iShareSize, nick.sNick
				tRecord.iShare = (tRecord.iShare or 0)
				if (iTotalShare > tRecord.iShare) then
					tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
				end

				tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
				if (iShare > tRecord.iMaxSharer) then
					tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, "*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); 	end;
				end

				if tSettings.bLogin then
					local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
					string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
					(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
					(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
					" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n"
					Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> ".. sMsg)
				end;
			end
			tDelay[nick] = nil
		end
	end
end

-- By kepp and NotRambitWombat 
DoShareUnits = function(intSize)
	if intSize and intSize ~= 0 then 
		local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
		for index in ipairs(tUnits) do 
			if(intSize < 1024) then sUnits = tUnits[index];  break;  else   intSize = intSize / 1024;  end 
		end 
		return string.format("%0.1f %s",intSize, sUnits);
	end 
end

Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key,value in pairs(tTable) do
		if (type(value) ~= "function") then
			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
	end
	hFile:write(sTab.."}");
end

SaveToFile = function(table,tablename,file)
	local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close() 
end

speedX

Try this:

-- This script is converted with PtokaX LUA API Converter v0.9 at 12/07/07 12:34:41
--[[

	RecordBot 1.6 - LUA 5.0/5.1 by jiten (11/8/2006)

	Based on RecordBot vKryFinal written by bonki 2003

	Description: Logs and displays a hub's all time share and user record.

	- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
	- Fixed: Stats sending before MOTD
	- Added: Top Share and Sharer Record (requested by XPMAN)
	- Added: Reg Bot switch (requested by (uk)jay)
	- Fixed: Nil Max Sharer (thx Cosmos)
	- Added: Ignore List (requested by chettedeboeuf)
	- Fixed: User Record Time (11/26/2005)
	- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
	- Changed: Command Parsing and profile permission structure
	- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
	- Chaged: Some code rewritten
	- Added: Time/Date to each record message (requested by Troubadour)
	- Changed: Chat and ToArrival structure;
	- Removed: !rb.set command;
	- Merged: tSettings and Record table;
	- Changed: Some code bits and variables;
	- Updated: To LUA 5.1 (11/8/2006)

]]--

tSettings = {

	-- Bot Name
	sBot = "RecordBot",

	-- Toggle automatically register Bot Name [true = on, false = off]
	bRegister = true,

	-- RecordBot DB
	fRecord = "tRecord.tbl",

	-- Ignore table
	tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },

	-- Top Sharer and Top Share validation delay (minutes)
	iDelay = 0,

	-- Message settings [ true = on, false = off ]

		-- Show report in Main
		bMain = true,

		-- Show report in PM
		bPM = false,

		-- Show report on Login
		bLogin = true,

	-- Commands
	sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"

}

tRecord, tDelay = {}, {}

OnStartup = function()
	if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
	if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end

end

ChatArrival = function(user,data)
	Core.GetUserAllData(user)
	-- Define vars
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot) or not to then
		-- Parse command
		local _,_, cmd = string.find(msg, "^%p(%S+)")
		-- Exists
		if cmd and tCommands[string.lower(cmd)] then
			cmd, user.SendMessage = string.lower(cmd), user.SendData
			-- PM
			if to == tSettings.sBot then user.SendMessage = user.SendPM end
			-- If user has permission
			if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
				return tCommands[cmd].fFunction(user), 1
			else
				return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), 1
			end
		end
	end
end

ToArrival = ChatArrival

OnExit = function()
	SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end

tCommands = {
	[tSettings.sHelp] =	{ 
		fFunction = function(user)
			-- Header
			local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1 version by jiten "..
			"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
			-- Loop through table
			for i,v in pairs(tCommands) do
				-- If user has permission
				if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
					-- Populate
					sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
				end
			end
			-- Send
			Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..sMsg.." \t\t\t"..string.rep("-",160));
		end, 
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
		},
		tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
	},
	[tSettings.sShow] = { 
		fFunction = function(user)
			if next(tRecord) then
				local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
				"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
				"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
				"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
				")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..msg.."|")
			else
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: No records have been saved.")
			end
		end,
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1, 
		},
		tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
	},
	[tSettings.sReset] = {
		fFunction = function(user)
			tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
		end, 
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1, 
		},
		tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
	},
};

UserConnected = function(user)
	Core.GetUserAllData(user)
	if not tSettings.tIgnore[user.sNick] then
		local iUserCount = Core.GetUsersCount()
		tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
		if (iUserCount > tRecord.iUsers) then
			tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
			if tSettings.bPM then
				Core.SendPmToNick(user.sNick, "*** Thanks, buddie. You've just raised the all-time share record!");
			end;
			if tSettings.bMain then
				Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
				tRecord.iUsers.." users at "..os.date().." :)");
			end;
		end
		tDelay[user] = {}
		tDelay[user]["iTime"] = tSettings.iDelay*60
	end
end

OpConnected = UserConnected

OnTimer = function(tmr)
	for nick,v in pairs(tDelay) do
		tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
		if tDelay[nick]["iTime"] <= 0 then
			if GetItemByName(nick.sNick) then
				local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), nick.iShareSize, nick.sNick
				tRecord.iShare = (tRecord.iShare or 0)
				if (iTotalShare > tRecord.iShare) then
					tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
				end

				tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
				if (iShare > tRecord.iMaxSharer) then
					tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, "*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); 	end;
				end

				if tSettings.bLogin then
					local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
					string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
					(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
					(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
					" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n"
					Core.SendToNick(nick.sNick,"<"..tSettings.sBot.."> ".. sMsg)
				end;
			end
			tDelay[nick] = nil
		end
	end
end

-- By kepp and NotRambitWombat 
DoShareUnits = function(intSize)
	if intSize and intSize ~= 0 then 
		local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
		for index in ipairs(tUnits) do 
			if(intSize < 1024) then sUnits = tUnits[index];  break;  else   intSize = intSize / 1024;  end 
		end 
		return string.format("%0.1f %s",intSize, sUnits);
	end 
end

Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key,value in pairs(tTable) do
		if (type(value) ~= "function") then
			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
	end
	hFile:write(sTab.."}");
end

SaveToFile = function(table,tablename,file)
	local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close() 
end
RegConnected = UserConnected



Used Hungarista's New API convertor and modified some code...
Thanking You,

speedX

Tw?sT?d-d?v

Thx for that m8   

Ive got 2 probs with it though . 
1, it dont show records on login
-- Show report on Login
		bLogin = true,

and 2, cmds show in main.
[14:16:11] <RecordBot> 

			================================================================================
						RecordBot - LUA 5.1 version by jiten 			
			----------------------------------------------------------------------------------------------------------------------------------------------------------------
			Available Commands:

			!rb.reset			Resets all records				!rb.reset
			!rb.help			Displays this help message			!rb.help
			!rb.show			Shows this hub's all time share and user record	!rb.show
 			----------------------------------------------------------------------------------------------------------------------------------------------------------------
[14:16:11] <Tw?sT?d-d?v?l> !rb.help

speedX

Please try this:

-- This script is converted with PtokaX LUA API Converter v0.9 at 12/07/07 12:34:41
--[[

	RecordBot 1.6 - LUA 5.0/5.1 by jiten (11/8/2006)

	Based on RecordBot vKryFinal written by bonki 2003

	Description: Logs and displays a hub's all time share and user record.

	- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
	- Fixed: Stats sending before MOTD
	- Added: Top Share and Sharer Record (requested by XPMAN)
	- Added: Reg Bot switch (requested by (uk)jay)
	- Fixed: Nil Max Sharer (thx Cosmos)
	- Added: Ignore List (requested by chettedeboeuf)
	- Fixed: User Record Time (11/26/2005)
	- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
	- Changed: Command Parsing and profile permission structure
	- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
	- Chaged: Some code rewritten
	- Added: Time/Date to each record message (requested by Troubadour)
	- Changed: Chat and ToArrival structure;
	- Removed: !rb.set command;
	- Merged: tSettings and Record table;
	- Changed: Some code bits and variables;
	- Updated: To LUA 5.1 (11/8/2006)

]]--

tSettings = {

	-- Bot Name
	sBot = "RecordBot",

	-- Toggle automatically register Bot Name [true = on, false = off]
	bRegister = true,

	-- RecordBot DB
	fRecord = "tRecord.tbl",

	-- Ignore table
	tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },

	-- Top Sharer and Top Share validation delay (minutes)
	iDelay = 0,

	-- Message settings [ true = on, false = off ]

		-- Show report in Main
		bMain = true,

		-- Show report in PM
		bPM = false,

		-- Show report on Login
		bLogin = true,

	-- Commands
	sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"

}

tRecord, tDelay = {}, {}

OnStartup = function()
	if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
	if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end

end

ChatArrival = function(user,data)
	Core.GetUserAllData(user)
	-- Define vars
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot) or not to then
		-- Parse command
		local _,_, cmd = string.find(msg, "^%p(%S+)")
		-- Exists
		if cmd and tCommands[string.lower(cmd)] then
			cmd, user.SendMessage = string.lower(cmd), user.SendData
			-- PM
			if to == tSettings.sBot then user.SendMessage = user.SendPM end
			-- If user has permission
			if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
				return tCommands[cmd].fFunction(user), 1
			else
				return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), 1
			end
		end
	end
end

ToArrival = ChatArrival

OnExit = function()
	SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end

tCommands = {
	[tSettings.sHelp] =	{ 
		fFunction = function(user)
			-- Header
			local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1 version by jiten "..
			"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
			-- Loop through table
			for i,v in pairs(tCommands) do
				-- If user has permission
				if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
					-- Populate
					sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
				end
			end
			-- Send
			Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..sMsg.." \t\t\t"..string.rep("-",160));
		end, 
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
		},
		tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp.."",
	},
	[tSettings.sShow] = { 
		fFunction = function(user)
			if next(tRecord) then
				local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
				"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
				"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
				"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
				")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..msg.."|")
			else
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: No records have been saved.")
			end
		end,
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1, 
		},
		tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
	},
	[tSettings.sReset] = {
		fFunction = function(user)
			tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
		end, 
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1, 
		},
		tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
	},
};

UserConnected = function(user)
	Core.GetUserAllData(user)
	if not tSettings.tIgnore[user.sNick] then
		local iUserCount = Core.GetUsersCount()
		tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
		if (iUserCount > tRecord.iUsers) then
			tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
			if tSettings.bPM then
				Core.SendPmToNick(user.sNick, "*** Thanks, buddie. You've just raised the all-time share record!");
			end;
			if tSettings.bMain then
				Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
				tRecord.iUsers.." users at "..os.date().." :)");
			end;
		end
		tDelay[user] = {}
		tDelay[user]["iTime"] = tSettings.iDelay*60
	end
end

OpConnected = UserConnected

OnTimer = function(tmr)
	for nick,v in pairs(tDelay) do
		tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
		if tDelay[nick]["iTime"] <= 0 then
			if GetItemByName(nick.sNick) then
				local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), nick.iShareSize, nick.sNick
				tRecord.iShare = (tRecord.iShare or 0)
				if (iTotalShare > tRecord.iShare) then
					tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
				end

				tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
				if (iShare > tRecord.iMaxSharer) then
					tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, "*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); 	end;
				end

				if tSettings.bLogin then
					local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
					string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
					(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
					(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
					" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n"
					Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> ".. sMsg)
				end;
			end
			tDelay[nick] = nil
		end
	end
end

-- By kepp and NotRambitWombat 
DoShareUnits = function(intSize)
	if intSize and intSize ~= 0 then 
		local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
		for index in ipairs(tUnits) do 
			if(intSize < 1024) then sUnits = tUnits[index];  break;  else   intSize = intSize / 1024;  end 
		end 
		return string.format("%0.1f %s",intSize, sUnits);
	end 
end

Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key,value in pairs(tTable) do
		if (type(value) ~= "function") then
			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
	end
	hFile:write(sTab.."}");
end

SaveToFile = function(table,tablename,file)
	local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close() 
end
RegConnected = UserConnected
Thanking You,

speedX

Tw?sT?d-d?v

Still the same   plus no rightclick menu sent either.  showing no error in PX to

btw  im now using 0.3.6.0j

speedX

Quote from: Tw?sT?d-d?v?l on 07 December, 2007, 17:06:26
Still the same   plus no rightclick menu sent either.  showing no error in PX to

btw  im now using 0.3.6.0j

Hmmm.....I tried, maybe u'll have to wait until some scripter converts it :( srry....
Thanking You,

speedX

Tw?sT?d-d?v

thanks for tryin    ;D

Cêñoßy†ê

#7
Try this one ;)

--[[

	RecordBot 1.6 - LUA 5.0/5.1 by jiten (11/8/2006)

	Based on RecordBot vKryFinal written by bonki 2003

	Description: Logs and displays a hub's all time share and user record.

	- Fixed: Huge users bug and some stuff (thx to T?M??r?V?ll?R)
	- Fixed: Stats sending before MOTD
	- Added: Top Share and Sharer Record (requested by XPMAN)
	- Added: Reg Bot switch (requested by (uk)jay)
	- Fixed: Nil Max Sharer (thx Cosmos)
	- Added: Ignore List (requested by chettedeboeuf)
	- Fixed: User Record Time (11/26/2005)
	- Added: Top Sharer and Share validation delay (requested by chettedeboeuf)
	- Changed: Command Parsing and profile permission structure
	- Fixed: Top Sharer and Share Delay bug (thx to chettedeboeuf)
	- Chaged: Some code rewritten
	- Added: Time/Date to each record message (requested by Troubadour)
	- Changed: Chat and ToArrival structure;
	- Removed: !rb.set command;
	- Merged: tSettings and Record table;
	- Changed: Some code bits and variables;
	- Updated: To LUA 5.1 (11/8/2006)
	- Updated: To PtokaX API 2 (07/12/2007)
	* Changed Login message from timer to userconnected =) (08/12/2007)

]]--

tSettings = {

	-- Bot Name
	sBot = "RecordBot",

	-- Toggle automatically register Bot Name [true = on, false = off]
	bRegister = true,

	-- RecordBot DB
	fRecord = "tRecord.tbl",

	-- Ignore table
	tIgnore = { ["jiten"] = 1, ["yournick"] = 1, },

	-- Top Sharer and Top Share validation delay (minutes)
	iDelay = 0,

	-- Message settings [ true = on, false = off ]

		-- Show report in Main
		bMain = true,

		-- Show report in PM
		bPM = false,

		-- Show report on Login
		bLogin = true,

	-- Commands
	sHelp = "rb.help", sShow = "rb.show", sSetup = "rb.set", sReset = "rb.reset"

}

tRecord, tDelay = {}, {}

OnStartup = function()
	if (tSettings.sBot ~= SetMan.GetString(21) or tSettings.bRegister) then Core.RegBot(tSettings.sBot,"","",true) end
	if loadfile(tSettings.fRecord) then dofile(tSettings.fRecord) end
	TmrMan.AddTimer(60*1000,"Timer")
end

ChatArrival = function(user,data)
	Core.GetUserAllData(user)
	-- Define vars
	local _,_, to = string.find(data, "^$To:%s(%S+)%s+From:")
	local _,_, msg = string.find(data, "%b<>%s(.*)|$") 
	-- Message sent to Bot or in Main
	if (to and to == tSettings.sBot) or not to then
		-- Parse command
		local _,_, cmd = string.find(msg, "^%p(%S+)")
		-- Exists
		if cmd and tCommands[string.lower(cmd)] then
			cmd, user.SendMessage = string.lower(cmd), Core.SendToNick
			-- PM
			if to == tSettings.sBot then user.SendMessage = Core.SendPMToNick end
			-- If user has permission
			if tCommands[cmd].tLevels[user.iProfile] and tCommands[cmd].tLevels[user.iProfile] == 1 then
				return tCommands[cmd].fFunction(user), true
			else
				return Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: You are not allowed to use this command!"), 1
			end
		end
	end
end

ToArrival = ChatArrival

OnExit = function()
	SaveToFile(tRecord, "tRecord", tSettings.fRecord)
end

tCommands = {
	[tSettings.sHelp] =	{ 
		fFunction = function(user)
			-- Header
			local sMsg = "\r\n\r\n\t\t\t"..string.rep("=", 80).."\r\n"..string.rep("\t", 6).."RecordBot - LUA 5.1 version by jiten "..
			"\t\t\t\r\n\t\t\t"..string.rep("-", 160).."\r\n\t\t\tAvailable Commands:".."\r\n\r\n"
			-- Loop through table
			for i,v in pairs(tCommands) do
				-- If user has permission
				if v.tLevels[user.iProfile] and v.tLevels[user.iProfile] == 1 then
					-- Populate
					sMsg = sMsg.."\t\t\t!"..i.."\t\t"..v.tDesc.."\r\n"
				end
			end
			-- Send
			Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..sMsg.." \t\t\t"..string.rep("-",160));
		end, 
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1,
		},
		tDesc = "\tDisplays this help message\t\t\t!"..tSettings.sHelp,
		tRC = "\\Display help message$<%[mynick]> !"..tSettings.sHelp,
	},
	[tSettings.sShow] = { 
		fFunction = function(user)
			if next(tRecord) then
				local msg = "\r\n\r\n\t"..string.rep ("=", 50).."\r\n\tRecord\t\tValue\t\tDate - Time\n\t"..string.rep ("-", 100).."\r\n"..
				"\tShare\t\t"..(DoShareUnits(tRecord.iShare) or 0).." \t\t"..(tRecord.tShare or "n/a")..
				"\r\n\tUsers\t\t"..(tRecord.iUsers or 0).." user(s)\t\t"..(tRecord.tUsers or "n/a")..
				"\r\n\tTop Sharer\t"..(tRecord.sMaxSharer or "n/a").." ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..
				")\t"..(tRecord.tMaxSharer or "n/a").."\r\n\t"..string.rep ("-", 100)
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> "..msg.."|")
			else
				Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> *** Error: No records have been saved.")
			end
		end,
		tLevels = {
			[-1] = 1, [0] = 1, [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1, 
		},
		tDesc = "\tShows this hub's all time share and user record\t!"..tSettings.sShow,
		tRC = "\\Display share and user record$<%[mynick]> !"..tSettings.sShow,
	},
	[tSettings.sReset] = {
		fFunction = function(user)
			tRecord = {}; Core.SendToAll("<"..tSettings.sBot.."> *** Hub records have been reset!");
		end, 
		tLevels = {
			[-1] = 0, [0] = 1, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 1, 
		},
		tDesc = "\tResets all records\t\t\t\t!"..tSettings.sReset,
		tRC = "\\Reset records$<%[mynick]> !"..tSettings.sReset,
	},
};

UserConnected = function(user)
	for _,cmd in pairs(tCommands) do
		if cmd.tLevels[user.iProfile] and cmd.tLevels[user.iProfile] == 1 then
			Core.SendToNick(user.sNick,"$UserCommand 1 3 "..tSettings.sBot..cmd.tRC.."&#124;")
		end
	end
	if tSettings.bLogin then
		local sMsg = "\r\n\r\n\t"..string.rep("=", 50).."\r\n\t\t\tStats\r\n\t"..
		string.rep("-", 100).."\r\n\r\n\tShare record: "..(DoShareUnits(tonumber(tRecord.iShare)) or 0).." [ "..
		(tRecord.tShare or "n/a").." ]\r\n\tUser record: "..(tRecord.iUsers or 0).." users [ "..
		(tRecord.tUsers or "n/a").." ]\r\n\tTop Sharer: "..(tRecord.sMaxSharer or "n/a")..
		" ("..(DoShareUnits(tRecord.iMaxSharer) or 0)..") [ "..(tRecord.tMaxSharer or "n/a").." ]\r\n"
		Core.SendToNick(user.sNick,"<"..tSettings.sBot.."> ".. sMsg)
	end
	Core.GetUserAllData(user)
	if not tSettings.tIgnore[user.sNick] then
		local iUserCount = Core.GetUsersCount()
		tRecord.iUsers, tRecord.tUsers = (tRecord.iUsers or 0), (tRecord.tUsers or "n/a")
		if (iUserCount > tRecord.iUsers) then
			tRecord.iUsers, tRecord.tUsers = iUserCount, os.date()
			if tSettings.bPM then
				Core.SendPmToNick(user.sNick, "*** Thanks, buddie. You've just raised the all-time share record!");
			end;
			if tSettings.bMain then
				Core.SendToAll("<"..tSettings.sBot.."> *** "..user.sNick.." has just raised the all-time user record to: "..
				tRecord.iUsers.." users at "..os.date().." :)");
			end;
		end
		tDelay[user] = {}
		tDelay[user]["iTime"] = tSettings.iDelay*60
	end
end

OpConnected = UserConnected
RegConnected = UserConnected

Timer = function(tmr)
	for nick,v in pairs(tDelay) do
		tDelay[nick]["iTime"] = tDelay[nick]["iTime"] - 1
		if tDelay[nick]["iTime"] <= 0 then
			if Core.GetUser(nick.sNick) then
				local iTotalShare, iShare, sNick = Core.GetCurrentSharedSize(), nick.iShareSize, nick.sNick
				tRecord.iShare = (tRecord.iShare or 0)
				if (iTotalShare > tRecord.iShare) then
					tRecord.iShare, tRecord.tShare = iTotalShare, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, tSettings.sBot, "*** Thanks, buddie. You have just raised the all-time share record to "..DoShareUnits(iTotalShare).." :)"); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." has just raised the all-time share record to: "..DoShareUnits(iTotalShare).." on "..os.date("%x")); end;
				end

				tRecord.iMaxSharer = (tRecord.iMaxSharer or 0)
				if (iShare > tRecord.iMaxSharer) then
					tRecord.iMaxSharer, tRecord.sMaxSharer, tRecord.tMaxSharer = iShare, nick.sNick, os.date()
					if tSettings.bPM then Core.SendPmToNick(nick.sNick, "*** Thanks, buddie. You are our highest sharer with: "..DoShareUnits(iShare).."."); end;
					if tSettings.bMain then Core.SendToAll("<"..tSettings.sBot.."> *** "..nick.sNick.." is our all-time biggest sharer with: "..DoShareUnits((iShare)).." since "..os.date("%x").." :)"); 	end;
				end
			end
			tDelay[nick] = nil
		end
	end
end

-- By kepp and NotRambitWombat 
DoShareUnits = function(intSize)
	if intSize and intSize ~= 0 then 
		local tUnits, intSize, sUnits = { "Bytes", "KB", "MB", "GB", "TB" }, tonumber(intSize)
		for index in ipairs(tUnits) do 
			if(intSize < 1024) then sUnits = tUnits[index];  break;  else   intSize = intSize / 1024;  end 
		end 
		return string.format("%0.1f %s",intSize, sUnits);
	end 
end

Serialize = function(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n");
	for key,value in pairs(tTable) do
		if (type(value) ~= "function") then
			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
	end
	hFile:write(sTab.."}");
end

SaveToFile = function(table,tablename,file)
	local hFile = io.open(file,"w+") Serialize(table,tablename,hFile); hFile:close() 
end
Powered By Leviathan™ 2nd Generation v. 1.9

Tw?sT?d-d?v

#8
:)  thx m8   this 1 works   

edit,
ive come across a prob ...   the login message lags between 30 - 60 secs or doesnt show at all

Cêñoßy†ê

Quote from: Tw?sT?d-d?v?l on 08 December, 2007, 11:20:31
:)  thx m8   this 1 works   

edit,
ive come across a prob ...   the login message lags between 30 - 60 secs or doesnt show at all

script above updated with fix =)
Powered By Leviathan™ 2nd Generation v. 1.9

Tw?sT?d-d?v

Thas was quick  :)   nice fix   thx again m8   ;D

SMF spam blocked by CleanTalk