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:
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:
# 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
}
}
Last edited by speechles on Tue Aug 10, 2010 5:45 pm, edited 6 times in total.
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.
# 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.
# 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:
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.
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* .
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* .
The OP's (original posters) bind, it illustrates this
I went that "extra mile" making it also pick up variants; crazier, craziest, crazyass, crazyfool, crazymotherforker, crazolicious, crazetc...
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.
#---------------------------------------------------------------------
# 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.