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 

Ignore certain nicks (random reply script)

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


Joined: 10 Feb 2009
Posts: 140

PostPosted: Sat Feb 16, 2013 8:49 am    Post subject: Ignore certain nicks (random reply script) Reply with quote

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
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Sat Feb 16, 2013 9:00 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
x0x
Op


Joined: 10 Feb 2009
Posts: 140

PostPosted: Sat Feb 16, 2013 9:12 am    Post subject: Reply with quote

Works great! Thank you!
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Mon Feb 18, 2013 5:20 am    Post subject: Reply with quote

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
View user's profile Send private message
x0x
Op


Joined: 10 Feb 2009
Posts: 140

PostPosted: Mon Feb 18, 2013 5:27 am    Post subject: Reply with quote

So how would the script look like if you add this fix?
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Mon Feb 18, 2013 7:35 am    Post subject: Reply with quote

Replace the foreach line with the one I mentioned? Smile
_________________
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
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Mon Feb 18, 2013 7:59 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
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