I think that there is a bug with this script. Could somebody please help me ?
 

I think that there is a bug with this script. Could somebody please help me ?

Started by Plagued Elohim, 21 May, 2007, 20:13:05

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Plagued Elohim

Hello. I have a script over here and I think that it has a bug. When it's activated I can't talk if I have OP or Master... but if I delete my account, I can speak ... I've tryied to seek the script that was doing this and ... well, here it is:
-- auto/manual registered user cleaner if user hasn't been in the hub for x weeks
-- made by plop
-- julian day function made by the guru tezlo
-- code stripped from artificial insanety bot
-- updated to LUA 5 by Pothead
-- updated to PtokaX 16.09 by [_XStaTiC_]  Removed the seen part sorry :) i don't use it :)
-- touched by Herodes (optimisation tsunami, and added !seen again)
-- thx to god for giving TimeTraveler the ability to discover those bugs.. notice the plural? :)
-- Pothead changed to allow different profiles to have a different cleaning time and updated to lua 5.1
-- Mod by Mutor, check for & create logs folder if non-existent, added process time for nightshadow
-- Corrected a few ancient spelling errors.

-- !noclean <user_name> add/remove  - adds/removes users from/to the list which aren't cleaned
-- !showusers - shows all registered users
-- !seen <user_name> - shows the last time the user left the hub
-- !shownoclean - shows all names wich are on the noclean list
-- !cleanusers - manualy start the usercleaner

--------------------------------------------------------------------- the needed tables // pls dont edit anything here..
cl = {}
cl.sets = {}
cl.levels = {}
cl.user = {}
cl.no = {}
cl.funcs = {}
--------------------------------------------------------------------- config
cl.sets.bot = frmHub:GetHubBotName() -- the bot Name...
cl.sets.auto = 0 -- 0:disables / 1:enables , automatic mode ( if disabled use !cleanusers to clean )
cl.files = { no = "logs/NoClean.lst", user = "logs/CleanUser.lst" } -- these are the files..

cl.levels = { [3]=1, [2]=2} -- levels it needs 2 clean 3=reg 2=vip , then = the amount of weeks to clean them in

--------------------------------------------------------------------- julian day function 2 calcute the time users spend in the hub
function cl.funcs.jdate(d, m, y)
	local a, b, c = 0, 0, 0
	if m <= 2 then y = y - 1; m = m + 12; end
	if (y*10000 + m*100 + d) >= 15821015 then
		a = math.floor(y/100); b = 2 - a + math.floor(a/4)
	end
	if y <= 0 then c = 0.75 end
	return math.floor(365.25*y - c) + math.floor(30.6001*(m+1) + d + 1720994 + b)
end
--------------------------------------------------------------------- Load a file
function cl.funcs.load(file)
	local f = io.open(file, "r")
	if f then
		for line in f:lines() do
			local s,e,name,date = string.find(line, "(.+)$(.+)")
			if name then cl.user[name] = date; end
		end
		f:close()
	end
end
--------------------------------------------------------------------- Save to file
function cl.funcs.save(file, tbl)
	local f = io.open(file, "w+")
	for a,b in pairs(tbl) do
		f:write(a.."$"..b.."\n")
	end
	f:close()
end
--------------------------------------------------------------------- call the garbage man
function cl.funcs.cls()
	collectgarbage()
	io.flush()
end
--------------------------------------------------------------------- Display some table
function cl.funcs.showusers( user, data )
	local tbl, txt;
	if (type(data) == "string") then
		local s,e,Profile = string.find(data, "%b<>%s+%S+%s+(%S+)")
		if not Profile then user:SendData(cl.sets.bot , "RTFM ;). It's !showusers <Profile_name>"); return 1; end
		tbl = GetUsersByProfile(Profile);
		txt = "registered users with Profile ("..Profile..")"
	else
		local function to_array(t) local r={}; for i , v in pairs(t) do table.insert(r, i); end; return r; end
		tbl = to_array(data)
		txt = "users who aren't cleaned"
	end
	local info = "\n Here are the "..txt.."\n"
	info = info.."=====================================\n"
	for i,nick in pairs(tbl) do info = info.."  "..nick.."\n"; end
	info = info.."=====================================\n"
	user:SendData( "$To: "..user.sName.." From: "..user.sName.." $<"..cl.sets.bot.."> "..info)
	cl.funcs.cls()
end
--------------------------------------------------------------------- cleanup old users
function cl.funcs.clean()
	local start = os.clock()
	local juliannow = cl.funcs.jdate(tonumber(os.date("%d")), tonumber(os.date("%m")), tonumber(os.date("%Y")))
	local chkd, clnd, totalchecked = 0,0,0
	local msg = "\r\nThe Cleaner has just ran.\r\n"
	for prof, v in pairs(cl.levels) do
		msg = msg.."\r\nToti cei care sunt inregistrati, si au profilul "..GetProfileName(prof)..", si nu se vor loga pe hub in cel putin "..cl.levels[prof].." saptamani li se vor sterge conturile automat. Va multumim pentru intelegere."
		local oldest = cl.levels[prof] * 7
		for a, b in pairs(GetUsersByProfile(GetProfileName(prof))) do
			chkd = chkd + 1
			if cl.user[b] then
				if not cl.no[b] then
					local s, e, month, day, year = string.find(cl.user[b], "(%d+)%/(%d+)%/(%d+)");
					year = "20"..year
					local julian = cl.funcs.jdate( tonumber(day), tonumber(month), tonumber(year) )
					if ((juliannow - julian) > oldest) then
						cl.user[b] = nil;
						DelRegUser(b);
						clnd = clnd + 1;
					end
				end
			else
				cl.user[b] = os.date("%x")
			end
		end
		msg = msg.." "..chkd.." users were processed, "..clnd.." of them were deleted."
		totalchecked = totalchecked + chkd
		chkd = 0
		clnd = 0
	end
	msg = msg.. "\r\n\r\nThis cleanup took: "..string.format("%8.6f seconds",os.difftime(os.clock(),start))..
	"\r\n\r\n(Daca aveti cont aici pe hub, si nu va puteti loga pentru o anumita perioada de timp, va rugam contactati un operator)"
	SendToAll(cl.sets.bot , msg)
	cl.funcs.save(cl.files.user, cl.user);
end
--------------------------------------------------------------------- don't clean this users adding/removing
function cl.funcs.addnocl( user, data )
	local s,e,who, addrem = string.find(data, "%b<>%s+%S+%s+(%S+)%s+(%S+)%s*")
	if who and addrem then
		if frmHub:isNickRegged(who) then
			if (addrem == "add") then
				if cl.no[who] then
					user:SendData(cl.sets.bot , who.." is already on the imune list.")
				else
					cl.no[who] = 1
					user:SendData(cl.sets.bot , who.." is added to the imune list and won't be cleaned.")
					cl.funcs.save(cl.files.no, cl.no)
				end
			elseif addrem == "remove" then
				if cl.no[who] then
					cl.no[who] = nil
					user:SendData(cl.sets.bot , who.." is removed from the imune list.")
					cl.funcs.save(cl.files.no, cl.no)
				else
					user:SendData(cl.sets.bot , who.." was not on the imune list.")
				end
			else
				user:SendData(cl.sets.bot , "RTFM ;). it's !noclean <user_name> <add/remove>")
			end
		else
			user:SendData(cl.sets.bot , who.." isn't a registered user.")
		end
	else
		user:SendData(cl.sets.bot , "Syntax Error, Use: !noclean <nick> <add or remove>")
	end
end
--------------------------------------------------------------------- Respond to a !seen
function cl.funcs.seen( user, data )
	local s,e,who = string.find( data, "%b<>%s+%S+%s+(%S+)" )
	if who then
		if who ~= user.sName then
			if not GetItemByName(who) then
				if cl.user[who] then
					user:SendData( cl.sets.bot, who.." was last seen on the "..cl.user[who])
				else
					user:SendData( cl.sets.bot, "How should I know when "..who.." was last seen ?")
				end
			else
				user:SendData( cl.sets.bot, who.." is online ... open those eyes of yours..")
			end
		else
			user:SendData( cl.sets.bot, "aren't you that guy ?")
		end
	else
		user:SendData( cl.sets.bot, "Syntax Error, Use: !seen <nick>")
	end
end
--------------------------------------------------------------------- do i need 2 explain this ?????
function ChatArrival(user, data)
	if (cl.sets.auto == 1) then
		if cl.day ~= os.date("%x") then -- user cleaning trigger, works as a timer without a timer
			cl.day = os.date("%x")
			cl.funcs.clean()
		end
	end
	if (user.bOperator) then
		data = string.sub(data,1,-2)
		local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
		if cmd then
			if (cmd == "!noclean") then cl.funcs.addnocl(user, data)
			elseif (cmd == "!seen") then cl.funcs.seen(user, data)
			elseif (cmd == "!showusers") then cl.funcs.showusers( user, data )
			elseif (cmd == "!shownoclean") then cl.funcs.showusers( user, cl.no )
			elseif (cmd =="!cleanusers") then cl.funcs.clean()
			end
		return 1
		end
	end
end
--------------------------------------------------------------------- stuff done when a user/vip leaves or come
function NewUserConnected(user)
	if cl.user[user.sName] then
		cl.user[user.sName] = nil;
		cl.funcs.save(cl.files.user, cl.user);
	end
end

OpConnected = NewUserConnected

function UserDisconnected(user)
	if (cl.levels[user.iProfile] ~= nil) then
		cl.user[user.sName] = os.date("%x");
		cl.funcs.save(cl.files.user, cl.user);
	end
end

OpDisconnected = UserDisconnected
--------------------------------------------------------------------- stuff done on bot startup
function Main()
	local f,e = io.open(cl.files.user)
	if f == nil then
		if os.execute("dir logs") ~= 0 then
			os.execute("md logs")
			cl.funcs.clean()
			Main()
		end
	else
	f:close()
	cl.funcs.load(cl.files.no)
	cl.funcs.load(cl.files.user)
	cl.day = os.date("%x")
	end
end
Could you please help me out ?

CrazyGuy

Your problem is with the return 1 in this function

function ChatArrival(user, data)
	if (cl.sets.auto == 1) then
		if cl.day ~= os.date("%x") then -- user cleaning trigger, works as a timer without a timer
			cl.day = os.date("%x")
			cl.funcs.clean()
		end
	end
	if (user.bOperator) then
		data = string.sub(data,1,-2)
		local s,e,cmd = string.find(data,"%b<>%s+(%S+)")
		if cmd then
			if (cmd == "!noclean") then cl.funcs.addnocl(user, data)
			elseif (cmd == "!seen") then cl.funcs.seen(user, data)
			elseif (cmd == "!showusers") then cl.funcs.showusers( user, data )
			elseif (cmd == "!shownoclean") then cl.funcs.showusers( user, cl.no )
			elseif (cmd =="!cleanusers") then cl.funcs.clean()
			end
		return 1
		end
	end
end


See if this works better

function ChatArrival(user, data)
	if (cl.sets.auto == 1) then
		if cl.day ~= os.date("%x") then -- user cleaning trigger, works as a timer without a timer
			cl.day = os.date("%x")
			cl.funcs.clean()
		end
	end
	if (user.bOperator) then
		data = string.sub(data,1,-2)
		local s,e,cmd = string.find(data,"%b<>%s%p(%S+)")
		if cmd then
			local tCmd = {
				["noclean"] = function(user,data)
					cl.funcs.addnocl(user, data)
				end,
				["seen"] = function(user,data)
					cl.funcs.seen(user, data)
				end,
				["showusers"] = function(user,data)
					cl.funcs.showusers(user, data)
				end,
				["shownoclean"] = function(user,data)
					cl.funcs.showusers( user, cl.no )
				end,
				["cleanusers"] = function(user,data)
					cl.funcs.clean()
				end,
			}
			if tCmd[cmd] then
				tCmd[cmd](user,data)
				return 1
			end
		end
	end
end


This script can definately use some more optimizations, but this should fix your problem.

The exact error was: The script's string.find would always return a pattern which caused the function to always return 1 when user.bOperator is true. When ChatArrival returns 1, the hub doesn't process the data, so the chat isn't relayed.
Now it only returns 1 if the users chat message is the exact command (but I haven't tested it)


BTW, I'm gonna move this post to the correct board ( Help with Scripts)  ::)


SMF spam blocked by CleanTalk