mIRCLog - Logs for pisg/mIRCStats

This plain and quite simple sBNC add-on will log all the various events (chatting, joins, parts, and so on) in the mIRC format. I chose this format so it could be used in both pisg and mIRCStats, the most common log→html statistic generators.

Requirements

Software Version Details
sBNC (w/TCL module) 1.1 Developed and tested on 1.2-864 but does not use any features specific to 1.2.

Download

  • No releases yet. For now you can use the source below.

Usage

Source

mirclog.tcl

#
# @name       mIRCLog - Create logs for pisg/mIRCStats
# @version    Build 1 (????-??-??)
# @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
# @author     David Lorentsen <zyberdog@quakenet.org>
# @www        http://wiki.zyberdog.dk/sbnc:mirclog
#
 
if {[namespace exists ::mirclog]} {
	namespace delete ::mirclog
}
 
namespace eval ::mirclog {
 
	# Configuration
 
	# Full path to the folder you want logs to be saved in.
	# Without trailing /
	variable logdir "~/sbnc/logs"
 
	# Log rotating
	#   0 = disabled, 1 file per channel
	#   1 = daily, 1 file/channel per day. #channel.YYYYMMDD.log
	#   2 = monthly, 1 file/channel/month. #channel.YYYYMM.log
	variable rotate 1
 
	# Use write buffer
	#   0 = disabled.
	#   1 = enabled. Events/chat is placed in a buffer and only written to the 
	#                logs every 10 minutes. Less CPU-intensive.
	variable usebuffer 1
 
	# End of Configuration
 
	# Initialize variables
	variable buffer
	array set buffer {}
 
	# Binds
	bind pubm - * pubm
	bind join - * join
	bind part - * part
	bind sign - * sign
	bind kick - * kick
	bind nick - * nick
	bind topc - * topc
	bind mode - * mode
	bind ctcp - "ACTION" action
 
	# Procedures
	proc pubm {nick host hand chan para} {
		log $chan "\[[clock format "%H:%M"]\] <$nick> $para"
	}
	proc join {nick host hand chan} {
		log $chan "\[[clock format "%H:%M"]\] *** $nick ($host) has joined $chan"
	}
	proc part {nick host hand chan} {
		log $chan "\[[clock format "%H:%M"]\] *** $nick ($host) has left $chan ()"
	}
	proc sign {nick host hand chan para} {
		log $chan "\[[clock format "%H:%M"]\] *** $nick has left $chan ($para)"
	}
	proc kick {nick host hand chan targ para} {
		log $chan "\[[clock format "%H:%M"]\] *** $targ was kicked by $nick ($text)"
	}
	proc nick {nick host hand chan newn} {
		log $chan "\[[clock format "%H:%M"]\] *** $nick is now known as $newn"
	}
	proc topc {nick host hand chan para} {
		log $chan "\[[clock format "%H:%M"]\] *** $nick changes topic to '$para'"
	}
	proc mode {nick host hand chan chag vict} {
		log $chan "\[[clock format "%H:%M"]\] *** $nick sets mode: $chag $vict"
	}
	proc ctcp {nick host hand targ keyw args} {
		if {![string equal [string index $targ 0] "#"]}
		log $chan "\[[clock format "%H:%M"]\] * $nick $args"
	}
 
 
	proc date {} {
		variable rotate
		switch $rotate {
			2 { return [clock format ".%Y%m"] }
			1 { return [clock format ".%Y%m%d"] }
			default { return }
		}
	}
 
 
	proc log {channel line} {
		variable usebuffer
		variable buffer
 
		if {[string equal $usebuffer "1"]} {
			set $buffer([string tolower $channel]) [lappend $buffer([string tolower $channel]) $line]
 
		} else {
			save $channel $line
 
		}
	}
 
 
	proc save {{channel ""} {line ""}} {
		variable logdir
 
		if {[string equal $channel ""] && [string equal $line ""]} {
			variable buffer
 
 
			foreach chan [array names buffer] {
				set file [open "$logdir/$chan[date].log" "a"]
				puts $file [join $buffer($chan) "\n"]
				close $file
 
				array unset buffer $chan
			}
 
		} else {
			set file [open "$logdir/[string tolower $channel][date].log" "a"]
			puts $file $line
			close $file
 
		}
	}
 
 
	proc init {} {
		variable logdir
		variable usebuffer
 
		if {![file isdirectory $logdir]} {
			file mkdir $logdir
 
		} elseif {![file iswriteable $logdir]} {
			return -code error \
				"\$logdir is not writeable: $logdir"
		}
 
		if {[string equal $usebuffer "1"]} {
			internaltimer 600 1 [namespace current]::save
 
		} else {
			variable buffer
 
			if {![string equal [lsearch -exact [internaltimers] "[namespace current]::save 600 1 \{\}"] "-1"]} [
				internalkilltimer [namespace current]::save
			}
 
			save
		}
	}
 
	init
 
}

History

  • No releases to list changes in between yet.
sbnc/mirclog.txt · Last modified: 2006/12/06 21:07 by zyberdog