egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bot Auto Reesponse

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
gasak
Halfop


Joined: 09 Aug 2010
Posts: 45

PostPosted: Tue Aug 10, 2010 12:31 am    Post subject: Bot Auto Reesponse Reply with quote

I have this code for auto bot response,

Code:
set crazybib {
"$nick are the real crazy"
}

bind pubm - *v1rus?crazy* pub_crazy

proc pub_crazy {nick uhost handle chan args} {
   global crazybib oldreplytime botnick
   
   set replytime [unixtime]

   if { $replytime - $oldreplytime  > 7} {
      set crazyline [lindex $crazybib [rand [llength $crazybib]]]
      puthelp "PRIVMSG $chan :$crazyline"
      set oldreplytime $replytime
   }
}

set oldreplytime 0


Theres an error on the $nick coding. when it comes on the channel it should replace the $nick as the nick that talk, but it wasnt. it just keep showing the $nick instead of the real nick.

The next question, how to put coding so that the bot will reply to someone if it mention its name with identical word. Tt is to replace this code:

Code:
bind pubm - *v1rus?crazy* pub_crazy


v1rus is the bot nickname. So i dont have to put the botnick and keep changing the tcl when i change the bot name.


please advice.[/code]
_________________
Learning Knows No Boundaries!!
Back to top
View user's profile Send private message
Luminous
Op


Joined: 12 Feb 2010
Posts: 146

PostPosted: Tue Aug 10, 2010 4:35 pm    Post subject: Re: Bot Auto Reesponse Reply with quote

You can certainly have $nick mean the real $nick and not the literal one. What happens is that set crazybib { creates a list of lines that you can then select from using rand or indexes, etc. However, variables are not valid in them unless you use subst -nocommands. However, I have not had good luck using this command with replies hard coded into the script. Seems to work best from a file for me. But, you could try this and see if it does what you want:
Code:
  set crazyline [subst -nocomands [lindex $crazybib [rand [llength $crazybib]]]


As to the second part.. try creating a var like the following:
Code:

set botn "$::botnick"
bind pubm - "*${botn}?crazy*" pub_crazy


and see if that works.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Tue Aug 10, 2010 5:28 pm    Post subject: Reply with quote

Code:
# you may use $nick or $chan here safely.
set crazybib [list "$nick are the real crazy" "$chan is crazy!!" "more"]
set oldreplytime 0

# check that "craz" begins a word somewhere in the input.
bind pubm - {* craz*} pub_crazy

proc pub_crazy {nick uhost handle chan arg} {
   # if botnick isn't the 1st word, return and do nothing
   if {![string equal -nocase [lindex "[split $arg]" [expr {[lsearch -glob [split $arg] "craz*"] -1}]]] $::botnick]} { return }
   # else, call globals and lets start...
   global crazybib oldreplytime
   set replytime [unixtime]
   if { $replytime - $oldreplytime  > 7} {
      set crazyline [lindex $crazybib [rand [llength $crazybib]]]
      # change $nick or $chan to their variable contents safely and easily.
      set crazyline [string map [list "\$nick" "$nick" "\$chan" "$chan" ] $crazyline]
      puthelp "PRIVMSG $chan :$crazyline"
      set oldreplytime $replytime
   }
}

_________________
speechles' eggdrop tcl archive


Last edited by speechles on Tue Aug 10, 2010 5:45 pm; edited 6 times in total
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Tue Aug 10, 2010 5:35 pm    Post subject: Re: Bot Auto Reesponse Reply with quote

Luminous wrote:
As to the second part.. try creating a var like the following:
Code:

set botn "$::botnick"
bind pubm - "*${botn}?crazy*" pub_crazy


and see if that works.


It would, but it wouldn't. The logic for a bot is to run each script globally at start/restart/rehash. Leaving the bind in global space would cause the bots nickname to then become "stuck" to whatever nickname the bot was using during start/rehash/restart when it first ran that script. To get around this I split up the logic, the bind merely checks for "* craz*" and the procedure makes sure the word before "craz" is the bots nickname or returns.
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
gasak
Halfop


Joined: 09 Aug 2010
Posts: 45

PostPosted: Tue Aug 10, 2010 11:59 pm    Post subject: Reply with quote

speechles wrote:
Code:
# you may use $nick or $chan here safely.
set crazybib [list "$nick are the real crazy" "$chan is crazy!!" "more"]
set oldreplytime 0

# check that "craz" begins a word somewhere in the input.
bind pubm - {* craz*} pub_crazy

proc pub_crazy {nick uhost handle chan arg} {
   # if botnick isn't the 1st word, return and do nothing
   if {![string equal -nocase [lindex "[split $arg]" [expr {[lsearch -glob [split $arg] "craz*"] -1}]]] $::botnick]} { return }
   # else, call globals and lets start...
   global crazybib oldreplytime
   set replytime [unixtime]
   if { $replytime - $oldreplytime  > 7} {
      set crazyline [lindex $crazybib [rand [llength $crazybib]]]
      # change $nick or $chan to their variable contents safely and easily.
      set crazyline [string map [list "\$nick" "$nick" "\$chan" "$chan" ] $crazyline]
      puthelp "PRIVMSG $chan :$crazyline"
      set oldreplytime $replytime
   }
}


Thanks for the response.. i tried those script but its not work. It doesnt event replies any. I try write on channel "v1rus crazy" but nothing happen.

Please advice.
_________________
Learning Knows No Boundaries!!
Back to top
View user's profile Send private message
game_over
Voice


Joined: 26 Apr 2007
Posts: 29

PostPosted: Wed Aug 11, 2010 1:50 pm    Post subject: Reply with quote

long way
Code:
proc reply {nick} {
set crazybib "
{$nick are the real crazy}
{lol $nick}
"
return [lindex $crazybib [rand [llength $crazybib]]]
}

bind pubm - *$botnick?crazy* pub_crazy

proc pub_crazy {nick uhost handle chan args} {
   global oldreplytime botnick
   set replytime [unixtime]
   if { $replytime - $oldreplytime  > 7} {   
      puthelp "PRIVMSG $chan :[reply $nick]"
      set oldreplytime $replytime
   }
}

set oldreplytime 0
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Aug 11, 2010 2:29 pm    Post subject: Reply with quote

gasak wrote:
speechles wrote:
Code:
# you may use $nick or $chan here safely.
set crazybib [list "$nick are the real crazy" "$chan is crazy!!" "more"]
set oldreplytime 0

# check that "craz" begins a word somewhere in the input.
bind pubm - {* craz*} pub_crazy

proc pub_crazy {nick uhost handle chan arg} {
   # if botnick isn't the 1st word, return and do nothing
   if {![string equal -nocase [lindex "[split $arg]" [expr {[lsearch -glob [split $arg] "craz*"] -1}]]] $::botnick]} { return }
   # else, call globals and lets start...
   global crazybib oldreplytime
   set replytime [unixtime]
   if { $replytime - $oldreplytime  > 7} {
      set crazyline [lindex $crazybib [rand [llength $crazybib]]]
      # change $nick or $chan to their variable contents safely and easily.
      set crazyline [string map [list "\$nick" "$nick" "\$chan" "$chan" ] $crazyline]
      puthelp "PRIVMSG $chan :$crazyline"
      set oldreplytime $replytime
   }
}


Thanks for the response.. i tried those script but its not work. It doesnt event replies any. I try write on channel "v1rus crazy" but nothing happen.

Please advice.


Does it load for you?

I tried it, and to get it to load, I had to change:
Code:

set crazybib [list "$nick are the real crazy" "$chan is crazy!!" "more"]

to
Code:

set crazybib [list "\$nick are the real crazy" "\$chan is crazy!!" "more"]



Also, ... I'm not sure what is meant here:
Code:

if {![string equal -nocase [lindex "[split $arg]" [expr {[lsearch -glob [split $arg] "craz*"] -1}]]] $::botnick]} { return }

as that line produces errors for me.

To do:
Quote:

# if botnick isn't the 1st word, return and do nothing

I changed that line to:
Code:

if {![string equal -nocase [lindex [split $arg] 0] $::botnick]} { return}


If you want to experiment with yours, try the above changes.

Also, check back to see what speechles has to say.
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed Aug 11, 2010 6:09 pm    Post subject: Reply with quote

Luminous wrote:
Also, ... I'm not sure what is meant here:
Code:
if {![string equal -nocase [lindex "[split $arg]" [expr {[lsearch -glob [split $arg] "craz*"] -1}]] $::botnick]} { return }

Let me simplify it.

we start with [split $arg] and apply an lsearch using glob matching for any word (since we split $arg) matching "craz*" .. this will give us the exact position of it within the entire list (of the split $arg, remember). Since this gives us the location of where "craz*" is (and will never error, it was bound on the same thing, it can never be -1...) you need to subtract one from it's place to get the word used in front of it. There you see the -1. This is then applied as the lindex position, of again, splitting $arg. This gives us the _exact_ word used prior. This is then run through a string equal with nocase option compared against the bots present nick ($::botnick). If it doesn't match, we return.

You are correct I didn't do the obvious:
Code:
set crazybib [list {$nick etc} {stuff $chan etc etc} {etc etc}]
Using escapes is needed within the double-quotes I demonstrated that with. But with braces this works without them.

Does that explain it?
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Aug 11, 2010 7:40 pm    Post subject: Reply with quote

speechles wrote:

...
This gives us the _exact_ word used prior. This is then run through a string equal with nocase option compared against the bots present nick ($::botnick). If it doesn't match, we return.
...
Does that explain it?


Yes, but I had all that. ... I must be missing something, as I dont' know why we need that.
I thought we just needed to check to see if botnick is the first word, not the first word prior to craz* .
Back to top
View user's profile Send private message
speechles
Revered One


Joined: 26 Aug 2006
Posts: 1398
Location: emerald triangle, california (coastal redwoods)

PostPosted: Wed Aug 11, 2010 8:15 pm    Post subject: Reply with quote

willyw wrote:
Yes, but I had all that. ... I must be missing something, as I dont' know why we need that.
I thought we just needed to check to see if botnick is the first word, not the first word prior to craz* .


Code:
bind pubm - *v1rus?crazy* pub_crazy


The OP's (original posters) bind, it illustrates this Wink
I went that "extra mile" making it also pick up variants; crazier, craziest, crazyass, crazyfool, crazymotherforker, crazolicious, crazetc...
_________________
speechles' eggdrop tcl archive
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Aug 11, 2010 8:45 pm    Post subject: Reply with quote

[quote="speechles"]
willyw wrote:

...

Code:
bind pubm - *v1rus?crazy* pub_crazy


The OP's (original posters) bind, it illustrates this Wink
...


I wasn't sure that was he really intended, even then.

Lately, I was going with the comment in your script:
# if botnick isn't the 1st word, return and do nothing


Hopefully, the OP will be able to get whatever it is that he wants, out of our posts. Smile


Thanks
Back to top
View user's profile Send private message
gasak
Halfop


Joined: 09 Aug 2010
Posts: 45

PostPosted: Wed Aug 11, 2010 10:57 pm    Post subject: Reply with quote

Wow.. it works now.. thanks a lot to willyw, game_over, speechles.

May i ask another question?

With the same script, how to make the bot response when someone on channels mention the bot name with an action. For example: /me $botnick crazy or /me punch $botnick then the bot will reply it.

Thanks before
_________________
Learning Knows No Boundaries!!
Back to top
View user's profile Send private message
gasak
Halfop


Joined: 09 Aug 2010
Posts: 45

PostPosted: Thu Aug 12, 2010 5:38 am    Post subject: Reply with quote

Dear All,

i try using game_over script.. it works for this one..

Code:
#---------------------------------------------------------------------
# dodol
#---------------------------------------------------------------------

proc reply {nick} {
set dodolbib "
{lu kata makanan yang dari garut}
{tau deh yang tukang dodol}
{\001ACTION males ladenin orang yg lebih dodol :p}
{yang bilang $::botnick dodol matanya juling}
"
return [lindex $dodolbib [rand [llength $dodolbib]]]
}

bind pubm - *$botnick?dodol* pub_dodol
bind pubm - *dodol*?$botnick* pub_dodol

proc pub_dodol {nick uhost handle chan args} {
   global oldreplytime botnick

   set replytime [unixtime]

   if { $replytime - $oldreplytime  > 7} {   
      puthelp "PRIVMSG $chan :[reply $nick]"
      set oldreplytime $replytime
   }
}

set oldreplytime 0


but when i try to add another different response below it becomes conflict,

Code:
#---------------------------------------------------------------------
# dodol
#---------------------------------------------------------------------

proc reply {nick} {
set dodolbib "
{lu kata makanan yang dari garut}
{tau deh yang tukang dodol}
{\001ACTION males ladenin orang yg lebih dodol :p}
{yang bilang $::botnick dodol matanya juling}
"
return [lindex $dodolbib [rand [llength $dodolbib]]]
}

bind pubm - *$botnick?dodol* pub_dodol
bind pubm - *dodol*?$botnick* pub_dodol

proc pub_dodol {nick uhost handle chan args} {
   global oldreplytime botnick

   set replytime [unixtime]

   if { $replytime - $oldreplytime  > 7} {   
      puthelp "PRIVMSG $chan :[reply $nick]"
      set oldreplytime $replytime
   }
}

set oldreplytime 0

#---------------------------------------------------------------------
# owner
#---------------------------------------------------------------------

proc reply {nick} {
set ownerbib "
{ada deeeehhhhhhhh}
{ganteng deh pokoknya :)}
{\001ACTION tunjuk tunjuk....}
{aduh.. bilang gk yaahh.. hmm.. $::botnick malu akh -_-!!}
"
return [lindex $ownerbib [rand [llength $ownerbib]]]
}

bind pubm - *$botnick?owner* pub_owner
bind pubm - *owner*?$botnick* pub_owner

proc pub_owner {nick uhost handle chan args} {
   global oldreplytime botnick

   set replytime [unixtime]

   if { $replytime - $oldreplytime  > 7} {   
      puthelp "PRIVMSG $chan :[reply $nick]"
      set oldreplytime $replytime
   }
}

set oldreplytime 0


whatever i say on the first response (dodol) it just give me answer for the second response (owner). Even though i say dodol in channel, it just keep answering using "ownerbib" instead of "dodolbib".

Why it is so? Please advice.

For speechles/willyw scripts it just allow the bot response if only the botnick mention at the 1rst word. But with game_over script i can make 2 possibilites weather the botnick mention at the first, middle or even at the last word.

Another advice please Smile
_________________
Learning Knows No Boundaries!!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber