| View previous topic :: View next topic |
| Author |
Message |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sat Jul 19, 2014 4:54 am Post subject: How to ignore channel messages with a specific phrase? |
|
|
My bot responds to any phrase with "good morning" in it said by a user in a channel with "the sun is up" (so if a user said in the channel, "today is a good morning" my bot would still respond with "the sun is up").
How would I make it so that if a user says "good morning!" (with an exclamation point after the letter 'g'), my bot doesn't respond to this message and just ignores it?
I would like to know how to do this in general with any phrase. |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Jul 19, 2014 11:07 am Post subject: |
|
|
Put something like this into the proc that does the replying...
| Code: | | if {$txt eq "good morning!"} { return 0 } |
Then do the channel reply after this line. _________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sat Jul 19, 2014 11:17 am Post subject: |
|
|
I get a TCL error:
| Quote: | | Tcl error [good:msg]: can't read "txt": no such variable |
This is the code I am using:
| Code: | set goodchan "#daigo"
bind pubm - * good:msg
proc good:msg {nick host hand chan arg} {
global goodchan
if {[string match -nocase "*good morning*" $arg] && $chan == $goodchan && $nick != "daigo"} {
puthelp "PRIVMSG $goodchan :the sun is up"
return 0
}
} |
|
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Jul 19, 2014 11:23 am Post subject: |
|
|
Because you did not change the var name to fit into your proc:)
| Code: | set goodchan "#daigo"
bind pubm - * good:msg
proc good:msg {nick host hand chan arg} {
global goodchan
if {[string tolower $arg] eq "good morning!"} { return 0 }
if {[string match -nocase "*good morning*" $arg] && $chan == $goodchan && $nick != "daigo"} {
puthelp "PRIVMSG $goodchan :the sun is up"
return 0
}
} |
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
daigo Voice
Joined: 27 Jun 2014 Posts: 37
|
Posted: Sat Jul 19, 2014 11:29 am Post subject: |
|
|
Oops Thank you Spike |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Jul 19, 2014 1:13 pm Post subject: |
|
|
Or maybe more like this, cleaned up a little...
| Code: | set goodchan "#daigo"
bind pubm - * good:msg
proc good:msg {nick host hand chan txt} {
set txt [string tolower $txt]
if {$chan ne $::goodchan || $nick eq "daigo" || $txt eq "good morning!"} {
return 0
}
if {[string match "*good morning*" $txt]} {
puthelp "PRIVMSG $chan :the sun is up"
}
return 0
} |
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
. |
|
| Back to top |
|
 |
|