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.

Binding a certain ACTION CTCP

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

Binding a certain ACTION CTCP

Post by dokueki »

I want to make a bind for an ACTION CTCP containing a certain word/words in them. Here's the script I made:

Code: Select all

#=================================================================================
# ** Notification(c) 1.0 by Hen Asraf
#=================================================================================
# * What does it do?
#---------------------------------------------------------------------------------
#   Reads from the keywords list and sends a PM to every nick in the nicknames
#   list whenever any of the keywords are mentioned in one of the bot's channels.
#   It also sends the original time of which it was triggered to prevent the lag
#   from causing a delay without the users knowing.
#
#   Good for cases where the botmaster is asleep or away and wouldn't want to miss
#   messages that were referring to them or something important.
#=================================================================================

# Set the keywords to trigger the notifier. Seperate with a space.
set keywords "Spide Spidy kumo kami"

# Set the nicknames to send the PM to. Seperate with a space.
set nicknames "kumoKami"
# MAIN #
# Turn the keywords and nicknames variables into lists.
set keywords [split $keywords ]
set nicknames [split $nicknames ]


# For each keyword in the list, bind the keyword to the spidey:notify procedure.
foreach keyword $keywords {
	bind pubm * "*$keyword*" spidey:notify
	bind ctcp * "ACTION*$keyword*" spidey:notify_tcl
}

# Start procedure
proc spidey:notify { nick host hand chan text } {

	# If the notified user said one of the keywords, you don't have to trigger the
	# messsage.
	foreach nickname $::nicknames {
		if { $nick != "$nickname" } {
			# Send the message in the following format:
			# (@time) [ #channel ] Nickname: Entire line containing the keyword(s)
			putserv "PRIVMSG $nickname :(@[strftime {%I:%M:%S %p}]) \[ $chan \] \002$nick:\002 \00312$text\003"
		}
	}

}
# Action procedure (/me)
proc spidey:notify_tcl { nick host hand chan key text } {

	# If the notified user said one of the keywords, you don't have to trigger the
	# messsage.
	foreach nickname $::nicknames {
		if { $nick != "$nickname" } {
			# Send the message in the following format:
			# (@time) [ #channel ] Nickname: Entire line containing the keyword(s)
			putserv "PRIVMSG $nickname :(@[strftime {%I:%M:%S %p}]) \[ $chan \] \0036\002$nick\002 $text\003"
		}
	}

}

# When successfully loaded, put this line into the partyline for logging purposes.
putlog "Notification 1.0 by Hen Asraf: Loaded"
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Just a little confused, if you're just announcing the release of this script, or whether you needed help with something?
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

Post by dokueki »

Oh yeah I wasn't very descriptive >_< Sorry.
I wanted to say, that I need only certain action CTCPs to be binded. How would I go upon doing this? "ACTION*keyword*" doesn't seem to bind what I need, if you look inside the first foreach loop.

And oops, I didn't notice I put it here :x If someone could put it in the scripting help section, It'd be lovely.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Bind against "ACTION", nothing else. Then within spidey:notify_tcl, test wether text contains any of your keywords.

Basically, Only the first word in a ctcp-message is the "key", the rest is the message/text/parameters/whatever. That's why you need to bind against "ACTION", and not "ACTION something".
NML_375
d
dokueki
Voice
Posts: 31
Joined: Sat Apr 28, 2007 8:42 am
Location: Bat Yam, Israel
Contact:

Post by dokueki »

I was trying to avoid that to make things simpler, but I guess I won't :P
Ok, so I have another question:
If several keywords appear in one message, the message is triggered for every one of them. How do I make it stop after only one trigger for each message? break didn't work :<
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Hmm... think you could post your test, cause break should end any kind of loop (innermost if nested loops).

One approach might be to iterate through the whole list of keywords, set some temp-variable if matched. Then, once the loop has completed, test for the presence of that variable, and take appropriate actions.
NML_375
Post Reply