can someone make a script that lets op's read and wright to and from a text file.what im looking for is to be able to let them say if they are checking users and find say good users i want them to be able to wright that users nick to a text file that the other op's with a command can then read.
!add to add a good users nick to the list(gooduser.txt)
!show to show the list of good users(gooduser.txt)
Hi,
Hope it helps...
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,goodusr = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (goodusr ~= nil) then
appendto(goodtext)
write("\r\n"..goodusr.."\t"..user.sName) --It writes the user and the op who added
writeto()
user:SendPM(Bot, "The user "..goodusr.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
Best regards, nErBoS
wow that was fast :)
il test it out right now
and thank you very much
when i load the bot and type !add i get this [21:25] Syntax error, !add . witch is ok but when i type this !add testing it makes a script error and the bot doesnt respond.
Syntax error: attempt to concat global `gooduser' (a nil value)
stack traceback:
1: function `DataArrival' at line 21 [file `...esktop\New Folder (10)\scripts\FavUsers-Bot.lua']
i fixed it.it was just a few spelling errors no big deal.
thank you very much nErBoS for the fast work on this one . :)
Hi,
You are rigth when you see gooduser change it to goodusr :) ,may bad.
Best regards, nErBoS
PS:I have edited the post and corrected that.
Sorry nErBoS, but i think that it is an error....
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
function Readtextfile(user, file)
hummm...
Why do you say that i am caliing the function readtextfile and this functions recives user and file.
Try to use a let me know :)
Best regards, nErBoS
ok, is a good bot ;)
Wow - I've been looking for this :D
Any change of adding so you can ad comments to that user -EX:
!add Snooze - Damn he should stop asking all those questions!
Result:
Snooze Damn he should stop asking all those questions! Added by: Snooze (Date)
;)
Hi,
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,goodusr, msg = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s+(.*)")
if (goodusr ~= nil) then
appendto(goodtext)
write("\r\n"..goodusr.." "..msg..". Added by: "..user.sName.."("..GetDate()..")") --It writes the user and the op who added
writeto()
user:SendPM(Bot, "The user "..goodusr.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Date()
d = date("%d")
mm = date("%m")
y = date("%y")
Date = d.."/"..mm.."/20"..y
return Date
end
Is this what you want ???
Best regards, nErBoS
DAMN your fast !!!
Its exactly what i had in mind :D
Thanks m8
You sure make it fun running a hub with the help your giving !!!! -
Keep up the good work ;)
ok i have a request on the first one you made . can we add a few more command like !findgu nick = search the list for a user by nick.and say !regu nick =removeing a user from the gooduser list.?
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
appendto(goodtext)
write("\r\n"..gooduser.."\t"..user.sName) --It writes the user and the op who added
writeto()
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
Hi,
Let me know if it works OK...
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
appendto(goodtext)
write("\r\n"..gooduser.."\t"..user.sName) --It writes the user and the op who added
writeto()
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
elseif (cmd=="!findgu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (GetItemByName(gooduser) == nil) then
user:SendPM(Bot, "The user "..gooduser.." isn't online.")
else
user:SendPM(Bot, "The user "..gooduser.." is online.")
end
else
user:SendPM(Bot, "Syntax error, !findgu . ")
end
end
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
RemoveGoodUser(gooduser, goodtext)
else
user:SendPM(Bot, "Syntax error, !regu . ")
end
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Writetextfile(file, array)
writeto(file)
for x=1,getn(array) do write(array[x].."\r\n") end
writeto()
end
function RemoveGoodUser(user, file)
local tmp = ""
local temp = {}
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick = strfind(line, "(%S*)%s%S*%s%S*")
if (nick == user.sName) then
else
tmp = tmp .. line .. "\r\n"
end
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
user:SendPM(Bot, "Done..")
end
Best regards, nErBoS
If your up for it, i have a new challange for you nErBoS ;)
http://board.univ-angers.fr/thread.php?threadid=1358&boardid=11&styleid=1
Hi,
Snooze when i get a free time i will see that, i don?t have any expirence in working a script with a site, i will see what i can learn to help you out.
Best regards, nErBoS
ok im getting a script error when i use the !regu cmd
Syntax error: attempt to index local `user' (a string value)
stack traceback:
1: function `RemoveGoodUser' at line 92 [file `...esktop\New Folder (10)\scripts\FavUsers-Bot.lua']
2: function `DataArrival' at line 52 [file `...esktop\New Folder (10)\scripts\FavUsers-Bot.lua']
Hi,
Try this...
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
appendto(goodtext)
write(gooduser.."\t"..user.sName.."\r\n") --It writes the user and the op who added
writeto()
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
elseif (cmd=="!findgu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (GetItemByName(gooduser) == nil) then
user:SendPM(Bot, "The user "..gooduser.." isn't online.")
return 1
else
user:SendPM(Bot, "The user "..gooduser.." is online.")
return 1
end
else
user:SendPM(Bot, "Syntax error, !findgu . ")
return 1
end
end
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
RemoveGoodUser(gooduser, goodtext)
user:SendPM(Bot, "Done..")
return 1
else
user:SendPM(Bot, "Syntax error, !regu . ")
return 1
end
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Writetextfile(file, array)
writeto(file)
for x=1,getn(array) do write(array[x].."\r\n") end
writeto()
end
function RemoveGoodUser(user, file)
local tmp = ""
local temp = {}
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick = strfind(line, "(%S*)%s%S*%s%S*")
if (nick == user) then
else
tmp = tmp .. line .. "\r\n"
end
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end
Best regards, nErBoS
Thanks nErBoS :-)
working great now . your da man :)
i guess i spoke to soon its not giveing the error and it says [19:18] Done.. when i use the !regu nick but then when i use the !show the user still shows on the list
Hi,
Problay you have a a line blank in the midle of the gooduser.txt you have to delete that line, a little bug i will try to correct him.
Best regards, nErBoS
yep i did have a blank line so i deleted it and its not giveing the error now but it still isnt removeing the user.
great job so far i thank you much for your time on this :)
Hi,
This will solve "i hope :) "..
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
appendto(goodtext)
write(gooduser.."\t"..user.sName.."\r\n") --It writes the user and the op who added
writeto()
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
elseif (cmd=="!findgu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (GetItemByName(gooduser) == nil) then
user:SendPM(Bot, "The user "..gooduser.." isn't online.")
return 1
else
user:SendPM(Bot, "The user "..gooduser.." is online.")
return 1
end
else
user:SendPM(Bot, "Syntax error, !findgu . ")
return 1
end
end
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
RemoveGoodUser(gooduser, goodtext)
user:SendPM(Bot, "Done..")
return 1
else
user:SendPM(Bot, "Syntax error, !regu . ")
return 1
end
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Writetextfile(file, array)
writeto(file)
for x=1,getn(array) do write(array[x].."\r\n") end
writeto()
end
function RemoveGoodUser(user, file)
local time = 0
local tmp = ""
local temp = {}
readfrom(file)
while 1 do
local line = read()
if (time == 3) then
break
else
if (line == nil) then
time = time + 1
else
local s, e, nick = strfind(line, "(%S+)%s+%S+")
if (nick == user) then
time = 0
else
tmp = tmp .. line .. "\r\n"
time = 0
end
end
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end
Best regards, nErBoS
looks like it still isnt removeing the user :(
no script errors tho :)
Hummmm..
Show me your text file with the goodusers please.
Best regards, nErBoS
[dsl]-tony- [DM]kbeh273300
[adsl]q8 [DM]kbeh273300
Pako [DM]kbeh273300
Bladerunner [DM]kbeh273300
bosboot [DM]kbeh273300
[DM]?harlene [DM]?rg??
[DM]bob1082 [DM]?harlene
BigFish [DM]?harlene
[DM]Joostkeijzer [DM]?harlene
[DM]Lazarus [DM]?harlene
[DM]TheOtherOne [DM]?harlene
testing [DM]kbeh273300
[DM]S^yfa [DM]?harlene
[DM]Lazarus [DM]?harlene
[DM]tankman57 [DM]?harlene
[DM]IanJ [DM]?harlene
[DM]IanJ [DM]?harlene
i think i just found my mistake.i was trying to get it too look better when i use the show commnd si i went into the text file and made it like my last post but i see now that that wont work.is there a way of makeing it look neater like the way it is in my last post?the way it is now it looks like this
[18:43] <[DM]kbeh273300> !show
[18:43] [dsl]-tony- [DM]kbeh273300[adsl]q8 [DM]kbeh273300Pako [DM]kbeh273300Bladerunner [DM]kbeh273300bosboot [DM]kbeh273300[DM]?harlene [DM]?rg??[DM]bob1082 [DM]?harleneBigFish [DM]?harlene[DM]Joostkeijzer [DM]?harlene[DM]Lazarus [DM]?harlene[DM]TheOtherOne [DM]?harlenetesting [DM]kbeh273300[DM]S^yfa [DM]?harlene[DM]Lazarus [DM]?harlene[DM]tankman57 [DM]?harlene[DM]IanJ [DM]?harlene[DM]IanJ [DM]?harlene
kinda messy can we make it wright neater like this?
<[DM]kbeh273300> !show
[dsl]-tony- [DM]kbeh273300
[adsl]q8 [DM]kbeh273300
Pako [DM]kbeh273300
Bladerunner [DM]kbeh273300
bosboot [DM]kbeh273300
[DM]?harlene [DM]?rg??
[DM]bob1082 [DM]?harlene
BigFish [DM]?harlene
[DM]Joostkeijzer [DM]?harlene
[DM]Lazarus [DM]?harlene
[DM]TheOtherOne [DM]?harlene
testing [DM]kbeh273300
[DM]S^yfa [DM]?harlene
[DM]Lazarus [DM]?harlene
[DM]tankman57 [DM]?harlene
[DM]IanJ [DM]?harlene
[DM]IanJ [DM]?harlene
but also it still didnt remove the user (testing) witch is what is still not working i hope its not me did i mess something up?
i just found out something the users with - infront of the nicks delete just fine but the users without the - wont delete
[18:56] <[DM]kbeh273300> !show
[18:56] [dsl]-tony- [DM]kbeh273300
- [adsl]q8 [DM]kbeh273300
Pako [DM]kbeh273300
Bladerunner [DM]kbeh273300
bosboot [DM]kbeh273300
- [DM]?harlene [DM]?rg??
- [DM]bob1082 [DM]?harlene
BigFish [DM]?harlene
- [DM]Joostkeijzer [DM]?harlene
- [DM]Lazarus [DM]?harlene
- [DM]TheOtherOne [DM]?harlene
testing [DM]kbeh273300
- [DM]S^yfa [DM]?harlene
- [DM]Lazarus [DM]?harlene
- [DM]tankman57 [DM]?harlene
im sorry for all these postes
Hi,
I have tested and is working...
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
AddGoodUser(user.sName, goodtext, gooduser)
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
elseif (cmd=="!findgu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (GetItemByName(gooduser) == nil) then
user:SendPM(Bot, "The user "..gooduser.." isn't online.")
return 1
else
user:SendPM(Bot, "The user "..gooduser.." is online.")
return 1
end
else
user:SendPM(Bot, "Syntax error, !findgu . ")
return 1
end
end
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
RemoveGoodUser(gooduser, goodtext)
user:SendPM(Bot, "Done..")
return 1
else
user:SendPM(Bot, "Syntax error, !regu . ")
return 1
end
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Writetextfile(file, array)
writeto(file)
for x=1,getn(array) do write(array[x].."\r\n") end
writeto()
end
function RemoveGoodUser(user, file)
local time = 0
local tmp = ""
local temp = {}
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick = strfind(line, "(%S+)%s+%S+")
if (nick == user) then
else
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end
function AddGoodUser(user, file, whoto)
local temp = {}
local tmp = ""
local time = 0
readfrom(file)
while 1 do
local line = read()
if (line == nil or line == "") then
tmp = tmp..whoto.."\t"..user
break
else
tmp = tmp..line.."\r\n"
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end
Delete your old goodtext and let this one start all over.
Best regards nErBoS
Damn im learning tons from this - thanks nErBoS
One more question :D
What would the command line look like if you wanted to delete all lines in the file ? As in clear the txt file..
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
user:SendPM(Bot, "Done..")
return 1
else
user:SendPM(Bot, "Syntax error, !regu . ")
return 1
end
end
**snooze
Hi,
Well just do this...
appendto(file) -- goes to the file wanted
write("") --- will write nothing in the file and everthing that was on him will disappeare
writeto() -- to write on the file
Best regards, nErBoS
well clearing the file, if u append it will leave the other text
Write: write as clean file
Append : Write leaving the other text
so as nerbox says but change appendto to writeto
or
openfile ( file, "w")
write("")
closefile(file)
Sorry you are right :)
Best regards, nErBoS
Thanks goes to both :)
Your are doing a superb job at helping us newbies getting the hang at this :D
Please keep up the good work !
**Snooze
I've used your read/write/delete functions to make a easily edited welcome msg. But im missing one feature.
I need the script to check if there is anything in the file before adding a new entry.
Ex:
If (file) 'not empty' then
SendC(Bot, "Another entry exists. Delete this before adding a new")
return 1
end
I hope this explains what im looking for ;)
**Snooze
Hi,
If you are checking if the file existes use this..
check = readfrom(file)
if (check == nil) then -- this checks if the file exists =nil the file doesn't exists
If you are trying to see if something is written in the file do this..
readfrom(file)
while 1 do
local line = read()
if (line == nil) then --if a line is nil then he checks but coud be mistaken because you could have a text with a first line empty
user:SendPM(Bot, "File is empty")
break
else
user:SendPM(Bot, "File has text")
break
end
end
Best regards, nErBoS
well iv never goten the !regu cmd to work iv started over with it 4 times and its always the same thing it say its deleteing the user but it never does.i use PtokaX DC Hub 0.3.3.0 build 15.25 [debug]
Hi,
My bad on always saying done, fixed that..
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
AddGoodUser(user.sName, goodtext, gooduser)
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
elseif (cmd=="!findgu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (GetItemByName(gooduser) == nil) then
user:SendPM(Bot, "The user "..gooduser.." isn't online.")
return 1
else
user:SendPM(Bot, "The user "..gooduser.." is online.")
return 1
end
else
user:SendPM(Bot, "Syntax error, !findgu . ")
return 1
end
end
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (RemoveGoodUser(gooduser, goodtext) == 0) then
user:SendPM(Bot, "User not founded in the GoodUser list.")
else
user:SendPM(Bot, "Done..")
end
return 1
else
user:SendPM(Bot, "Syntax error, !regu . ")
return 1
end
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Writetextfile(file, array)
writeto(file)
for x=1,getn(array) do write(array[x].."\r\n") end
writeto()
end
function RemoveGoodUser(user, file)
local time = 0
local tmp = ""
local temp = {}
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick = strfind(line, "(%S+)%s+%S+")
if (nick == user) then
time = 1
else
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
return time
end
function AddGoodUser(user, file, whoto)
local temp = {}
local tmp = ""
local time = 0
readfrom(file)
while 1 do
local line = read()
if (line == nil or line == "") then
tmp = tmp..whoto.."\t"..user
break
else
tmp = tmp..line.."\r\n"
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end
I have tried on the ptokax 0.3.3.0 and is working ok !!
Best regards, nErBoS
so if i change it to
while 2 do
it would check the 2nd line, right ?
**Snooze
Hi,
No..
While 1 do --- this number doen?t have nothing to do with the lines, is a condition to while work indefenely, on the code of while you should have a break condition with the break in your case is "if line ==nil then break", if not your while will not stop :)
Best regards, nErBoS
that did the trick nErBoS and i thank you very much for sticking with it.this forum and its scripters just keeps getting better :) your the man i cant thank you enough
I dound a new feature i would love to add.
When a new msg has meen added, could we have it send a PM to 3 "special" users ?
Hi,
Sorry didn?t understood your request :)
Can you be more clear.
Best regards, nErBoS
Sorry...
When a new txt has been added to the txt file, is it possible to have the script send a PM to ex.: 3 special users ?
This is what i tried - it might explain what im after.
I add this:
sHubOwner = { "Snooze", "Owner2", "Owner3", "Owner4" }
Then added this in the script part that sends you a reply that the msg has been written to the txt file:
writeto()
user:SendPM(Bot, "Your Owner Message has been added: Topic: '"..topic.."' Message: '"..msg..".'")
sHubOwner:SendPM(Bot, "A new Owner msg has been added: Topic: '"..topic.."' Message: '"..msg..".'")
return 1
I hope that clears it up ;)
Hi,
This script doesn't save msg, only user and the operator who saved.
Or do you want to add to, when a user his added in the goodlist to send a pm to the special usres ??
Best regards, nErBoS
QuoteOr do you want to add to, when a user his added in the goodlist to send a pm to the special usres ??
Yes - I want to send a notification to a few special users about the latest entry.
Hi,
Made it also when a user is removed...
--Requested by kbeh273300
--Made by nErBoS
Bot = "FavUsers-Bot"
specialusrs = { "nErBoS", "Snooze" }
goodtext = "gooduser.txt" --It will be created in the script folder
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=="!add") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
AddGoodUser(user.sName, goodtext, gooduser)
user:SendPM(Bot, "The user "..gooduser.." was been added to the list GoodUser.")
for i=1, getn(specialusrs) do
if (GetItemByName(specialusrs[i]) ~= nil) then
local usr = GetItemByName(specialusrs[i])
usr:SendPM(Bot, "The user "..gooduser.." has been added to the goodlist by "..user.sName)
else
end
end
return 1
else
user:SendPM(Bot, "Syntax error, !add . ")
return 1
end
end
elseif (cmd=="!show") then
if (user.bOperator) then
Readtextfile(user, goodtext)
return 1
end
elseif (cmd=="!findgu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (GetItemByName(gooduser) == nil) then
user:SendPM(Bot, "The user "..gooduser.." isn't online.")
return 1
else
user:SendPM(Bot, "The user "..gooduser.." is online.")
return 1
end
else
user:SendPM(Bot, "Syntax error, !findgu . ")
return 1
end
end
elseif (cmd=="!regu") then
if (user.bOperator) then
s,e,cmd,gooduser = strfind(data, "%b<>%s+(%S+)%s+(%S+)%s*")
if (gooduser ~= nil) then
if (RemoveGoodUser(gooduser, goodtext) == 0) then
user:SendPM(Bot, "User not founded in the GoodUser list.")
else
user:SendPM(Bot, "Done..")
for i=1, getn(specialusrs) do
if (GetItemByName(specialusrs[i]) ~= nil) then
local usr = GetItemByName(specialusrs[i])
usr:SendPM(Bot, "The user "..gooduser.." has been removed fromm the goodlist by "..user.sName)
else
end
end
end
return 1
else
user:SendPM(Bot, "Syntax error, !regu . ")
return 1
end
end
end
end
end
function Readtextfile(user, file)
local filecontents = ""
local handle = openfile(file, "r")
if (handle ~= nil) then
local line = read(handle)
while line do
filecontents = filecontents..line.."\r\n"
line = read(handle)
end
closefile(handle)
user:SendPM(Bot, filecontents)
end
end
function Writetextfile(file, array)
writeto(file)
for x=1,getn(array) do write(array[x].."\r\n") end
writeto()
end
function RemoveGoodUser(user, file)
local time = 0
local tmp = ""
local temp = {}
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
local s, e, nick = strfind(line, "(%S+)%s+%S+")
if (nick == user) then
time = 1
else
tmp = tmp..line.."\r\n"
end
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
return time
end
function AddGoodUser(user, file, whoto)
local temp = {}
local tmp = ""
local time = 0
readfrom(file)
while 1 do
local line = read()
if (line == nil or line == "") then
tmp = tmp..whoto.."\t"..user
break
else
tmp = tmp..line.."\r\n"
end
end
readfrom()
tinsert(temp, tmp)
Writetextfile(file, temp)
end
Best regards, nErBoS
Perfect nErBoS :))
Thats exactly what i was looking for :)
**Snooze