Update LUA5.11 -> LUA5.12
 

News:

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

Update LUA5.11 -> LUA5.12

Started by LeChuck, 05 March, 2008, 12:29:36

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LeChuck

Hello,
i need a Update of this Script to move it in PtokaX 0.3.6.0 with RoboCop 10.0.23 (LUA5.1.2).

--[[

	Chat History On Entry 1.06 LUA 5.11 [Strict][API 2]

	By Mutor			01/15/07

	Logs Main Chat and provides chat history
	in private message at user connect.

	-Provides manual history command
	-Provides delete message command
	-Provides delete all messages command
	-Provides history by days command
	-Provides chat history help command
	-Provides context menu [right click]
	-Optional max history entries
	-Optional number of messages sent at connect
	-Optional exclude pm at login per user

	+Changes from 1.05
		+Added Anti-advertisement options. Requested by sphinx


<BotName> Chat History Help

	Command			Description
	????????????????????????????????????????????
	+delchat        	Delete Single Chat Entry
	+history        	Get Chat History
	+togglehistory  	Toggle Chat History
	+dayhistory     	Chat History By Days
	+chathelp       	Chat History Help
	+delete         	Delete Chat History

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


]]

Cfg = {
-- Botname pulled from the hub or use "CustomName"
Bot = "[Historian]", --SetMan.GetString(21),
-- Bot description
Desc = "I send a message to new users.",
-- Bot email address
Mail = "user@domain.com",
-- Admin's profile
AdminProf = 0,
-- Admins nick for status / error messages
OpNick = "Mutor",
-- File to save chat data to
File = "HubChat.dat",
-- File to save chat data to
UserFile = "ChatUsers.dat",
-- Maximum number of lines to display on user connect
History = 10,
-- Maximum number of lines to cache
MaxChat = 50,
-- Context Menu Title
-- Menu = SetMan.GetString(0),
-- Context Submenu Title
-- SubMenu = "Chat History",
-- Set your profiles permissions here.
-- profile_idx, history enabled [0=no 1=yes], "Profile Name"
Profiles = {
	[-1] = {1,"Unregistered User"},
	[0] = {1,"Master"},
	[1] = {1,"Operator"},
	[2] = {1,"Vip"},
	[3] = {1,"Registered User"},
	},
-- Block Advert Strings? 0 = disabled, 1 = From History, 2 = From History/Main Chat
AaBlock = 2,
-- Message to send to user when advert trigger was found. "" = disabled [(user) will be replaced with user nick]
AaReply = "(user), your chat was blocked, don't advertise here please.",
-- External File Advert Strings "" = disabled
AaFile = "AntiAd.txt",
-- Default Anti-Advertisement triggers, if not using external file
AaTrigs = {
	"dchub:","http:","ftp:","hopto.org","myftp.biz","myftp.org","myvnc.com","no-ip.biz","no-ip.info","no-ip.org",
	"redirectme.net","servebeer.com","serveblog.net","servecounterstrike.com","serveftp.com","servegame.com",
	"servehalflife.com","servehttp.com","servemp3.com","servepics.com","servequake.com","sytes.net","mine.nu",
	"zapto.org","blogsyte.com","cable-modem.org","ciscofreak.com","damnserver.com","ditchyourip.com","bounceme.net",
	"dnsiskinky.com","geekgalaxy.com","homesecuritymac.com","homesecuritypc.com","myactivedirectory.com",
	"mymediapc.net","mypsx.net","net-freaks.com","no-ip.ca","no-ip.co.uk","no-ip.com","no-ip.net","point2this.com",
	"pointto.us","quicksytes.com","securityexploits.com","securitytactics.com","serveexchange.com","servehumour.com",
	"servep2p.com","servesarcasm.com","stufftoread.com","unusualperson.com","workisboring.com","dns2go","myftpsite",
	},
}

OnStartup = function()
	local LuaVer = _VERSION:sub(1,7)
	if LuaVer ~= "Lua 5.1" then
		return OnError("This script is incompatible with ".._VERSION),true
	end
	Cfg.Script = "Chat History 1.06 for PtokaX ".._VERSION.." by Mutor"
	Cfg.Pfx = SetMan.GetString(29):sub(1,1)
	if Cfg.Bot ~= SetMan.GetString(21) or Cfg.Bot ~= SetMan.GetString(21) and not SetMan.GetHubBot().bEnabled then
		Core.RegBot(Cfg.Bot,Cfg.Desc.." PtokaX ".._VERSION, Cfg.Mail,true)
	end
	Cfg.Path = string.gsub(Core.GetPtokaXPath().."scripts/","/","\\")
	Cfg.File = Cfg.Path..Cfg.File
	Cfg.UserFile = Cfg.Path..Cfg.UserFile
	if loadfile(Cfg.File) then
		dofile(Cfg.File)
		local f,e = io.open(Cfg.File)
		local size = f:seek("end")
		size = FormatSize(size)
		f:close()
		OnError(Cfg.File.." was found and executed. File size: "..
		size.." "..#Cfg.Chat.." entries.")
	else
		Cfg.Chat = {}
		local t = {
		tonumber(os.date("%Y") + os.date("%j")),
		os.date("%m/%d/%y"),
		os.date("%I:%M")..string.sub(string.lower(os.date("%p")),1,1),
		"<"..Cfg.Bot.."> Chat history file created "..
		os.date("on: %B %d, %Y at: %I:%M")..string.sub(string.lower(os.date("%p")),1,1)
		}
		table.insert(Cfg.Chat,t)
		SaveToFile(Cfg.File,Cfg.Chat,"Cfg.Chat")
		OnError(Cfg.File.." was not found. This file has been created for you.")
	end
	if loadfile(Cfg.UserFile) then
		dofile(Cfg.UserFile)
		local f,e = io.open(Cfg.UserFile)
		local size = f:seek("end")
		size = FormatSize(size)
		f:close()
		OnError(Cfg.UserFile.." was found and executed. File size: "..
		size.." "..#Cfg.Exclude.." entries.")
	else
		Cfg.Exclude = {}
		SaveToFile(Cfg.UserFile,Cfg.Exclude,"Cfg.Exclude")
		OnError(Cfg.UserFile.." was not found. This file has been created for you.")
	end
	if Cfg.AaFile ~= "" and loadfile(Cfg.AaFile) then
		dofile(Cfg.File)
	end
	OnError(Cfg.Script.." has been started. Memory usage: "..CleanMem())
end

OnExit = function()
	OnError(Cfg.Script.." has been stopped, freeing "..CleanMem().." of memory.")
end

OnError = function(msg)
	if Core.GetUser(Cfg.OpNick) then
		Core.SendToNick(Cfg.OpNick,"<"..Cfg.Bot.."> "..msg)
	end
end

ChatArrival = function(user, data)
	data = data:sub(1,-2)
	local _,_,to = data:find("^$To: (%S+) From:")
	local _,_,prefix = data:find("%b<> ([%p%d])")
	if not prefix and not to then
		local op = ProfMan.GetProfile(user.iProfile).tProfilePermissions.bIsOP
		if not op and ChkAd(data) and Cfg.AaBlock > 0 then
			if Cfg.AaReply ~= "" then
				Core.SendToUser(user,"<"..Cfg.Bot..">"..Cfg.AaReply:gsub("%(user%)",user.sNick).."|")
			end
			if Cfg.AaBlock == 2 then
				return true
			else
				return false
			end
		end
		local t = {
		tonumber(os.date("%Y") + os.date("%j")),
		os.date("%m/%d/%y"),
		os.date("%I:%M")..string.sub(string.lower(os.date("%p")),1,1),
		data,
		}
		table.insert(Cfg.Chat,t)
		for x = 1, #Cfg.Chat -  Cfg.MaxChat do
			table.remove(Cfg.Chat,1)
		end
		SaveToFile(Cfg.File,Cfg.Chat,"Cfg.Chat")
	else
		local _,_,cmd = data:find("%b<> %p(%w+)")
		if cmd and Cmds[cmd] then
			if Cfg.Profiles[user.iProfile] and Cfg.Profiles[user.iProfile][1] == 1 then
				if to and to == Cfg.Bot then
					return Core.SendPmToUser(user,Cfg.Bot,Cmds[cmd](user,data).."|"),true
				else
					return Core.SendToUser(user,"<"..Cfg.Bot.."> "..Cmds[cmd](user,data).."|"),true
				end
			else
				if to and to == Cfg.Bot then
					Core.SendPmToUser(user,Cfg.Bot,user.sNick..
					" you dont have permission to use this command.|")
				else
					Core.SendToUser(user,"<"..Cfg.Bot.."> "..user.sNick..
					" you dont have permission to use this command.|")
				end
				return true
			end
		end
	end
end
ToArrival = ChatArrival

UserConnected = function(user)
	if Cfg.Profiles[user.iProfile] and Cfg.Profiles[user.iProfile][1] == 1 then
		local Exclude = CheckEx(user)
		if not Exclude then
			local add = "\n\n\tType "..Cfg.Pfx.."togglehistory to disable this message.\n\n"
			Core.SendPmToUser(user,Cfg.Bot,add..GetChat(Cfg.History).."|")
		end
	end
	if SendCmds(user) then
		local Profile = ProfName(user)
		Core.SendToUser(user,"<"..Cfg.Bot.."> "..Profile.."'s Chat History 1.06 "..
		"commands enabled. Right click hub tab for command menu.|")
	end
end
RegConnected,OpConnected = UserConnected,UserConnected

CleanMem = function()
	collectgarbage("collect")
	Cfg.Mem = string.format("%-.2f Kb.",collectgarbage("count"))
	return Cfg.Mem
end

CheckEx = function(user)
	for a,b in ipairs(Cfg.Exclude) do
		if b:lower() == user.sNick:lower() then
			return a
		end
	end
end

GetChat = function(lines)
	local x = lines
	if lines > #Cfg.Chat then
		x,lines = #Cfg.Chat,#Cfg.Chat
	end
	x = #Cfg.Chat - x
	local str = "\r\n\r\n <"..string.rep("?",70).."[ Last ( "..(lines).." ) chat messages ]??????????>\r\n"
	for i,v in ipairs(Cfg.Chat) do
		if i > x then
			str = str.."\r\n "..string.format("%"..string.len(#Cfg.Chat)..
			"s",i).."] "..v[2].." "..v[3].." "..v[4]
		end
	end
	return str.."\r\n\r\n <"..string.rep("?",70).."[ End of chat history ]"..
	string.rep("?",4 + string.len(lines)).."??????????>\r\n\r\n"
end

DelChat = function(lines)
	local count = lines
	if lines > #Cfg.Chat then
		lines = #Cfg.Chat
	end
	if lines == #Cfg.Chat then
		count = "all "..lines
	end
	for x = 1, lines do
		table.remove(Cfg.Chat,1)
	end
	if #Cfg.Chat == 0 then
		local t = {
		tonumber(os.date("%Y") + os.date("%j")),
		os.date("%m/%d/%y"),
		os.date("%I:%M")..string.sub(string.lower(os.date("%p")),1,1),
		"<"..Cfg.Bot.."> Chat history cleared "..
		os.date("on: %B %d %Y at: %I:%M")..string.sub(string.lower(os.date("%p")),1,1)
		}
		table.insert(Cfg.Chat,t)
	end
	SaveToFile(Cfg.File,Cfg.Chat,"Cfg.Chat")
	return count.." messages deleted."
end

function Serialize(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil")
	assert(sTableName, "sTableName equals nil")
	assert(type(tTable) == "table", "tTable must be a table!")
	assert(type(sTableName) == "string", "sTableName must be a string!")
	sTab = sTab or ""
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in ipairs(tTable) do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key)
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t")
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value)
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

function SaveToFile(File , Table , Tablename)
	local handle = io.open(File,"w")
	handle:write(Serialize(Table, Tablename))
	handle:flush()
	handle:close()
	CleanMem()
end

SendCmds = function(user)
	if Cfg.Profiles[user.iProfile] and Cfg.Profiles[user.iProfile][1] == 1 then
		for i,v in pairs(Cmds) do
			local m,s,pfx = Cfg.Menu,Cfg.SubMenu,Cfg.Pfx
			local c,n,pm,p = "$UserCommand 1","$<%[mynick]>","$$To: "..
			Cfg.Bot.." From: %[mynick] ","&#124;|"
			local d,a1,a2 = Cmds[i]()
			Core.SendToUser(user,c.." 1 "..m.."\\"..s.."\\"..d..n.." "..pfx..i..a1..p)
			Core.SendToUser(user,c.." 2 "..m.."\\"..s.."\\"..d..pm..n.." "..pfx..i..a2..p)
		end
		CleanMem()
		return true
	end
end

FormatSize = function(int)
	local i,u,x = tonumber(int) or 0,{"","K","M","G","T","P"},1
	while i > 1024 do i,x = i/1024,x+1 end return string.format("%.2f %sB.",i,u[x])
end

ProfName = function(user)
	local p,prof = user.iProfile
	if p and p ~= -1 then
		prof = ProfMan.GetProfile(p).sProfileName
	else
		prof = "Unregistered User"
	end
	return prof
end

ChkAd = function(data)
	for i,v in ipairs(Cfg.AaTrigs) do
		if data:lower():find(v:lower(),1,1) or data:lower():find("%d+%.%d+%.%d+%.%d+") then
			return i
		end
	end
end

Cmds = {
	togglehistory = function(user,data)
		if user then
			local status,result = "removed from","You will now "..
				"receive chat history at login."
			local Exclude = CheckEx(user)
			if not Exclude then
				table.insert(Cfg.Exclude,user.sNick)
				status,result = "added to","You will no "..
				"longer receive chat history at login."
			else
				table.remove(Cfg.Exclude,Exclude)
			end
			SaveToFile(Cfg.UserFile,Cfg.Exclude,"Cfg.Exclude")
			return "You have been "..status.." the exclusion table. "..result
		else
			return "Toggle Chat History","",""
		end
	end,
	history = function(user,data)
		local ChatLines = Cfg.MaxChat
		if user then
			local _,_,lines = data:find("%b<> %p%w+ (%d+)")
			if not lines then
				lines = ChatLines
			else
				lines = tonumber(lines)
			end
			return GetChat(lines)
		else
			return "Get Chat History",
			" %[line:# of Lines or none for "..ChatLines.."]",
			" %[line:# of Lines or none for "..ChatLines.."]"
		end
	end,
	dayhistory = function(user,data)
		local today = tonumber(os.date("%Y") + os.date("%j"))
		if user then
			local _,_,days = data:find("%b<> %p%w+ (%d+)")
			if days then
				local past = today - tonumber(days)
				OnError(past)
				local str = "\r\n\r\n <"..string.rep("?",70)..
				"[ Last ( "..days.." ) days of chat ]??????????>\r\n"
				for i,v in ipairs(Cfg.Chat)do
					if v[1] > past then
						str = str.."\r\n ["..i.."] "..v[2].." "..v[3].." "..v[4]
					end
				end
				str = str.."\r\n\r\n <"..string.rep("?",70).."[ End of chat history ]"..
				string.rep("?",string.len(days)).."??????????>\r\n\r\n"
				return str
			else
				return "You must specify how many days"
			end
		else
			return "Chat History By Days",
			" %[line:How Many Days of Chat Do You Want to See?]",
			" %[line:How Many Days of Chat Do You Want to See?]"
		end
	end,
	delete = function(user,data)
		local ChatLines = #Cfg.Chat
		if user then
			if user.iProfile == Cfg.AdminProf then
				local _,_,lines = data:find("%b<> %p%w+ (%d+)")
				if not lines then
					lines = ChatLines
				else
					lines = tonumber(lines)
				end
				return DelChat(lines)
			else
				return "Sorry "..user.sNick..", this command is for "..
				ProfMan.GetProfile(Cfg.AdminProf).sProfileName.."'s only."
			end
		else
			return "Delete Chat History",
			" %[line:# of Lines **None = All ("..ChatLines..") messages ]",
			" %[line:# of Lines **None = All ("..ChatLines..") messages ]"
		end
	end,
	delchat = function(user,data)
		local ChatLines = #Cfg.Chat
		if user then
			if user.iProfile == Cfg.AdminProf then
				local _,_,line = data:find("%b<> %p%w+ (%d+)")
				if line then
					line = tonumber(line)
					if Cfg.Chat[line] then
						local str = Cfg.Chat[line][4]
						table.remove(Cfg.Chat,line)
						SaveToFile(Cfg.File,Cfg.Chat,"Cfg.Chat")
						return "Chat entry "..line.." deleted has been deleted.\r\n"..
						"Deleted Entry: "..string.format("%q",str)
					else
						return line.." is not a valid entry."..GetChat(Cfg.History)
					end
				else
					return "You must specify an entry to delete."
				end
			else
				return "Sorry "..user.sNick..", this command is for "..
				ProfMan.GetProfile(Cfg.AdminProf).sProfileName.."'s only."
			end
		else
			return "Delete Single Chat Entry",
			" %[line:Delete Which Entry?]",
			" %[line:Delete Which Entry?]"
		end
	end,
	chathelp = function(user,data,to)
		if user then
			local reply = "Chat History Help\n\n\tCommand\t\tDescription\r\n"..
			"\t"..string.rep("?",40).."\r\n"
			for i,v in pairs(Cmds) do
				local desc,args = Cmds[i]()
				reply = reply.."\t"..Cfg.Pfx..string.format("%-15s",i).."\t"..desc.."\r\n"
			end
			return reply.."\n\t"..string.rep("?",40).."\r\n\r\n"
		else
			return "Chat History Help","",""
		end
	end,
}


Can anybody help, please.  :-*

Madman

That would be a downgrade. That script is written for px 0.4.0.0.
Witch i suggest you upgrade to instead of useing 0.3.6.0...
And most likely the reason for you not to upgrade is that you want RoboCop...

Well you can't! RoboCop is dead, dead, dead and dead!
However there is atm 2 All In One scripts for 0.4.0.0
They can be found Here

There is also my script Flexo, that covers the basic security needs and some other stuff...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

]-[?LL?L?L??nG?L

#2
heres a link i found chuck it maybe what your looking for
http://lua.uknnet.com/thread.php?threadid=607&hilight=chat+history
the script at the bottom of the page done by Mutor and as Madman said it is a downgrade from the one that you posted  ;D

LeChuck

Great *thumb_up*

Version 1.03b works.

Thanks for help & Mutor for Script !

SMF spam blocked by CleanTalk