PtokaX forum

Archive => Archived 4.0 boards => Help with Lua 4 scripts => Topic started by: kb2000 on 23 January, 2004, 19:10:14

Title: Help to view a file
Post by: kb2000 on 23 January, 2004, 19:10:14
I have file in birthday.dat
when i use a command it should be displayed. In that file i have list of birthday dates

example like this

01.02.04Monday person's name is here

like this i have few lines......

How to make this type of file and display it as it is.

Now it is displaying everything next and next and etc.....

Thanks in advance...
Title:
Post by: plop on 23 January, 2004, 19:26:01
  readfrom(file)
   while 1 do
      local line = read()
      if ( line == nil ) then
         break
      else
         user:SendPM(Bot, line)
      end
   end
   readfrom()

plop
Title:
Post by: kb2000 on 23 January, 2004, 20:17:04
Sorry plop,

Can you change in this code
------------------------------------------------------------------------code
--//Festival Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "FestivalBot"
bot_email = "someone@yahoo.com"
bot_speed = "Fast Enough"
bot_descr = "Type !help In PM To Me."
bot_share_size = 420.01 * 1024 *1024
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email
TimeSpanInMinutes = 600   --//You May Change This

function Main()
frmHub:RegBot(botname)
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email..
"$"..bot_share_size.."$"
SetTimer(TimeSpanInMinutes*33000)
StartTimer()
end

function NewUserConnected(curUser)
curUser:SendData( my_info_string )
end

function OpConnected(curUser)
curUser:SendData( my_info_string )
end

function OnTimer()

--//Note that a "|" denotes a break in the line

SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
SendToAll("    HI THERE!!!!, I'm The FestivalBot.")
SendToAll("    Do You Need To know the Upcoming Festivals???")
SendToAll("    CHECK IT!!!")
SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
SendToAll("  To Request A File, Simply Send !help As A Private Message")
SendToAll("  To FestBot.")
SendToAll("  Remember To Check The Upcoming Festivals.....")
SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")

end

function tokenize (inString,token)
_WORDS = {}
local matcher = "([^?"..token.."]+)"
gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
return _WORDS
end

function GetArgs(data)
s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
return arg,arg2
end

function DataArrival(user, data)
if(strsub(data, 1, 4) == "$To:") then
data=strsub(data,1,strlen(data)-1)
s,e,whoTo = strfind(data,"$To:%s+(%S+)")
if (whoTo == botname) then
s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")

if (cmd=="!help") then
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname,"    This is the FestivalBot!")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname," Type !help To View This Help Menu.")
user:SendPM(botname," Type !add To Request A File.")
user:SendPM(botname," Type !list To List The Festivals & Posted Updates.")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
user:SendPM(botname," Please Add the missed Festivals.")
user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
end

if (cmd=="!add") then
SendToAll("***New Festival Added***")
arg= GetArgs(data)
local handle=openfile("festivals.dat","a")
write(handle,"("..user.sName..") requested :"..arg.."?")
user:SendPM(botname,"Festival entry saved ....")
closefile(handle)
end

if (cmd=="!list") then
handle2=openfile("festivals.dat","r")
if (handle2==nil) then
else
line = read(handle2,"*a")
line=strsub(line,1,strlen(line)-1)
linearray=tokenize(line,"?")
for i=1,linearray.n do
user:SendPM(botname,linearray)
end
closefile(handle2)
end

end
end
end
end
---------
Thanks in advance...
Title:
Post by: plop on 23 January, 2004, 20:38:47
yep i could.
------------------------------------------------------------------------code
--//Festival Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "FestivalBot"
bot_email = "someone@yahoo.com"
bot_speed = "Fast Enough"
bot_descr = "Type !help In PM To Me."
bot_share_size = 420.01 * 1024 *1024
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email
TimeSpanInMinutes = 600 --//You May Change This

function Main()
   frmHub:RegBot(botname)my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email.."$"..bot_share_size.."$"
   SetTimer(TimeSpanInMinutes*33000)
   StartTimer()
end

function NewUserConnected(curUser)
   curUser:SendData( my_info_string )
end

function OpConnected(curUser)
   curUser:SendData( my_info_string )
end

function OnTimer()
   --//Note that a "|" denotes a break in the line
   SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
   SendToAll(" HI THERE!!!!, I'm The FestivalBot.")
   SendToAll(" Do You Need To know the Upcoming Festivals???")
   SendToAll(" CHECK IT!!!")
   SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
   SendToAll(" To Request A File, Simply Send !help As A Private Message")
   SendToAll(" To FestBot.")
   SendToAll(" Remember To Check The Upcoming Festivals.....")
   SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
end

function tokenize (inString,token)
   _WORDS = {}
   local matcher = "([^?"..token.."]+)"
   gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
   return _WORDS
end

function GetArgs(data)
   s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
   return arg,arg2
end

function DataArrival(user, data)
   if(strsub(data, 1, 4) == "$To:") then
      data=strsub(data,1,strlen(data)-1)
      s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == botname) then
         s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
         if (cmd=="!help") then
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
            user:SendPM(botname," This is the FestivalBot!")
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
            user:SendPM(botname," Type !help To View This Help Menu.")
            user:SendPM(botname," Type !add To Request A File.")
            user:SendPM(botname," Type !list To List The Festivals & Posted Updates.")
            user:SendPM(botname," Type !birthday To List The birthday's from the hub users.")
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
            user:SendPM(botname," Please Add the missed Festivals.")
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
         elseif (cmd=="!add") then
            SendToAll("***New Festival Added***")
            arg= GetArgs(data)
            local handle=openfile("festivals.dat","a")
            write(handle,"("..user.sName..") requested :"..arg.."?")
            user:SendPM(botname,"Festival entry saved ....")
            closefile(handle)
         elseif (cmd=="!list") then
            handle2=openfile("festivals.dat","r")
            if (handle2==nil) then
               user:SendPM(botname, "Error file couln't be opend|")
            else
               line = read(handle2,"*a")
               line=strsub(line,1,strlen(line)-1)
               linearray=tokenize(line,"?")
               for i=1,linearray.n do
                  user:SendPM(botname,linearray[i])
               end
               closefile(handle2)
            end
         elseif (cmd=="!birthday") then
            readfrom("birthday.dat")
            while 1 do
               local line = read()
               if ( line == nil ) then
                  break
               else
                  user:SendPM(botname, line)
               end
            end
            readfrom()
         end
      end
   end
end

plop
Title:
Post by: kb2000 on 24 January, 2004, 09:01:58
Thanks plop.... and one more request

that is to delete festivals by command

i tried adding a  "delete" cmd in the script,  but not working.... and i don't know much abt lua script, just tried but the script showed you(i mean me not "plop" or anyone) are not the one to do it.

There are professionals (like plop and others) around the forum....


So i'm asking again.. thanks for the help

Please don't misunderstand.........
Title:
Post by: pHaTTy on 24 January, 2004, 09:17:06
QuoteOriginally posted by kb2000
Thanks plop.... and one more request

that is to delete festivals by command

i tried with "delete" cmd but not working.... and i don't know lua script, just tried but the script showed you are not the one to do it.

There are professionals around the forum....


So i'm asking again.. thanks for the help

whats that suppose to mean, plop is a pro, hes probby one of the best on the forum


and btw he has not added a delete command
Title:
Post by: kb2000 on 24 January, 2004, 10:29:51
QuoteOriginally posted by (uk-kingdom)pH?tt?
QuoteOriginally posted by kb2000
Thanks plop.... and one more request

that is to delete festivals by command

i tried with "delete" cmd but not working.... and i don't know lua script, just tried but the script showed you are not the one to do it.

There are professionals around the forum....


So i'm asking again.. thanks for the help

whats that suppose to mean, plop is a pro, hes probby one of the best on the forum


and btw he has not added a delete command

hi ph?tt?,

Please read it again, that is what i mean......
Title:
Post by: pHaTTy on 24 January, 2004, 10:40:50
ok i re-read since u changed it and makes more sense to me now ty :))
Title:
Post by: kb2000 on 24 January, 2004, 11:04:01
QuoteOriginally posted by (uk-kingdom)pH?tt?
ok i re-read since u changed it and makes more sense to me now ty :))

Thanks for understanding me....... May be i think that's good you told or else everyone will think like you..... And it would be very worse for me.....

Anyway thanks again...
Title:
Post by: pHaTTy on 24 January, 2004, 11:07:51
QuoteOriginally posted by kb2000
QuoteOriginally posted by (uk-kingdom)pH?tt?
ok i re-read since u changed it and makes more sense to me now ty :))

Thanks for understanding me....... May be i think that's good you told or else everyone will think like you..... And it would be very worse for me.....

Anyway thanks again...

LoL np i usual speak my mind :)) yw
Title:
Post by: kb2000 on 24 January, 2004, 11:35:34
plop, here is the code now, that i'm using and want to add the delete part also

code
--------------------------------------------------------------------
--//Festival Board Bot
--//(Mr420)
--//A Simple Request Board For The Hub
--//Version 3.0

botname = "FestivalBot"
bot_email = "someone@yahoo.com"
bot_speed = "Fast Enough"
bot_descr = "Type !help In PM To Me."
bot_share_size = 420.01 * 1024 *1024
my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email
TimeSpanInMinutes = 600 --//You May Change This

function Main()
   frmHub:RegBot(botname)my_info_string = "$MyINFO $ALL "..botname.." "..bot_descr.."$ $"..bot_speed..strchar( 1 ).."$"..bot_email.."$"..bot_share_size.."$"
   SetTimer(TimeSpanInMinutes*33000)
   StartTimer()
end

function NewUserConnected(curUser)
   curUser:SendData( my_info_string )
end

function OpConnected(curUser)
   curUser:SendData( my_info_string )
end

function OnTimer()
   --//Note that a "|" denotes a break in the line
   SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
   SendToAll(" HI THERE!!!!, I'm The FestivalBot.")
   SendToAll(" Do You Need To know the Upcoming Festivals???")
   SendToAll(" CHECK IT!!!")
   SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
   SendToAll(" To Request A File, Simply Send !help As A Private Message")
   SendToAll(" To FestBot.")
   SendToAll(" Remember To Check The Upcoming Festivals.....")
   SendToAll("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
end

function tokenize (inString,token)
   _WORDS = {}
   local matcher = "([^?"..token.."]+)"
   gsub(inString, matcher, function (w) tinsert(_WORDS,w) end)
   return _WORDS
end

function GetArgs(data)
   s,e,whoTo,from,cmd,arg,arg2 = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)%s+(.*)")
   return arg,arg2
end

function DataArrival(user, data)
   if(strsub(data, 1, 4) == "$To:") then
      data=strsub(data,1,strlen(data)-1)
      s,e,whoTo = strfind(data,"$To:%s+(%S+)")
      if (whoTo == botname) then
         s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
         if (cmd=="!help") then
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
            user:SendPM(botname," This is the FestivalBot!")
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
            user:SendPM(botname," Type !help To View This Help Menu.")
            user:SendPM(botname," Type !add To Request A File.")
            user:SendPM(botname," Type !festivals To List The Festivals & Posted Updates.")
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
            user:SendPM(botname," Please Add the missed Festivals.")
            user:SendPM(botname,"-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-")
         elseif (cmd=="!add") then
            SendToAll("***New Festival Added***")
            arg= GetArgs(data)
            local handle=openfile("festivals.dat","a")
            write(handle,"("..user.sName..") added :"..arg.."?")
            user:SendPM(botname,"Festival entry saved ....")
            closefile(handle)

         elseif (cmd=="!festivals") then
            readfrom("festivals.dat")
            while 1 do
               local line = read()
               if ( line == nil ) then
                  break
               else
                  user:SendPM(botname, line)
               end
            end
            readfrom()
      end
         end
   end
end
---------------------------------------------------

Thanks again.....
Title:
Post by: pHaTTy on 24 January, 2004, 11:49:52
what do you want it to do?? delete the file? or delete the last line or delete what exactly?
Title:
Post by: kb2000 on 24 January, 2004, 12:51:00
Delete the unwanted line with the given date or festival name.....
Title:
Post by: plop on 24 January, 2004, 19:41:14
QuoteOriginally posted by kb2000
Delete the unwanted line with the given date or festival name.....
do you mind if i mod freshstuf a bit so it suits your needs for doing the same as this bot ???
i like the easy way of deleting i added to the latest version of that.
then it's also easy 2 add adding/removing of birthday's 2 it.

plop
Title:
Post by: kb2000 on 24 January, 2004, 21:15:49
you are welcome to mod it. What i want is to have a help command that tells the commands available and then add, read and del from file (something.dat)

TIA plop
Title:
Post by: kb2000 on 26 January, 2004, 06:43:39
Hi plop,

Have you forgot my request??
Title:
Post by: plop on 26 January, 2004, 12:06:46
QuoteOriginally posted by kb2000
Hi plop,

Have you forgot my request??
no but i have more scripts on the waiting list so you gotta wait your turn. lol
if i don't post it in 3 day's i might have forgotten it.

plop
Title:
Post by: pHaTTy on 26 January, 2004, 13:05:24
it might be possible, but it wil be pretty big, its going to have to do searches, save all file into memory, and remove the line, maybe table would be faster, if i get 2, ill be stright on it
Title:
Post by: plop on 26 January, 2004, 13:38:27
QuoteOriginally posted by (uk-kingdom)pH?tt?
it might be possible, but it wil be pretty big, its going to have to do searches, save all file into memory, and remove the line, maybe table would be faster, if i get 2, ill be stright on it
thats why i suggested using freshstuff 3.3 as a base, then deleting doesn't need any searching.
you can delete by id number.
if you wanne try it be my guest.

plop
Title:
Post by: kb2000 on 28 January, 2004, 15:41:48
Thanks for working on...... i will wait, as i have no knowledge with scripting.....