This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

How to ignore channel messages with a specific phrase?

Help for those learning Tcl or writing their own scripts.
Post Reply
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

How to ignore channel messages with a specific phrase?

Post by daigo »

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.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Put something like this into the proc that does the replying...

Code: Select all

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
.
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

Post by daigo »

I get a TCL error:
Tcl error [good:msg]: can't read "txt": no such variable
This is the code I am using:

Code: Select all

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
 }
}
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Because you did not change the var name to fit into your proc:)

Code: Select all

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
.
d
daigo
Voice
Posts: 37
Joined: Fri Jun 27, 2014 8:02 pm

Post by daigo »

Oops :oops: Thank you Spike
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Or maybe more like this, cleaned up a little...

Code: Select all

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
.
Post Reply