All pastes #207869 Raw Edit

ndcatch

public text v1 · immutable
#207869 ·published 2006-10-18 08:30 UTC
rendered paste body
namespace eval ::ngBot::NDCatch {
	variable ndcatch

	## Config Settings ###############################
	##
	set ndcatch(sections) { "/site/" }
	##
	set ndcatch(targets) { "Something" }
	##
	##################################################

	variable scriptName [namespace current]::LogEvent
	bind evnt -|- prerehash [namespace current]::DeInit
}

proc ::ngBot::NDCatch::Init {args} {
	global postcommand

	variable scriptName

	## Register the event handler.
	lappend postcommand(NEWDIR) $scriptName

	putlog "\[ngBot\] NewDirCatch :: Loaded successfully."
}

proc ::ngBot::NDCatch::DeInit {args} {
	global postcommand

	variable scriptName

	## Remove the script event from postcommand.
	if {[info exists postcommand(NEWDIR)] && [set pos [lsearch -exact $postcommand(NEWDIR) $scriptName]] !=  -1} {
		set postcommand(NEWDIR) [lreplace $postcommand(NEWDIR) $pos $pos]
	}

	catch {unbind evnt -|- prerehash [namespace current]::DeInit}

	namespace delete [namespace current]
}

proc ::ngBot::NDCatch::LogEvent {event section logData} {
	variable ndcatch

	set data(pf) [lindex $logData 0]
	set data(u_name) [lindex $logData 1]
	set data(g_name) [lindex $logData 2]
	set data(u_tagline) [lindex $logData 3]

	foreach path $ndcatch(sections) {
		if {[string match -nocase "$path*" $data(pf)]} {
			putserv "PRIVMSG [join $ndcatch(targets) ","] :five [file tail $data(pf)]"

			break
		}
	}

	return 1	
}

::ngBot::NDCatch::Init