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 

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

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
chadrt
Voice


Joined: 19 Mar 2006
Posts: 33

PostPosted: Wed Feb 11, 2015 5:40 am    Post subject: Fun Kicking - Match trigger anywhere not just first word... Reply with quote

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:
#### 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?
Back to top
View user's profile Send private message
chadrt
Voice


Joined: 19 Mar 2006
Posts: 33

PostPosted: Wed Feb 11, 2015 6:51 am    Post subject: Reply with quote

Ok so after reading http://www.eggheads.org/support/egghtml/1.6.21/tcl-commands.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:
Quote:
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:
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!) Very Happy
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Wed Feb 11, 2015 7:46 am    Post subject: Reply with quote

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
.
Back to top
View user's profile Send private message Visit poster's website
chadrt
Voice


Joined: 19 Mar 2006
Posts: 33

PostPosted: Wed Feb 11, 2015 7:04 pm    Post subject: Reply with quote

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:
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.
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Feb 12, 2015 7:49 am    Post subject: Reply with quote

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.
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 -> Scripting Help 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