Please, help for this script ...
 

Please, help for this script ...

Started by BobyJ, 30 September, 2013, 21:09:08

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

BobyJ

Hello. I need help with this AntiSpam script. Gets me this error message in PtokaX 0.5.0.0: 
[21:49:07 ?.] Syntax E:\0.5.0.0-Lua5.2.1-x64\scripts\AntiSpam_3.lua:10: invalid escape sequence near '\c'

In PtokaX 0.4.1.2 works fine. And one more question. How can all Operators gets PM from this script?
Thanks in advance for your help and attention!
Regards


MainBot="AntiSpam"
BotReg=0 

RekProfNotAllow={  -- profiellijst
	[-1]=1, -- unregistered users
}

Reklama={ -- spam
"d c h u b://","dchub://","d*c*h*u*b://","http://","www.","ftp://","d`c`h`u`b://","d#c#h#u#b://","d$c$h$u$b://","d%c%h%u%b://","f^c^h^u^b://","d&c&h&u&b://","d(c(h(u(b://","d)c)h)u)b://","d=c=h=u=b://","d+c+h+u+b://","d\c\h\u\b://","d?c?h?u?b://","d.c.h.u.b://","d>c>h>u>b://","d,c,h,u,b://","d<c<h<u<b://","d~c~h~u~b://","d?c?h?u?b://","d;c;h;u;b://","d:c:h:u:b://","d/c/h/u/b://","d|c|h|u|b://","d]c]h]u]b://","d[c[h[u[b://","d{c{h{u{b://","d}c}h}u}b://"," dchub://","N G O N N K N G","A     D     S     L","[-dc.hub-]","d=c=h=u=b","s  e  r  v  e  m  p  3  .  c  o  m","[dc-hub]",
}
RekExcept={ -- toegestaan
          "dchublist",
}

function OnStartup()
	if BotReg==1 then
		Core.RegBot(Bot,"","",true)
	end
end

function UserConnected(user) 
	Core.GetUserAllData(user)
	local msg = user.sMyInfoString 
		if (RekProfNotAllow[user.iProfile]==1) then
--			msg = StringLower(msg)
			if RekCheck(msg) then
				if RekExceptCheck(msg) then
				return nil
				end
				Core.SendToOps("<"..MainBot.."> Lets all laugh about "..user.sNick.." who tried to spam inhere but failed to get in :-)")
				Core.SendPmToNick(Report, MainBot, user.sNick.." IP: "..user.sIP.." was kicked for advertising: "..msg)

					BanMan.TempBan(user, 0, "Hubspammer", MainBot, true)
				return true
			end
		end
--	end
end
	function ChatArrival(user,data)
	Core.GetUserAllData(user)
	local s,e,msg = string.find(data,"%b<>%s*(.*)%|")
	if (RekProfNotAllow[user.iProfile]==1) then
	    msg = StringLower(msg)
		if RekCheck(msg) then
			if RekExceptCheck(msg) then
				return nil
			end
			Core.SendToAll("<"..MainBot.."> Lets all laugh about "..user.sNick.." who tried to spam inhere but failed :-)")
			Core.SendPmToNick(Report, MainBot, user.sNick.." IP: "..user.sIP.." was kicked for advertising: "..msg)

					BanMan.TempBan(user, 0, "Hubspammer", MainBot, true)
			return true
		end
	end
end


function ToArrival(user,data)
	Core.GetUserAllData(user)
	s,e,to,from,msg=string.find(data,"%$To:%s(%S+)%sFrom:%s%S+%s$<(%S+)%>%s(.*)$")
	if (RekProfNotAllow[user.iProfile]==1) then
	    msg = StringLower(msg)
		if RekCheck(msg) then
			if RekExceptCheck(msg) then
				return nil
			end
			Core.SendToAll("<"..MainBot.."> Lets all laugh about "..user.sNick.." who tried to spam inhere but failed :-)")
			Core.SendPmToNick(Report, MainBot, user.sNick.." IP: "..user.sIP.." was kicked for advertising: "..msg)

					BanMan.TempBan(user, 0, "Hubspammer", MainBot, true)
			return true
		end
	end
end


function RekCheck(msg)
	for i = 1,#Reklama do
		if string.find( msg , Reklama[i] , 1 , true ) or msg:find("%d+%.%d+%.%d+%.%d+") then
			return 1
		end
	end
end

function RekExceptCheck(msg)
	for i = 1,#RekExcept do
		if string.find( msg , RekExcept[i] , 1 , true ) then
			return 1
		end
	end
end

function StringLower(msg)
    local res = ""
    local Byte, Len = nil, string.len(msg)
    msg = string.lower(msg)
    for i = 1, Len do
        Byte = string.byte(msg, i)
        if (Byte >= 192) and (Byte < 224) then
            Byte = Byte + 32
        end
        if (Byte == 168) or (Byte == 184) then Byte = 229 end
        res = res..string.char(Byte)
    end
    return res
end

PPK

Script error is caused by Lua 5.2. Use PtokaX 0.5.0.0 with Lua 5.1 ;)
"Most of you are familiar with the virtues of a programmer. There are three, of course: laziness, impatience, and hubris." - Larry Wall

BobyJ

#2
Thanks PPK! I will try.  :yes:

BobyJ

Hi again.
Can anyone help me with the settings of this one script? I want just certain (two or more) nicknames of Ops to receive the report, or at least all operators. Where i need to change the script and how?
Thanks in advance for your help!  :)


--[[

	CleanReg 1.1 LUA 5.1x [Strict] [API 2]
	By Mutor	01/18/08
	Requested by Gnuff™

	User registry cleaner for the new Px API
	*Deletes user accounts after 'x' days of inactivity.

	-Interval setting, per profile
	-Exclusion by nick
	-Context menu [right click]
	-Option for pm reply only
	-Report to OpNick or Ops
	-Script data saved to files for hub/script restart
	-Non-excluded users are reminded of account purge time at disconnect.

	+Changes from 1.0	10/10/08
		+Added commands / functions to get remaining user reg time / all users reg times requested by quicky2g

]]

-- -- "Botname" ["" = hub bot]
local Bot = ""
-- Report nick ["" = send to ops]
local ReportNick = ""
-- If true replies in PM only
local PmOnly = true
-- User data
local File = "RegUser.dat"
-- Excluded nicks
local ExcFile = "ExcUser.dat"
-- Profile data
local ProfFile = "Profiles.dat"
-- Command prefix ["" = first char set in PtokaX]
local Prefix = ""
-- Interval [in minutes] to check users
local Mins = 30
-- Inactivity interval [in days] before user is purged from registry [0 = disable]
-- [#] = days,
local Profiles  = {
	[0] = 0,	--Master
	[1] = 0,	--Operator
	[2] = 0,	--Vip
	[3] = 90,	--Registered User
	}

-- Nick,password and profile for testing script function [Set TestNick = "" to disable]
local TestNick,TestPass,TestProf = "","",3 --"TestNick","Password",3
--//--

local Cmds,Tmr = {},0
OnStartup = function()
	local chg
	Mins = math.max(Mins,1)
	Tmr = TmrMan.AddTimer(Mins*60000)
	if Bot == "" then Bot = SetMan.GetString(21) end
	if Prefix == "" then Prefix = SetMan.GetString(29):sub(1,1) end
	local Path = Core.GetPtokaXPath().."scripts/"
	if not ProfFile:find("^"..Path,1,true) then ProfFile = Path..ProfFile end
	if loadfile(ProfFile) then dofile(ProfFile) else SaveFile(ProfFile,Profiles,"Profiles") end
	if not ExcFile:find("^"..Path,1,true) then ExcFile = Path..ExcFile end
	if loadfile(ExcFile) then dofile(ExcFile) else Exclude = {"NewUser"} SaveFile(ExcFile,Exclude,"Exclude") end
	if not File:find("^"..Path,1,true) then File = Path..File end
	if loadfile(File) then
		dofile(File)
	else
		RegUsers = {}
		local tab,t = RegMan.GetRegs(),os.time()
		if next(tab) then
			for _,user in ipairs(tab) do
				local p,i,n = user.iProfile,Profiles[user.iProfile],user.sNick
				if not Exclude[n] then
					if i and i > 0 then
						RegUsers[n] = {t,p}
						if not chg then chg = true end
					end
				end
			end
		end
	end
	for k,v in pairs(RegUsers) do
		if not RegMan.GetReg(k) then RegUsers[k] = nil if not chg then chg = true end end
	end
	if TestNick:len() > 0 then
		local usr,pwd,prf,tm = TestNick,TestPass,TestProf,(os.time() - ((Profiles[TestProf]+1)*86400))
		if not RegMan.GetReg(TestNick) then
			RegMan.AddReg(usr,pwd,prf) RegUsers[usr] = {tm,prf}
			if not chg then chg = true end
		end
	end
	if chg then SaveFile(File,RegUsers,"RegUsers") end
	OnTimer(Tmr)
end

OnExit = function()
	if TestNick:len() > 0 then
		if RegMan.GetReg(TestNick) then RegMan.DelReg(TestNick) end
		if RegUsers[TestNick] then RegUsers[TestNick] = nil SaveFile(File,RegUsers,"RegUsers") end
	end
end

ChatArrival = function(user,data)
	local _,_,cmd = data:find("^%b<> ["..SetMan.GetString(29).."](%a+)")
	if cmd then
		cmd = cmd:lower()
		if Cmds[cmd] and Cmds[cmd][2][user.iProfile] then
			return Core.SendToUser(user,"<"..Bot.."> "..Cmds[cmd][1](user,data,cmd).."|"),true
		end
	end
end

OnTimer = function(Id)
	if Id == Tmr then
		local cur,cnt,ru,chg = os.time(),0,#RegMan.GetRegs()
		for a,b in ipairs(RegMan.GetRegs()) do
			if Profiles[b.iProfile] then
				if not RegUsers[b.sNick] then
					RegUsers[b.sNick] = {os.time(),b.iProfile}
					if not chg then chg = true end
				end
			end
		end
		for key,tab in pairs(RegUsers) do
			local user = Core.GetUser(key)
			if user then
				if Profiles[user.iProfile] then
					if not RegMan.GetReg(user.sNick) then
						RegUsers[user.sNick] = nil
					else
						RegUsers[user.sNick] = {os.time(),user.iProfile}
					end
				end
			else
				local td = os.difftime(os.time(),tab[1])/86400
				if Profiles[tab[2]] > 0 and td > Profiles[tab[2]] then
					cnt = cnt + 1
					Report(key.." has not visited the hub in over "..Profiles[tab[2]]..
					" days. ("..string.format("%.0f",(td))..")  "..key..
					" has been removed from the user registry.")
					RegMan.DelReg(key)
					RegUsers[key] = nil
					if not chg then chg = true end
				end
			end
		end
		if chg then
			SaveFile(File,RegUsers,"RegUsers")
			Report(tostring(cnt).." of "..tostring(ru).." were cleaned in <"..
			string.format("%.2f seconds.",os.difftime(os.time(),cur)+.01))
		end
	end
end

UserConnected = function(user,data)
	if Profiles[user.iProfile] and Profiles[user.iProfile] > 0 and not Exclude[user.sNick] then
		if RegUsers[user.sNick] then
			local td = os.difftime(os.time(),RegUsers[user.sNick][1])/86400
			if td >= 1 then
				Core.SendToUser(user,"<"..Bot.."> Hey "..user.sNick..
				", we've missed you for the last "..td.." days.|")
			end
		end
		RegUsers[user.sNick] = {os.time(),user.iProfile}
		SaveFile(File,RegUsers,"RegUsers")
	end
	local s,h  = "",SetMan.GetString(0)
	for i,v in pairs(Cmds) do
		if v[2][user.iProfile] then
			local d,a = v[3][1],v[3][2]
			s = s.."$UserCommand 1 3 "..h.."\\Registry Cleaner\\"..
			d.."$<%[mynick]> "..Prefix..i..a.."&#124;|"
		end
	end
	if s:len() > 0 then Core.SendToUser(user,s) end
end
OpConnected,RegConnected = UserConnected,UserConnected

UserDisconnected = function(user,data)
	if Profiles[user.iProfile] and Profiles[user.iProfile] > 0 and not Exclude[user.sNick] then
		local t = os.date("%c",os.time() + (86400 * Profiles[user.iProfile]))
		Core.SendToUser(user,"<"..Bot.."> Goodbye "..user.sNick..". Your registered account "..
		"will only be held for "..Profiles[user.iProfile].." days.|")
		Core.SendToUser(user,"<"..Bot.."> After which it will be purged, be sure to return before "..t.."|")
		RegUsers[user.sNick] = {os.time(),user.iProfile}
		SaveFile(File,RegUsers,"RegUsers")
	end
end
RegDisconnected,OpDisconnected = UserDisconnected,UserDisconnected

Report = function(msg)
	if ReportNick:len() > 0 then
		local op = Core.GetUser(ReportNick)
		if msg and op then
			if PmOnly then
				Core.SendPmToUser(op,Bot,msg.."|")
			else
				Core.SendToUser(op,"<"..Bot.."> "..msg.."|")
			end
		end
	end
end

Cmds = {
	excuser = {function(user,data,cmd)
		if user then
			local _,_,nick = data:find("^%b<> %S+ (%S+)|")
			if nick then
				if RegMan.GetReg(nick) then
					for i,v in ipairs(Exclude) do
						if nick:lower() == v:lower() then
							table.remove(Exclude,i)
							SaveFile(ExcFile,Exclude,"Exclude")
							return nick.." is no longer excluded from the registry cleaner."
						end
					end
					table.insert(Exclude,nick)
					SaveFile(ExcFile,Exclude,"Exclude")
					return nick.." is excluded from the registry cleaner."
				else
					return "Error! Usage: "..Prefix..cmd.." <registered nick>"
				end
			else
				return "Error! Usage: "..Prefix..cmd.." <nick>"
			end
		end
	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false},
	{"Exclude / Include User"," %[line:Nick]"}
	},
	usertime = {function(user,data,cmd)
		if user then
			local _,_,nick = data:find("^%b<> %S+ (%S+)|")
			if nick then
				if RegUsers[nick] then
					local remaining = Convert(RegUsers[nick][1] + (86400 * Profiles[RegUsers[nick][2]]))
					return "Remaining time for "..nick..": "..remaining
				else
					return "Error! "..nick.." was not found."
				end
			else
				return "Error! Usage: "..Prefix..cmd.." <nick>"
			end
		end
	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false},
	{"Display User's Remaining Reg Time"," %[line:Nick]"}
	},
	regtimes = {function(user,data,cmd)
		if user then
			if next(RegUsers) then
				local s = ""
				for nick,tab in pairs(RegUsers) do
					local remaining = Convert(tab[1] + (86400 * Profiles[tab[2]]))
					s = s.."\t"..string.format("%-30.50s",nick).."\t\t"..remaining.."\r\n"
				end
				if s ~= "" then
					return "\r\n\r\n\tRemaining registration times:\r\n\r\n"..s
				end
			else
				return "There are no users to list."
			end
		end
	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false},
	{"Display All Users Remaining Reg Time",""}
	},
	setprof = {function(user,data,cmd)
		local _,_,pnumb,days = data:find("^%b<> ["..SetMan.GetString(29).."]"..cmd.." (%d+) (%d+)|")
		if pnumb and days then
			if not Profiles[tonumber(pnumb)] then
				return "Error! "..pnumb.." is not a valid profile number."
			else
				local x,p = Profiles[tonumber(pnumb)],ProfMan.GetProfile(tonumber(pnumb)).sProfileName
				Profiles[tonumber(pnumb)] = tonumber(days)
				SaveFile(ProfFile,Profiles,"Profiles")
				return p.."'s clean time successfully changed from "..x.." to "..days.." days."
			end
		else
			return "Error! Usage: "..Prefix..cmd.." <profile number> <days>"
		end
	end,{[-1] = false,[0] = true,[1] = true,[2] = false,[3] = false},
	{"Set Profile Clean Time"," %[line:Profile Number] %[line:Interval In Days]"}
	},
}

Convert = function(time)
	if time then
		local s,x,n = "",0,os.time()
		local tab = {{31556926,"year"},{2592000,"month"},{604800,"week"},
		{86400,"day"},{3600,"hour"},{60,"minute"},{1,"second"}}
		if time > 0 then
			if time < 2145876659 then
				if n > time then
					time = n - time
				elseif n < time then
					time = time - n
				end
				for i,v in ipairs(tab) do
					if time > v[1] then
						x = math.floor(time/v[1])
						if x > 1 then v[2] = v[2].."s" end
						if x > 0 then
							s = s..x.." "..v[2]..", "
							time = time-x*v[1]
						end
					end
				end
				collectgarbage("collect")
				return s:sub(1,-3)
			else
				return "Invalid date or time supplied. [must be pre 12/31/2037]"
			end
		else
			return "Invalid date or time supplied. [must be post 01/01/1970]"
		end
	else
		return "Invalid date or time supplied."
	end
end

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
			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

SaveFile = function(file,table, tablename )
	local hFile = io.open (file , "wb")
	Serialize(table, tablename, hFile)
	hFile:close()
	collectgarbage("collect")
end

sphinx_spb

Report = function(msg)
	if msg then
		if PmOnly then
			for i=0,1 do
				Core.SendPmToProfile(i,Bot,msg.."|")
			end
		else
			for i=0,1 do
				Core.SendToProfile(i,"<"..Bot.."> "..msg.."|")
			end
		end
	end
end

BobyJ

#5
Quote from: sphinx_spb on 24 March, 2014, 01:55:26
Report = function(msg)
	if msg then
		if PmOnly then
			for i=0,1 do
				Core.SendPmToProfile(i,Bot,msg.."|")
			end
		else
			for i=0,1 do
				Core.SendToProfile(i,"<"..Bot.."> "..msg.."|")
			end
		end
	end
end



Big Thanks! Will make the changes today. After 90 days  ;) will tell you what is the result.  :)


P.S:
Confirm. Works without problems. Thanks a lot sphinx_spb  :yes:

SMF spam blocked by CleanTalk