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.
Help for those learning Tcl or writing their own scripts.
x0x
Op
Posts: 140 Joined: Tue Feb 10, 2009 6:42 am
Post
by x0x » Sat Feb 16, 2013 8:49 am
This script replies to certain words (wildcard) with a random message. I would like to have it ignore a couple of nicknames tho. How to add this?
Code: Select all
bind pubm - *word* pub_random
proc pub_random {nick mask hand channel args} {
global randommessage
putquick "PRIVMSG $channel :[lindex $randommessage [rand [llength $randommessage]]]"
}
set randommessage {
"Message 1"
"Message 2"
"Message 3"
}
putlog "Random Reply Script Loaded"
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Sat Feb 16, 2013 9:00 am
Try this
Code: Select all
bind pubm - *word* pub_random
set temp(ignore) {
"nick1"
"nick2"
}
proc pub_random {nick mask hand channel args} {
global randommessage temp
foreach n $temp(ignore) { if {[string tolower $nick] == [string tolower $n]} { return } }
putquick "PRIVMSG $channel :[lindex $randommessage [rand [llength $randommessage]]]"
}
set randommessage {
"Message 1"
"Message 2"
"Message 3"
}
putlog "Random Reply Script Loaded"
x0x
Op
Posts: 140 Joined: Tue Feb 10, 2009 6:42 am
Post
by x0x » Sat Feb 16, 2013 9:12 am
Works great! Thank you!
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Mon Feb 18, 2013 5:20 am
There no need to loop inside a list when you have list functions specially made for this kind of operations like
lsearch that will "see if a list contains a particular element".
Also, to end a loop you should use
break not
return . There's no need for two transformations of strings in to lower format if you would have used
string match -nocase for instance.
Anyway, the best option would have been a
lsearch -nocase like this:
Code: Select all
if {[lsearch -nocase $temp(ignore) $nick]} return
instead of the foreach line.
Once the game is over, the king and the pawn go back in the same box.
x0x
Op
Posts: 140 Joined: Tue Feb 10, 2009 6:42 am
Post
by x0x » Mon Feb 18, 2013 5:27 am
So how would the script look like if you add this fix?
caesar
Mint Rubber
Posts: 3778 Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory
Post
by caesar » Mon Feb 18, 2013 7:35 am
Replace the foreach line with the one I mentioned?
Once the game is over, the king and the pawn go back in the same box.
Madalin
Master
Posts: 310 Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:
Post
by Madalin » Mon Feb 18, 2013 7:59 am
Replace
foreach n $temp(ignore) { if {[string tolower $nick] == [string tolower $n]} { return } }
with
if {[lsearch -nocase $temp(ignore) $nick]} return
or using my version
foreach n $temp(ignore) { if {[string match -nocase $nick $n]} { break } }
This last version is better than the first i made (now its using string match and break) the secod is caesar idea