PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: kbeh273300 on 23 February, 2004, 01:48:32

Title: request
Post by: kbeh273300 on 23 February, 2004, 01:48:32
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)
Title:
Post by: nErBoS on 23 February, 2004, 02:37:21
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
Title: request
Post by: kbeh273300 on 23 February, 2004, 03:53:41
wow that was fast :)

il test it out right now


and thank you very much
Title: hmmm
Post by: kbeh273300 on 23 February, 2004, 04:29:15
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']
Title: goodusers
Post by: kbeh273300 on 23 February, 2004, 08:07:20
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 . :)
Title:
Post by: nErBoS on 23 February, 2004, 14:17:54
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.
Title:
Post by: DorianG on 23 February, 2004, 14:47:34
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)

Title:
Post by: nErBoS on 23 February, 2004, 14:57:46
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
Title:
Post by: DorianG on 23 February, 2004, 16:00:28
ok, is a good bot  ;)
Title:
Post by: Snooze on 23 February, 2004, 17:43:26
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)
;)
Title:
Post by: nErBoS on 23 February, 2004, 18:12:32
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
Title:
Post by: Snooze on 23 February, 2004, 18:28:20
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 ;)
Title: request
Post by: kbeh273300 on 23 February, 2004, 18:42:13
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
Title:
Post by: nErBoS on 23 February, 2004, 20:45:10
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
Title:
Post by: Snooze on 23 February, 2004, 22:10:18
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
Title:
Post by: nErBoS on 24 February, 2004, 00:28:50
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
Title: request
Post by: kbeh273300 on 24 February, 2004, 01:40:33
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']
Title:
Post by: nErBoS on 24 February, 2004, 02:05:47
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
Title:
Post by: Snooze on 24 February, 2004, 02:08:55
Thanks nErBoS :-)
Title: request
Post by: kbeh273300 on 24 February, 2004, 02:11:20
working great now . your da man :)
Title: oops
Post by: kbeh273300 on 24 February, 2004, 02:20:37
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
Title:
Post by: nErBoS on 24 February, 2004, 14:49:00
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
Title: goodusers
Post by: kbeh273300 on 24 February, 2004, 15:04:04
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 :)
Title:
Post by: nErBoS on 24 February, 2004, 15:21:42
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
Title: hmm
Post by: kbeh273300 on 24 February, 2004, 15:58:22
looks like it still isnt removeing the user :(
no script errors tho :)
Title:
Post by: nErBoS on 24 February, 2004, 16:25:49
Hummmm..

Show me your text file with the goodusers please.

Best regards, nErBoS
Title: goodusers
Post by: kbeh273300 on 25 February, 2004, 01:41:31
[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
Title: goodusers
Post by: kbeh273300 on 25 February, 2004, 01:49:09
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
Title: goodusers
Post by: kbeh273300 on 25 February, 2004, 01:52:25
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?
Title: hmm
Post by: kbeh273300 on 25 February, 2004, 01:58:15
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
Title:
Post by: nErBoS on 25 February, 2004, 02:21:07
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
Title:
Post by: Snooze on 25 February, 2004, 04:01:12
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
Title:
Post by: nErBoS on 25 February, 2004, 13:31:23
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
Title:
Post by: pHaTTy on 25 February, 2004, 13:34:55
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)
Title:
Post by: nErBoS on 25 February, 2004, 13:43:34
Sorry you are right :)

Best regards, nErBoS
Title:
Post by: Snooze on 26 February, 2004, 01:25:38
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
Title:
Post by: Snooze on 26 February, 2004, 17:30:26
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
Title:
Post by: nErBoS on 27 February, 2004, 01:33:03
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
Title: hello
Post by: kbeh273300 on 27 February, 2004, 01:37:47
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]
Title:
Post by: nErBoS on 27 February, 2004, 14:30:19
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
Title:
Post by: Snooze on 27 February, 2004, 14:48:13
so if i change it to

while 2 do


it would check the 2nd line, right ?

**Snooze
Title:
Post by: nErBoS on 27 February, 2004, 15:06:49
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
Title: request
Post by: kbeh273300 on 27 February, 2004, 15:53:22
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
Title:
Post by: Snooze on 01 March, 2004, 00:55:37
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 ?
Title:
Post by: nErBoS on 01 March, 2004, 01:37:51
Hi,

Sorry didn?t understood your request :)
Can you be more clear.

Best regards, nErBoS
Title:
Post by: Snooze on 01 March, 2004, 01:42:46
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 ;)

Title:
Post by: nErBoS on 01 March, 2004, 01:51:21
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
Title:
Post by: Snooze on 01 March, 2004, 01:54:34
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.
Title:
Post by: nErBoS on 01 March, 2004, 02:05:57
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
Title:
Post by: Snooze on 01 March, 2004, 02:09:05
Perfect nErBoS :))


Thats exactly what i was looking for :)


**Snooze