| View previous topic :: View next topic |
| Author |
Message |
x0x Op
Joined: 10 Feb 2009 Posts: 140
|
Posted: Sat Feb 16, 2013 8:49 am Post subject: Ignore certain nicks (random reply script) |
|
|
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: | 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" |
|
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Sat Feb 16, 2013 9:00 am Post subject: |
|
|
Try this
| Code: |
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"
|
_________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
x0x Op
Joined: 10 Feb 2009 Posts: 140
|
Posted: Sat Feb 16, 2013 9:12 am Post subject: |
|
|
| Works great! Thank you! |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Feb 18, 2013 5:20 am Post subject: |
|
|
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: |
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. |
|
| Back to top |
|
 |
x0x Op
Joined: 10 Feb 2009 Posts: 140
|
Posted: Mon Feb 18, 2013 5:27 am Post subject: |
|
|
| So how would the script look like if you add this fix? |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Feb 18, 2013 7:35 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Mon Feb 18, 2013 7:59 am Post subject: |
|
|
Replace
| Quote: | foreach n $temp(ignore) { if {[string tolower $nick] == [string tolower $n]} { return } }
|
with
| Quote: | | if {[lsearch -nocase $temp(ignore) $nick]} return |
or using my version
| Quote: | | 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 _________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
|