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.

Fun Kicking - Match trigger anywhere not just first word...

Help for those learning Tcl or writing their own scripts.
Post Reply
c
chadrt
Voice
Posts: 33
Joined: Sun Mar 19, 2006 4:37 pm

Fun Kicking - Match trigger anywhere not just first word...

Post by chadrt »

I have this script that provides some fun kicking in the chat room that I built but I would like it to match the trigger word anywhere in the text. Right now it only works if it is the first word in the line from the user.

Code: Select all

#### TEST TO PROVIDE FUN KICKS IN CHAT ####

bind pub - **goodnight** fun1
bind pub - **poof** fun2
bind pub - **badboy** fun3
bind pub - **badgirl** fun3


proc fun1 {nick host hand chan text} {
putserv "KICK $chan $nick :Goodnight and sweet dreams!"
}

proc fun2 {nick host hand chan text} {
putserv "KICK $chan $nick :With a wave of the Magic Wand you disappear!"
}

proc fun3 {nick host hand chan text} {
putserv "KICK $chan $nick :You have been very very bad!!!!!"
If a user types this then it works:
**goodnight** everyone I am tired

Want it to work like this too:
Oh my gosh I am so tired **goodnight** everyone!

So that no matter where in the text it would pick it up! Any ideas on this little modification?
c
chadrt
Voice
Posts: 33
Joined: Sun Mar 19, 2006 4:37 pm

Post by chadrt »

Ok so after reading http://www.eggheads.org/support/egghtml ... mands.html I have found that using "pubm" will look for the word to provide the proc but it is interpreting the * as a wildcard and not as a character is there a way to stop this?

I thought maybe I could escape the characters but that didnt work.

I tried to use a string match but it also interprets the * as a wildcard.

EDIT:
string match ?-nocase? pattern string
See if pattern matches string; return 1 if it does, 0 if it does not. If -nocase is specified, then the pattern attempts to match against the string in a case insensitive manner. For the two strings to match, their contents must be identical except that the following special sequences may appear in pattern:

*
Matches any sequence of characters in string, including a null string.

?
Matches any single character in string.

[chars]
Matches any character in the set given by chars. If a sequence of the form x-y appears in chars, then any character between x and y, inclusive, will match. When used with -nocase, the end points of the range are converted to lower case first. Whereas {[A-z]} matches “_” when matching case-sensitively (since “_” falls between the “Z” and “a”), with -nocase this is considered like {[A-Za-z]} (and probably what was meant in the first place).

\x
Matches the single character x. This provides a way of avoiding the special interpretation of the characters *?[]\ in pattern.
So according to this from the TCL manual I should be able to escape the * in the string match. But even this is not working. Here is my code that I have been testing with.

Code: Select all

bind pubm - * funkicker


proc funkicker {nick host hand chan txt} {
  set txt [string tolower $txt]

  if {([string match -nocase "\*\*test\*\*" $txt])} {
  puthelp "PRIVMSG $chan :$nick, this is a test message"
  }

  return 0
} 
This should have made it recognize **test** but it is not instead it is recognizing just plain old "test" all by itself.

(Sorry for my rambling I just want you all to see I am trying to read and do my homework before blindly asking you to complete my idea for me!) :D
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

My guess is you did not restart the bot to remove all of your old binds in the testing before this bind:)

You must restart the bot to remove all prior binds.

You might also try this as your pattern: {\*\*test\*\*} :or: "\\*\\*test\\*\\*"
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
c
chadrt
Voice
Posts: 33
Joined: Sun Mar 19, 2006 4:37 pm

Post by chadrt »

Spike,

I was performing a .die on the PL and then restarting in the shell. But that was not doing it! Your idea of double escaping the *'s did the trick, but I had to do it like this adding the additional *'s to each end.

Code: Select all

proc funkicker {nick host hand chan txt} {
  set txt [string tolower $txt]

  if {([string match -nocase "*\\*\\*test\\*\\**" $txt])} {
  puthelp "PRIVMSG $chan :$nick, this is a test message"
  }

  return 0
}
Then it all came together! Thank you for the assistance.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

If you use string match -nocase there's no need for the string tolower as the first will match either way if it's upper, lower or mixed case.
Once the game is over, the king and the pawn go back in the same box.
Post Reply