[BOT]LoginBlock with time settings
 

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

[BOT]LoginBlock with time settings

Started by TTB, 20 July, 2005, 00:30:36

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

TTB

Hi...

I'm working on a huge script, so there were not that much posts from me... I stripped a nice feature from it, it could be useful for some admins.

The script blocks non-regs permanent, or from time - time. There is already such a script, but I like the one I made....

IMPORTANT! You need to make a file called "logintimer.dat" and you have to put that in the scripts folder! Copy paste the table below in the file:
bSettings = {
	["login"] = {
		["message"] = "None",
		["end"] = 0,
		["enable"] = 0,
		["start"] = 0,
	},
}

Here is the code...:
-- [BOT]LoginBlock with time settings
-- by TTB 20/07/05
-- Stripped from [BOT]Vliegenmepper (still in progress)
----------------------------------------------------------------------
-- Usage:
-- #nonregblock   				-  Block non-regs. Settings can be done with: (prefix)nonregset 
-- #nonregset    	- Set the non-reg block in time. Only 1 (or 2 when needed) digit(s) possible by time (hours)
-- NOTE: Status and other info will be given when you don't config... Type: #nonregblock or #nonregset without any extra text... Find out yourself
----------------------------------------------------------------------
-- Info:
-- I didn't post that much on the forum the last few weeks, so that's why I give you all this stripped version from a bot that maybe will released some day
-- It might be useful for some admins....
----------------------------------------------------------------------
-- IMPORTANT!!!!!!!
-- YOU HAVE TO MAKE A FILE CALLED:  logintimer.dat  IN YOUR SCRIPTS DIRECTORY!!!!
-- It won't work without...
-- 
--Put this in that file (without the double -  ) >>
--
--bSettings = {
--	["login"] = {
--		["message"] = "None",
--		["end"] = 0,
--		["enable"] = 0,
--		["start"] = 0,
--	},
--}
----------------------------------------------------------------------


-- ## SETTINGS ##--

-->> Name of the bot
bot = "[BOT]LoginBlock"
--> Reg the bot in the userlist? 1 = yes 0 = no
regbot = 1
-->> Your commands
prefix = "#"
cmd1 = "nonregblock"
cmd2 = "nonregset"
-->> The profiles who can use this commands
Profiles = {
[-1] = 0,  -- Users
[0] = 1,   -- Masters
[1] = 1,   -- OPs
[2] = 0,   -- VIPs
[3] = 0,   -- REGs
[4] = 1,   -- MODs
[5] = 1,   -- Founders
}

-- ## End of Settings ##--

file = "logintimer.dat"

function loadlua(file,msg)
	local f = assert(loadfile(file), msg)
	return f()
end

loadlua(file,file.."  for  "..bot.." not found")

function Main()
	if regbot == 1 then 
		frmHub:RegBot(bot)
	end
end

function ChatArrival(curUser, data)
	data = string.sub(data,1,string.len(data)-1)
	s,e,cmd = string.find(data,"%b<>%s+(%S+)")
	if (string.lower(cmd) == (prefix..cmd1)) then
		if Profiles[curUser.iProfile] == 1 then
			BlockNonRegStatus(curUser,data)
			return 1
		end
	elseif (string.lower(cmd) == (prefix..cmd2)) then
		if Profiles[curUser.iProfile] == 1 then
			BlockNonReg(curUser,data)
			return 1
		end
	end
end

function BlockNonReg(curUser,data)
	local mijntabel = "bSettings"
	local s,e,cmd,start,eind,reden = string.find(data,"%b<>%s+(%S+)%s+(%d+)%s+(%d+)%s+(.+)")
	if start==nil or eind==nil or reden==nil then
		if bSettings["login"]["enable"] == 1 then
			curUser:SendData(bot,"The current setting is: ON")
		else
			curUser:SendData(bot,"The current setting is: OFF")
		end
		curUser:SendData(bot,"*** Syntax error! Please use: "..prefix..cmd2.."   \r\n\r\n"..
		"Example: "..prefix..cmd2.." 22 6 Not welcome     <--- blocks from 22:00 till 6:00 with the reason 'Not welcome'\r\n"..
		"To block nonreg's for 24 hours, use: "..prefix..cmd2.." 0 0 \r\n"..
		"NOTE: It can only be done in hours!!")
	else
		local start=tonumber(start);local eind=tonumber(eind);
		if start > 23 or start < 0 or eind > 23 or eind < 0 then
			curUser:SendData(bot,"*** Error! The numbers: 0 - 23 are possible.")
		else
			curUser:SendData(bot,"Old settings: Start = "..bSettings["login"]["start"].." end = "..bSettings["login"]["end"].." Reason = "..bSettings["login"]["message"])
			bSettings["login"]["start"] = start
			bSettings["login"]["end"] = eind
			bSettings["login"]["message"] = reden
			curUser:SendData(bot,"New settings: Start = "..bSettings["login"]["start"].." end = "..bSettings["login"]["end"].." Reason = "..bSettings["login"]["message"])
			SendPmToOps(bot,"The non-reg blocker settings has been changed by: "..curUser.sName.."  "..
			"New settings: Start = "..bSettings["login"]["start"].." end = "..bSettings["login"]["end"].." Reason = "..bSettings["login"]["message"])
			WriteFile(bSettings,mijntabel,file)
		end
	end	
end

function BlockNonRegStatus(curUser,data)
	local mijntabel = "bSettings"
	local s,e,cmd,status = string.find(data,"%b<>%s+(%S+)%s+(%S+)")
	if status == nil then
		if bSettings["login"]["enable"] == 1 then
			curUser:SendData(bot,"*** Syntax error! Please use: "..prefix..cmd1.." ")
			curUser:SendData(bot,"Settings: Start = "..bSettings["login"]["start"].." end = "..bSettings["login"]["end"].." Reason = "..bSettings["login"]["message"])
			curUser:SendData(bot,"The current setting is: ON")
		else
			curUser:SendData(bot,"*** Syntax error! Please use: "..prefix..cmd1.."     The current setting is: OFF")
		end
	else
		if status == "on" then
			if bSettings["login"]["enable"] == 1 then
				curUser:SendData(bot,"The blocker is already on!")
			else
				bSettings["login"]["enable"] = 1
				curUser:SendData(bot,"The blocker is enabled!")
				SendPmToOps(bot,"The non-reg blocker has been enabled by: "..curUser.sName.."  "..
				"Current settings: Start = "..bSettings["login"]["start"].." end = "..bSettings["login"]["end"].." Reason = "..bSettings["login"]["message"])
			end
		elseif status == "off" then
			if bSettings["login"]["enable"] == 0 then
				curUser:SendData(bot,"The blocker is already off!")
			else
				bSettings["login"]["enable"] = 0
				curUser:SendData(bot,"The blocker is disabled!")
				SendPmToOps(bot,"The non-reg blocker has been disabled by: "..curUser.sName)
			end
		else
			curUser:SendData(bot,"*** Syntax error! Please use: "..prefix..cmd1.." ")
		end
		WriteFile(bSettings,mijntabel,file)
	end
end


function NewUserConnected(user)
	if not user.bRegistered and bSettings["login"]["enable"] == 1 then
		local hr=tonumber(os.date("%H"));
		if (bSettings["login"]["end"] - bSettings["login"]["start"]) <= 0 then
			if hr >= bSettings["login"]["start"] or hr < bSettings["login"]["end"] then
				user:SendData(bot,bSettings["login"]["message"])
				user:Disconnect()
				end
		else
			if hr >= bSettings["login"]["start"] and hr < bSettings["login"]["end"] then
				user:SendData(bot,bSettings["login"]["message"])
				user:Disconnect()
			end
		end
	end
end


function Serialize(tTable, sTableName, hFile, sTab)
	sTab = sTab or "";
	hFile:write(sTab..sTableName.." = {\n" );
	for key, value in 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

function WriteFile(table, tablename, file)
	local handle = io.open(file, "w")
	Serialize(table, tablename, handle)
  	handle:close()
end

Have fun... tested it very quick, should work!
TTB

(? ?.??.-> Admin @ Surfnet hubs <-.??.???)

SMF spam blocked by CleanTalk