PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Mardeg on 25 March, 2004, 20:23:51

Title: .promote and .demote
Post by: Mardeg on 25 March, 2004, 20:23:51
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.
Title:
Post by: nErBoS on 26 March, 2004, 02:41:53
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
Title:
Post by: Mardeg on 26 March, 2004, 22:46:50
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.
Title:
Post by: nErBoS on 26 March, 2004, 23:15:32
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
Title:
Post by: Mardeg on 27 March, 2004, 01:54:30
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?
Title:
Post by: nErBoS on 27 March, 2004, 02:18:27
Hi,

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

Best regards, nErBoS