PtokaX forum

Archive => Archived 4.0 boards => Request for Lua 4 scripts => Topic started by: Pit on 08 November, 2004, 18:00:15

Title: A better guestbook
Post by: Pit on 08 November, 2004, 18:00:15
Greetings scripters

I have this script:

bot = "GuestBook"

AddEntry = "!assinar"
Help = "!guestbook"
ReadGB = "!ler"

function Main()
   frmHub:RegBot(bot)
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 == bot then
         s,e,whoTo,from,cmd = strfind(data,"$To:%s+(%S+)%s+From:%s+(%S+)%s+$%b<>%s+(%S+)")
         if cmd==AddEntry then
            arg= GetArgs(data)
            local handle=openfile("guestbook.dat","a")
            write(handle,"("..user.sName..") Assinou :"..arg.."?")
            SendPmToNick(botname,"Entrada gravada no GuestBook ....")            
            closefile(handle)
            SendToAll("Nova entrada no nosso GuestBook pelo User "..user.sName.."!!")
         return 1
         elseif cmd==Help then
            user:SendPM(bot,"Benvindo ao GuestBook do Friends!")
            user:SendPM(bot,"Assina como quiseres!")
            user:SendPM(bot,"      ")
            user:SendPM(bot,"Para assinar o Livro basta escrever   !assinar  < msg >  ")
            user:SendPM(bot,"Para ler todas as mensagens escrever  !ler   ")
         return 1
         elseif cmd==ReadGB then
            handle2=openfile("guestbook.dat","r")
            if (handle2~=nil) then
               line = read(handle2,"*a")
               line=strsub(line,1,strlen(line)-1)
               linearray=tokenize(line,"?")
               for i=1,linearray.n do
                  user:SendPM(bot,linearray)
               end
            closefile(handle2)
            end
         return 1
         end
      end
   elseif strsub(data, 1, 1) == "<"  then
      data=strsub(data,1,strlen(data)-1)
      s,e,cmd = strfind(data,"%b<>%s+(%S+)")

      if cmd==AddEntry then
         local s,e,arg = strfind(data,"%b<>%s+%S+%s+(.*)")
         if arg ~= nil and arg ~= "" then
            local handle=openfile("guestbook.dat","a")
            write(handle,"("..user.sName..") assinou :"..arg.."?")
            user:SendData(bot,"Entrada gravada no GuestBook ....")
            closefile(handle)
         else
            user:SendData(bot,"Escreve qualquer coisa, n?o estou programado para ler pensamentos! :)")
         end
         return 1
      elseif cmd==Help then
         user:SendPM(bot,"Este ? o nosso GuestBook! Assina como quiseres!     '  !assinar  < msg >  ;     !ler ' ")
      return 1
      elseif cmd==ReadGB then
         handle2=openfile("guestbook.dat","r")
         if (handle2~=nil) then
            line = read(handle2,"*a")
            line=strsub(line,1,strlen(line)-1)
            linearray=tokenize(line,"?")
            for i=1,linearray.n do
               user:SendPM(bot,linearray)
            end
         closefile(handle2)
         end
      return 1
      end
   end
end

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

Now what i wanted if it's possible, is can the bot send a msg when we enter on it??
I mean,
when we send private msg to it, then it opens but stays blanc, is it possible that the bot script after we enter on it give us a welcome msg, like:

Welcome 'nick'
Type !assinar to write the guestbook
Type !ler to read all msgs

..instead of the actual procedure, witch is , we have to type !guestbook to see this comands...

And one other thing scripters,
On the guestbook.dat that is created only appears teh msgs and who wrote them, is it possible to have a few more points, like date and time??
Thanks

and please cheak it out how the help functions appears:
is like this:

Benvindo ao GuestBook do Friends!
Assina como quiseres!
     
Para assinar o Livro basta escrever   !assinar  < msg >  
Para ler todas as mensagens escrever  !ler  

Can you make it like this:

Benvindo ao GuestBook do Friends!
                       Assina como quiseres!
       
                       Para assinar o Livro basta escrever   !assinar  < msg >  
                       Para ler todas as mensagens escrever  !ler  


Hope you can do this, it's just a matter of 'estectic'!!!

Keep helping who needs..

Thanks a lot
Title:
Post by: Herodes on 08 November, 2004, 22:07:46
There is a way to pop up a blank window , yes ...

but what do you mean by saying 'entering'? either you chat to or you receive chat from ...

there isnt a middle state in this ...
as there isnt in the pm chat with other ppl ...

BTW were is the Vital CREDITS note ??
Title: SORRY
Post by: Pit on 09 November, 2004, 01:29:18
Greetings Herodes

In first place...yes...The guestbook script isn't mine!!!
Is from plop, nerbos or another great scripter!
I simple edit it here but with no intention what so ever to make believe that is mine...
I don?t know how to make this scripts....
I never did any...

But i 'apoligise' the autor of this script...Honest

Now, what i mean is imagine i want to sign the guestbook, so i send a private msg to the bot by clicking right mouse, choosing the the pvt msg.
So a page blanc opens and stays as well, what i wanted was when i do that when entering the blanc page, even i don't type anything i wanted to receve promptly a msg with the comands..

Hope it work..

Thanks
Title: Same script...
Post by: Pit on 09 November, 2004, 12:47:09
Greetings Mutor

Thanks for the reply man
But that script is one level below this one i have...
There's nothing new on it...

P.S. I've said i'm sorry about the missing CREDITS, but it seems like my mistake is more importante that the help i need...

But thanks anyway...i'll research for who's the owner of this script i have and then i'll post here my sincere respects for it...

Thanks..


monnie
Title:
Post by: Herodes on 09 November, 2004, 15:05:36
Well what you ask of isnt possible ...
if you dont sent data to the bot there is no way it can respond on its own .. and the  "about-to-start-a-pm-session" simply isnt sending any data ..

The bot cant figure out that you've opened that window as you cant have known if some1 else does that on your nick .. you are only able to realise that he did if you get some chat ... I hope it's clear ..
Title: Thanks for the answer..but
Post by: Pit on 09 November, 2004, 18:58:20
Greetings

Sorry Herodes,
what you've said is not true!
I have a chatroom created by plop and it does what i say
When i enter the room
the boot sends me imedeatly a welcome msg
saying Hello
without any word by my nick

But thanks for your time

Pit
Title:
Post by: Herodes on 10 November, 2004, 14:08:45
if you dont send data to it ..
there is no way that it knows you want smth from it ..

So maybe that you dont explain what you need in the right way ?

I mean maybe  it triggers on Logging in to the hub .. or maybe some other way that you'll need to make clear .. :)