PtokaX forum

Archive => Archived 5.0 boards => Request for scripts => Topic started by: Awenger on 26 March, 2006, 20:29:08

Title: registration script
Post by: Awenger on 26 March, 2006, 20:29:08
I am tryin write new users data to RegisteredUsers.xml file but PtokaX don't see added users :(  Can anyone write script that add new users based on data added to RegisteredUsers.xml or external txt file  (check updates in file once per minite) ?
Title: Re: registration script
Post by: bastya_elvtars on 26 March, 2006, 23:17:49
If one adds them to a textfile like:
Nick/Pass/Profile
then it's possible to read on a certain interval. I may make this script.
Title: Re: registration script
Post by: bastya_elvtars on 27 March, 2006, 01:29:51
By the way this script is cool for using web-based registration to the hub.
Title: Re: registration script
Post by: bastya_elvtars on 27 March, 2006, 01:46:28
f:seek("*a") can do the trick.
Title: Re: registration script
Post by: Awenger on 27 March, 2006, 11:28:20
Thanks for script.

Quote from: Mutor on 27 March, 2006, 01:32:46
Rather than using a straight timer, it may be better to add the users, purge the file and then watch for change in file size on timer.

It will be cool ! Or add timer that read file once per minite and delete or purge it
Title: Re: registration script
Post by: bastya_elvtars on 27 March, 2006, 17:11:35
I am working on the script that does this, but it does not work yet.
Title: Re: registration script
Post by: bastya_elvtars on 27 March, 2006, 19:55:29
Ok, this part is clear. The bug is somewhere else.
Title: Re: registration script
Post by: bastya_elvtars on 27 March, 2006, 22:49:32
I don't know if this works good or not... but anyway, here ya go, another flavor:

--[[

Quick example of regging users from external list.
-Checks if nick is already regged
-Reports results to opnick


Expected file format: (Nickname Password Profile-Number)
Tester1 secret 0
Tester2 swordfish 1
Tester3 unknown 2
Tester4 password 3

Result:
<RegScript>
Failed [Master] Tester1 exists and was not added
Added [Operator] Tester2 with the Password: swordfish
Failed [VIP] Tester3 exists and was not added
Added [Reg] Tester4 with the Password: password

Change the line below (in Main) to reflect your file and your nick
AddReg("addreg.txt","Mutor")

Touched by bastya_elvtars:
- Removes the file upon parsing.
- Checks the last size, and if unchanged, it won't go any further.
- Sends PM to a list of nicks.
- Uses the hub bot's name.
]]

-- NOTE: BETA! Use for testing only!

filename="reg_pending.txt"

interval=30 -- in minutes

Bot=frmHub:GetHubBotName() -- pulling the main hub bit name, should be good in 95% of the cases

opnicks={"[TGA-OP]bastya_elvtars","Mutor"}

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

OnTimer = function()
local f,e = io.open(filename,"r")
if f then
local cur=f:seek()
local size=f:seek("end")
if size~=0 and size~=_LAST then
f:seek("set", cur)
_LAST=size
AddReg(f)
else
-- for _,opnick in ipairs(opnicks) do
-- SendToNick(opnick,"<"..Bot.."> No new registration was necessary.")
-- end
end
else
-- for _,opnick in ipairs(opnicks) do
-- SendToNick(opnick,"<"..Bot.."> "..e)
-- end
end
end

AddReg = function(file)
local reply = ""
local l=0
for line in file:lines() do
l=l+1
local _,_,usr,pwd,prof = string.find(line,"(%S+)%s+(%S+)%s+(%d+)")
if usr then
prof=tonumber(prof)
if not frmHub:isNickRegged(usr) then
AddRegUser(usr,pwd,prof)
reply = reply.."Added ["..GetProfileName(prof).."] "..usr..
" with the Password: "..pwd.."\r\n"
else
reply = reply.."Failed to add ["..GetProfileName(prof)..
"] "..usr.."  - perhaps the account already exists.\r\n"
end
else
reply = reply.."Bad data found in line "..l.." of "..filename.."!"
end
end
file:close()
os.remove(filename)
for _,opnick in ipairs(opnicks) do
SendPmToNick(opnick, Bot, "\r\n"..reply)
end
end

Main=function()
SetTimer(interval*60*1000)
StartTimer()
end
Title: Re: registration script
Post by: Awenger on 28 March, 2006, 00:39:00
To Mutor:
Your script works fine, thanks for help.  I will use it :) 

To Bastya_elvtars:
Script seems working , but bot flood mainchat with messages like - names of regged users, reg_pending.txt: No such file or directory, No new registration was necessary. Even if i dont enter any nicks in line  opnicks={" "} bot post in mainchat nicks of new regged users.

P.S.
IMHO  sends PM or in mainchat reg info don't need because it's very annoying if many registration occurs .  But someone maybe find this very usefull.

I will test more both scripts tomorrow
Title: Re: registration script
Post by: bastya_elvtars on 28 March, 2006, 00:44:11
Thanks for trying out, looks like I forgot to remove some debug code. Edited the above.
Title: Re: registration script
Post by: Awenger on 28 March, 2006, 13:36:51
Thanks , script working very well