## first, set a few user defines
##
setudef flag encrypted
## this is used to 'mark' your encypted channels
setudef str blowkey
## this is the encyrption key to use for the channel

### these flags are used like this:
## .chanset #channel +encrypted
## .chanset #channel blowkey "encryption key"

## here is a nice little switch that handles your pub commands
proc pubTriggers {nick uhost hand chan text} {
	## check that the channel is marked as encrypted and that we have a key set for it
	if {(![channel get $chan encrypted]) || (![string length [set bkey [channel get $chan blowkey]]])} {return}
	## decrypt the text and seperate out the trigger from the arguments
	set trigger [lindex [split [set text [decrypt $bkey $text]]] 0]
	set text [join [lrange [split $text] 1 end]]
	## start the switch to handle your commands...these normally would have thier own binds
	switch -exact $trigger {
		!help {pub_help_proc $nick $uhost $hand $chan $text}
		!list {pub_list_proc $nick $uhost $hand $chan $text}
		!blah {pub_blah_proc $nick $uhost $hand $chan $text}
		## no match..lets stop
		default {return}
	}
}
bind pubm -X * pubTriggers

## notice the bind...we use pubm to catch ALL text including the possible trigger
## we also bind to all flags EXCEPT custom flag X...this allows us to exclude certain users/things
## example:
## .adduser somebot
## .chattr somebot +X
## this bot will now not trigger this bind

## another common question...how to handle pubm binds...much the same manner...see below

## here is a nice little switch that handles your pubm commands
proc pubmTriggers {nick uhost hand chan text} {
	## check that the channel is marked as encrypted and that we have a key set for it
	if {(![channel get $chan encrypted]) || (![string length [set bkey [channel get $chan blowkey]]])} {return}
	## start the switch to handle your commands...these normally would have thier own binds
	## we also include the channel in the glob...to match as close as possible to a real pubm bind
	## note the text is also decrypted here as well
	switch -glob "$chan[set text [decrypt $bkey $text]]" {
		"*#bob*hello*" {pubm_proc $nick $uhost $hand $chan $text}
		"*hello world*" {another_pubm_proc $nick $uhost $hand $chan $text}
		## no match..lets stop
		default {return}
	}
}
bind pubm -X * pubmTriggers

## same story with the bind here...we still use pubm since we are doing pubm..
## and we use the -X to allow for exceptions via a custom flag

## hope this helps people with thier encrypted channels
## leprechau@EFnet
