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) ?
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.
By the way this script is cool for using web-based registration to the hub.
f:seek("*a") can do the trick.
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
I am working on the script that does this, but it does not work yet.
Ok, this part is clear. The bug is somewhere else.
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
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
Thanks for trying out, looks like I forgot to remove some debug code. Edited the above.
Thanks , script working very well