.promote and .demote
 

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

.promote and .demote

Started by Mardeg, 25 March, 2004, 20:23:51

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mardeg

I'd like users at op level or higher to be able to use:

.promote username
.demote username

on registered users up to or down from the level one below their own, so a SuperOP can demote an OP to VIP, but OPs can't demote other OPs (they get an error message if they try) but can demote a VIP down to Reg and vice versa.
Btw, if a SuperOP promotes a VIP to OP it hopefully should give them OP status instantly, and revoke OP status likewise if they demote an OP.

Is it possible for such a simple pair of commands? I think to work properly they would need to automatically detect the user's current level and password, regardless of whether the user is online at the time.

nErBoS

Hi,

I belive is this what you want...

--Requested by Mardeg
--Made by nErBoS

Bot = "Promter-Bot"

regfile = "../RegisteredUsers.dat"

function Main()
	frmHub:RegBot(Bot)
end

function DataArrival(user, data)
	if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
	data=strsub(data,1,strlen(data)-1)
	s,e,cmd = strfind(data,"%b<>%s+(%S+)")
		if (cmd=="!promote") then
			if (user.bOperator) then
				Promoter(user, data, "pR")
			else
				user:SendPM(Bot, "You don't have permission to use this command.")
			end
			return 1
		elseif (cmd=="depromote") then
			if (user.bOperator) then
				Promoter(user, data, "dP")
			else
				user:SendPM(Bot, "You don't have permission to use this command.")
			end
			return 1
		end
	end
end

function Promoter(user, data, type)
local time = 0
local s,e,who = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
	if (who == nil or who == "") then
		if (type == "pR") then
			user:SendPM(Bot, "Syntax Error, !promote , you must write a name.")
		elseif (type == "dP") then
			user:SendPM(Bot, "Syntax Error, !depromote , you must write a name.")
		end
	else
		readfrom(regfile)
		while 1 do
		local line = read()
			if (line == nil) then
				if (time == 0) then
					user:SendPM(Bot, "The user "..who.." is not registered in the Hub.")
				end
				break
			else
				local s,e,name,pass,level = strfind(line, "(%S+)|(%S+)|(%S+)")
				if (name == who and who ~= nil and tonumber(level) ~= nil) then
					if (user.iProfile > tonumber(level)) then
						user:SendPM(Bot, "You can't promote or depromote the user "..who.." .")
						SendPmToOps(Bot, "The user has tryied to promote or depromote the user "..who.." .")
						time = 1
					else
						if (type == "pR") then
							DelRegUser(who)
							AddRegUser(who, pass, tonumber(level)-1) 
							user:SendPM(Bot, "The user "..who.." has been promoted to "..GetProfileName(tonumber(level)-1))
							SendPmToOps(Bot, "The user "..who.." has been promoted to "..GetProfileName(tonumber(level)-1).." by "..user.sName..".")
							time = 1
						elseif (type == "dP") then
							if (tonumber(level) == 3) then
								DelRegUser(who)
								user:SendPM(Bot, "The user has been depromoted to unreg.")
								SendPmToOps(Bot, "The user "..who.." has been dpromoted to unreg by "..user.sName..".")
								time = 1
							else
								DelRegUser(who)
								AddRegUser(who, pass, tonumber(level)+1) 
								user:SendPM(Bot, "The user "..who.." has been depromoted to "..GetProfileName(tonumber(level)+1))
								SendPmToOps(Bot, "The user "..who.." has been depromoted to "..GetProfileName(tonumber(level)+1).." by "..user.sName..".")
								time = 1
							end
						end
					end
				end
			end
		end
		readfrom()
	end
end

Not tested.

Best regards, nErBoS
--## nErBoS Spot ##--

Mardeg

I got some popup alerts from ptokax with that script that I haven't seen before.

When I attempted either command with users that could be promoted/demoted the message was:

Cannot create file "[Drive:\path\to]\ptokax\RegisteredUsers.dat"

But before I had a chance to look into it another message popped up multiple times over the next minute:

Access violation at address 004531B3 in module 'Ptokax.exe'. Read address 00000062.

Possibly everytime dataarrival occurred after the command. After about 2 dozen popups with this error appeared ptokax just vanished without a crash notification, it's process just no longer appeared in task manager.

nErBoS

#3
Hi,

Sorry the script was doing something that he shouldn't, fixed..

--Requested by Mardeg
--Made by nErBoS

Bot = "Promter-Bot"

regfile = "../RegisteredUsers.dat"

function Main()
	frmHub:RegBot(Bot)
end

function DataArrival(user, data)
	if (strsub(data,1,1)=="<") or (strsub(data,1,5+strlen(Bot))=="$To: "..Bot) then
	data=strsub(data,1,strlen(data)-1)
	s,e,cmd = strfind(data,"%b<>%s+(%S+)")
		if (cmd=="!promote") then
			if (user.bOperator) then
				Promoter(user, data, "pR")
			else
				user:SendPM(Bot, "You don't have permission to use this command.")
			end
			return 1
		elseif (cmd=="!depromote") then
			if (user.bOperator) then
				Promoter(user, data, "dP")
			else
				user:SendPM(Bot, "You don't have permission to use this command.")
			end
			return 1
		end
	end
end

function Promoter(user, data, type)
local time = 0
local iLevel = 0
local sPass = ""
local s,e,who = strfind(data, "%b<>%s+%S+%s+(%S+)")
	if (who == nil or who == "") then
		if (type == "pR") then
			user:SendPM(Bot, "Syntax Error, !promote , you must write a name.")
		elseif (type == "dP") then
			user:SendPM(Bot, "Syntax Error, !depromote , you must write a name.")
		end
	else
		readfrom(regfile)
		while 1 do
		local line = read()
			if (line == nil) then
				break
			else
				local s,e,name,pass,level = strfind(line, "(%S+)|(%S+)|(%S+)")
				if (name == who and who ~= nil and tonumber(level) ~= nil) then
					if (user.iProfile > tonumber(level)) then
						time = 3
						break
					else
						time = 1
						iLevel = tonumber(level)
						sPass = pass
						break
					end
				end
			end
		end
		readfrom()
		if (time == 0) then
			user:SendPM(Bot, "The user "..who.." is not registered in the Hub.")
		elseif (time == 1) then
			if (type == "pR") then
				DelRegUser(who)
				AddRegUser(who, sPass, iLevel-1) 
				user:SendPM(Bot, "The user "..who.." has been promoted to "..GetProfileName(iLevel-1))
				SendPmToOps(Bot, "The user "..who.." has been promoted to "..GetProfileName(iLevel-1).." by "..user.sName..".")
			elseif (type == "dP") then
				if (iLevel == 3) then
					DelRegUser(who)
					user:SendPM(Bot, "The user has been depromoted to unreg.")
					SendPmToOps(Bot, "The user "..who.." has been dpromoted to unreg by "..user.sName..".")
				else
					DelRegUser(who)
					AddRegUser(who, sPass, iLevel+1) 
					user:SendPM(Bot, "The user "..who.." has been depromoted to "..GetProfileName(iLevel+1))
					SendPmToOps(Bot, "The user "..who.." has been depromoted to "..GetProfileName(iLevel+1).." by "..user.sName..".")
				end
			end
		elseif (time == 2) then
			user:SendPM(Bot, "You can't promote or depromote the user "..who.." .")
			SendPmToOps(Bot, "The user has tryied to promote or depromote the user "..who.." .")
		end
	end
end

Best regards, nErBoS
--## nErBoS Spot ##--

Mardeg

#4
Sorry I did a fix myself before seeing yours. I separated the password/level grabbing part to a separate function from the promoter one, and forced the command to only work in mainchat, along with replies from the bot, so the command is visible to everyone when it works.
prefix = "."
------------------
-- Inside DataArrival function:
		if (cmd == prefix.."promote") then
			if (user.bOperator) then
				return Promoter(user, data, "pM")
			else
				SendToNick(user.sName, "<"..Bot.."> You don't have permission to use "..prefix.."promote")
				return 1
			end
		elseif (cmd == prefix.."demote") then
			if (user.bOperator) then
				return Promoter(user, data, "dM")
			else
				SendToNick(user.sName, "<"..Bot.."> You don't have permission to use "..prefix.."demote")
				return 1
			end
		end

------------------

function Promoter(user, data, PorD)
local s,e,cmd,who = strfind(data, "%b<>%s+(%S+)%s+(%S+)")
	if (who == nil or who == "") then
		if (PorD == "pM") then
			SendToNick(user.sName, "<"..Bot.."> FORMAT: "..prefix.."promote username")
		elseif (PorD == "dM") then
			SendToNick(user.sName, "<"..Bot.."> FORMAT: "..prefix.."demote username")
		end
		return 1
	else
		local Pwd, Lvl = GetPwLvl(who)
		if (Pwd == nil) then
			SendToNick(user.sName, "<"..Bot.."> The user "..who.." is not registered in the Hub.")
			return 1
		elseif (user.iProfile >= tonumber(Lvl)-1) and (PorD == "pM") then
			SendToNick(user.sName, "<"..Bot.."> You can't promote the user "..who.." from "..GetProfileName(tonumber(Lvl))..".")
			return 1
		elseif (user.iProfile >= tonumber(Lvl)) and (PorD == "dM") then
			SendToNick(user.sName, "<"..Bot.."> You can't demote the user "..who.." from "..GetProfileName(tonumber(Lvl))..".")
			return 1
		else
			if (PorD == "pM") then
				DelRegUser(who)
				AddRegUser(who, Pwd, tonumber(Lvl)-1) 
				SendPmToOps("OpChat", "The user "..who.." has been promoted to "..GetProfileName(tonumber(Lvl)-1).." by "..user.sName..".")
			elseif (PorD == "dM") then
				if (GetProfileName(tonumber(Lvl)) == "Reg") then
					SendToNick(user.sName, "<"..Bot.."> The user "..who.." is already at the lowest level.")
					return 1
				else
					DelRegUser(who)
					AddRegUser(who, Pwd, tonumber(Lvl)+1) 
					SendPmToOps("OpChat", "The user "..who.." has been demoted to "..GetProfileName(tonumber(Lvl)+1).." by "..user.sName..".")
				end
			end
			return 0
		end
	end
end

function GetPwLvl(sFrom)
	local sPasswdFile = "../RegisteredUsers.dat"
	local flPasswdFile = openfile(sPasswdFile, "r");
	local line         = "";

	sFrom = strlower(sFrom);

	if (flPasswdFile) then
		line = read(flPasswdFile);
		while (line) do
			_, _, sNick, sPasswd, nLevel = strfind(line, "^(%S+)|(%S+)|(%S+)");
			if (strlower(sNick) == sFrom) then
				closefile(flPasswdFile);
				return sPasswd, nLevel
			end
			line = read(flPasswdFile);
		end
		closefile(flPasswdFile);
	end

  return nil
end

Am I right in thinking these level changes are not effective immediately if a user is currently connected, but only after they disconnect and re-login?

If so, when a user is promoted to Op is there a script equivalent to !op username that gives them op status in the current session? And if demoted from Op how can they lose the op status without resorting to disconnecting them?

nErBoS

Hi,

He haves to get re-connect in the Hub to the stauts have affect.

Best regards, nErBoS
--## nErBoS Spot ##--

SMF spam blocked by CleanTalk