PtokaX forum

Development Section => Your Developing Problems => Topic started by: Znupi on 11 June, 2006, 21:56:07

Title: Screwed with RegBot
Post by: Znupi on 11 June, 2006, 21:56:07
I tryed to make a regbot ... and it works just fine except for one thing ... here's the code:

--[[

...ooO::: ReG BoT bY ZnuPi :::Ooo...

]]--

---------------------------- [ Here-The-ScriPt-StartS ] ----------------------------

Bot = frmHub:GetHubBotName() --Don't mess with this
OpChat = frmHub:GetOpChatName() --Neither with this
prefix = "!" --Prefix you want users to use, example: if prefix = "!", they will use !regme <pass>, if prefix is "@", they will use @regme <pass>
regpref = "[Znup.Member]" --Prefix of nick required for a user to register, change to "" for any prefix
regnr = 3 --Auto-detects, better not mess with this


function NewUserConnected(user)
if (user.bRegistered == nil) then
if (string.sub(user.sName,1,string.len(regpref)) ~= regpref) then
user:SendData(Bot,"If you want to reg yourself, set your nick prefix to "..regpref)
user:SendData("$UserCommand 1 1 Reg Help $<%[mynick]> "..prefix.."rhelp&#124;|")
else
user:SendData(Bot,"\r\nYou have the prefix required to get regged! Don't miss this oportunity!\r\n"..
"You may use right-click commands to get regged, or use "..prefix.."regme <pass>")
user:SendData("$UserCommand 1 1 Get ReggeD $<%[mynick]> "..prefix.."regme %[line:Password]&#124;|")
end
else
user:SendData(Bot,"\r\nWelcome regged user "..user.sName.." !\r\n"..
"To get unregged use right-click commands or type "..prefix.."unregme")
user:SendData("$UserCommand 1 1 Get UnReggeD $<%[mynick]> "..prefix.."unregme&#124;|")
end
end


function ChatArrival(user,data)
data = string.sub(data,1,string.len(data)-1)
s,e,cmd = string.find(data,"%s+(%S+)")
if (cmd == prefix.."regme") then
if (user.bRegistered and user.bOperator == nil) then
user:SendData(Bot,"Dude, ur already regged!")
return 1
end
if (user.bOperator) then
user:SendData(Bot,"Dude, ur an OP !")
return 1
end
if (string.sub(user.sName,1,string.len(regpref)) ~= regpref) then
user:SendData(Bot,"First, you have to set your nick prefix to "..regpref)
return 1
end
local i = 0
CheckReg()
s,e,cmd,pass = string.find(data,"%s+(%S+)%s+(.*)")
user:SendData(Bot,"Pass: "..pass)
AddRegUser(user.sName,pass,regnr)
SendPmToOps(OpChat,"\r\n\r\n\t"..string.rep("=",7).."R-E-G"..string.rep("=",7).."\r\n\r\n"..
"\tUser: "..user.sName.."\r\n\r\n"..
"\tIP: "..user.sIP.."\r\n\r\n"..
"\tPassword: "..pass.."\r\n\r\n"..
"\t"..string.rep("=",7).."R-E-G"..string.rep("=",7).."\r\n\r\n")
user:SendPM(Bot,"\r\n\r\n\t"..string.rep("=",5).."? [ You haVe been reGGeD ]? "..string.rep("=",5).."\r\n\r\n"..
"\t[ Profile Information ]\r\n\r\n"..
"\tNick: "..user.sName.."\r\n\r\n"..
"\tPassword: "..pass.."\r\n\r\n"..
"\t[ BeTTer WriTe ThiS DoWn ;) ]\r\n\r\n"..
"\t"..string.rep("=",5).."? [ You haVe been reGGeD ]? "..string.rep("=",5))
return 1
end
if (cmd == prefix.."unregme") then
DelRegUser(user.sName)
user:SendPM(Bot,"\r\n\r\n\t\t\t"..string.rep("[=]",5).."? ?[ Your accounT haS beeN DeleteD ]? ?"..string.rep("[=]",5))
SendPmToOps(OpChat,"\r\n\r\n\t"..string.rep("=",7).."U-N-R-E-G"..string.rep("=",7).."\r\n\r\n"..
"\tUser: "..user.sName.."\r\n\r\n"..
"\tIP: "..user.sIP.."\r\n\r\n"..
"\t"..string.rep("=",7).."U-N-R-E-G"..string.rep("=",7).."\r\n\r\n")
return 1
end
if (cmd == prefix.."rhelp") then
user:SendData(Bot,"\r\n\r\nHow to get regged to this hub:\r\n"..
"\t1)Add this hub to your favorites by typing /fav\r\n"..
"\t2)Go to your favorite hubs list, right-click this one, choose Properties and change your nick to one with the prefix "..regpref.."\r\n"..
"\t3)Reconnect to the hub\r\n"..
"\t4)Use Right-click commands to register or type !regme <pass> to get regged with your desired password\r\n")
return 1
end
end

function CheckReg()
if (GetProfileName(regnr) ~= "Reg") then
while (GetProfileName(i)) do
if (GetProfileName(i)=="Reg") then
regnr = i
i = i + 1
return 1
end
end
end
end

---------------------------- [ Here-The-ScriPt-EndS ] ----------------------------

The CheckReg() function doesn't work ... if I set regnr to 2 by default ... the users get regged as VIP ...
Two questions : Is it necessary to make this checking, is the default number going to be 3 all the time ?
Where have I gone wrong? ;D

Oh, and ... another thing ... I do know my string.find is bad ... but it works ...
Title: Re: Screwed with RegBot
Post by: Rincewind on 11 June, 2006, 22:23:53
In PtokaX a registered user always has a profile number of 3.

The full listing of profiles is;
      -1 = unreg
       3 = reg
       2 = VIP
       1 = operator
       0 = master

Some scripts like Robocop and Grimoire also use;
       4 = moderator
       5 = net founder
Title: Re: Screwed with RegBot
Post by: Znupi on 11 June, 2006, 22:28:52
So I can lose the CheckReg() function, thanks.
Title: Re: Screwed with RegBot
Post by: bastya_elvtars on 12 June, 2006, 00:21:56
Quote from: Znupi on 11 June, 2006, 22:28:52
So I can lose the CheckReg() function, thanks.

The less function calls, the better. Separate functions should only be declared if used frequently.
Title: Re: Screwed with RegBot
Post by: Markitos on 12 June, 2006, 09:34:08
BTW u need to register the bot in the userlist to send Pm msgs...
Title: Re: Screwed with RegBot
Post by: Psycho_Chihuahua on 12 June, 2006, 12:42:53
Quote from: Markitos on 12 June, 2006, 09:34:08
BTW u need to register the bot in the userlist to send Pm msgs...

If he is using Bot = frmHub:GetHubBotName() not necessarily (well if HubBot is already registered he doesn't have to - otherwise your right)
Title: Re: Screwed with RegBot
Post by: Znupi on 13 June, 2006, 08:46:10
The Hub Bot is registered, otherwise I would have registered it. ;D
Title: Re: Screwed with RegBot
Post by: Markitos on 13 June, 2006, 10:02:00
Quote from: Psycho_Chihuahua on 12 June, 2006, 12:42:53
Quote from: Markitos on 12 June, 2006, 09:34:08
BTW u need to register the bot in the userlist to send Pm msgs...

If he is using Bot = frmHub:GetHubBotName() not necessarily (well if HubBot is already registered he doesn't have to - otherwise your right)
Silly me  ;D