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.

Mel2 Error [SOLVED]

Support & discussion of released scripts, and announcements of new releases.
Post Reply
m
marvz
Halfop
Posts: 64
Joined: Fri Jun 18, 2010 2:37 pm

Mel2 Error [SOLVED]

Post by marvz »

Code: Select all

Eggdrop v1.6.19+ctcpfix (C) 1997 Robey Pointer (C) 2008 Eggheads
[20:20] --- Loading eggdrop v1.6.19+ctcpfix (Mon Aug  2 2010)
[20:20] Listening at telnet port 5555 (all).
[20:20] Module loaded: blowfish        
[20:20] Module loaded: dns             
[20:20] Module loaded: channels        
[20:20] Module loaded: server          
[20:20] Module loaded: ctcp            
[20:20] Module loaded: irc             
[20:20] Module loaded: notes            (with lang support)
[20:20] Module loaded: console          (with lang support)
[20:20] Module loaded: uptime          
[20:20] gseen.mod v1.1.1 dev3 loaded.
[20:20] Module loaded: gseen           
[20:20] LegoMan's Quote Database Script: Loading quote database...
[20:20] LegoMan's Quote Database Script: for help on commands, type .helpqs
[20:20] LegoMan's Quote Database Script [script_load]: Loaded 5 quotes from beersnob.quote_database
[20:20] Loaded LegoMan's Quote Database Script v1.2.0 successfully.
[20:20] Loading language "en" from language/gseen.en.lang...
[20:20] Initializing mEL 2.0....
[20:20] mEL 2.0 - Running startup tests...
[20:20] mEL 2.0 - Tcl version 8.5 detected... OK.
[20:20] mEL 2.0 - Eggdrop version 1.6.19+ctcpfix detected... OK.
[20:20] mEL 2.0 - mel exists and is a directory... OK.
[20:20] mEL 2.0 - mel/logs exists and is a directory... OK.
[20:20] mEL 2.0 - Marvz is a valid user on this bot... OK.
[20:20] mEL 2.0 - No channels defined. Use +chan first. Unable to add datestamp in logfile.
[20:20] Tcl error in file 'beersnob.conf':
[20:20] missing operator at _@_
in expression "0_@_9 -1";
looks like invalid octal number
    (parsing expression "09 -1")
    invoked from within
"expr [lindex $t 3] -1"
    (procedure "::mel::checkstamptimer" line 27)
    invoked from within
"::mel::checkstamptimer"
    invoked from within
"if {[::mel::starttests]} {
	putlog $::mel::starterror
	die "Fatal error - Can not continue"
} else {
	::mel::arrayinit
	::mel::logfile datestamp all
	..."
    (file "scripts/mel2.tcl" line 1105)
    invoked from within
"source scripts/mel2.tcl"
    (file "beersnob.conf" line 1362)
[20:20] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
Marvin-Gomezs-MacBook:Eggdrop marvingomez$ 
I looked around for similar errors and couldn't find anything. The funny thing is that it worked before and now its not. I didn't do anything different or install anything new on the bot. It worked for a few days then one day I did a rehash and boom, I got this error. I'm trying to install ircstats now and they suggested that I use this to convert the log files into something that could be used by ircstats. Any help would be appreciated. thanks in advance.
Last edited by marvz on Tue Aug 03, 2010 12:33 pm, edited 1 time in total.
m
marvz
Halfop
Posts: 64
Joined: Fri Jun 18, 2010 2:37 pm

Post by marvz »

Got it fixed thanks to simple on the undernet servers #tcl.

For those that may encounter the problem, here's the fix:

Locate this in the script

Code: Select all

expr [lindex [string trimleft $t 0] 3] -1
Change it to this:

Code: Select all

expr [string trimleft [lindex $t 3] 0] -1
Again, all credit goes to simple on IRC. Thanks!
s
storm6699
Voice
Posts: 4
Joined: Mon Sep 20, 2010 9:15 am

Post by storm6699 »

there are no such lines in my mel2.tcl
[15:20] Tcl error in file 'eggdrop.conf':
[15:20] expected integer but got "09" (looks like invalid octal number)
while executing
"expr [lindex $t 3] -1"
(procedure "::mel::checkstamptimer" line 27)
invoked from within
"::mel::checkstamptimer"
invoked from within
"if {[::mel::starttests]} {
putlog $::mel::starterror
die "Fatal error - Can not continue"
} else {
::mel::arrayinit
::mel::logfile datestamp all
..."
(file "scripts/mel2.tcl" line 1105)
invoked from within
"source scripts/mel2.tcl"
(file "eggdrop.conf" line 1360)
[15:20] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
Connection closed by foreign host.
Is it possible that someone upload the correct mel2.tcl pls

thnx
m
marvz
Halfop
Posts: 64
Joined: Fri Jun 18, 2010 2:37 pm

Post by marvz »

Download it from here: http://mel.sourceforge.net/

I ended up removing the mel2 script and started using pisg. Not because I didn't like it but because my shell provider isn't compatible with the mel2 script.

If you still have a problem let me know and I can try looking for the old copy I had here with the fix.
s
storm6699
Voice
Posts: 4
Joined: Mon Sep 20, 2010 9:15 am

Post by storm6699 »

I am using the version from a http://mel.sourceforge.net/ and the script worked well until I made one occasion . / rehash and since then crashes eggdrp and prints error

Code: Select all

[15:20] Tcl error in file 'eggdrop.conf':
[15:20] expected integer but got "09" (looks like invalid octal number)
while executing
"expr [lindex $t 3] -1"
(procedure "::mel::checkstamptimer" line 27)
invoked from within
"::mel::checkstamptimer"
invoked from within
"if {[::mel::starttests]} {
putlog $::mel::starterror
die "Fatal error - Can not continue"
} else {
::mel::arrayinit
::mel::logfile datestamp all
..."
(file "scripts/mel2.tcl" line 1105)
invoked from within
"source scripts/mel2.tcl"
(file "eggdrop.conf" line 1360)
[15:20] * CONFIG FILE NOT LOADED (NOT FOUND, OR ERROR)
Connection closed by foreign host.

In the meantime, I have not changed anything or added to the script to eggdrop

eggdrop1.6.19
TCL 8.4

sorry on my english
m
marvz
Halfop
Posts: 64
Joined: Fri Jun 18, 2010 2:37 pm

Post by marvz »

Can you please post your script so I can take a look at it?

I had the same exact problem when I was using it. I did a .rehash and it started acting up.
s
storm6699
Voice
Posts: 4
Joined: Mon Sep 20, 2010 9:15 am

Post by storm6699 »

Code: Select all

#### mIRCStats Eggdrop Logger 2.0
#### (c)1999-2004 Jules <mel@angelbears.org>
#### Multiple Channel Support by SirSir <sirsir@thuntek.net>
#### Unix/Linux Support by T_D <todd6971@msn.com> #cracks2000@EFNet
####
#### This tcl creates mIRC-style channel logfiles for use with the popular
#### mIRCStats <http://www.mircstats.com> program.
#### This script is written for Tcl 8.1 or higher and Eggdrop 1.6.0 or higher.
#### Running this script on any lower version of Tcl or Eggdrop will cause your
#### eggdrop to die.
####
#### For version history see history.txt


#### Change your settings below ####

#### Check readme.txt for explanation of these settings

namespace eval mel {
	
	# Location of logfiles
	variable statslogdir mel/logs
	# Location of configuration files
	variable statsdir mel
	# Static logkeeper
	variable staticlogkeeper storm6699
	# Add datestamp in the log itself at regular intervals (0=never 1=daily 2=weekly 3=monthly)
	variable stamplogs 1
	# Adds datestamp in logfile name
	variable dodatestamp 1
	# Use year (yyyy) instead of date in filename (in case of adding a datestamp)
	variable doyearstamp 1
	# Strips '#' from logfile name
	variable unixnames 1
	# Enable/disable host blocking
	variable bhosts 0
	# Day of week (1 is monday) <- for weekly rotation
	variable weekly 1
	# Notify static logkeeper on logfile rotation?
	variable notify 1
	
	# Ignore nicknames
	variable ignorenicks {
		botnick
		bot2nick
		bot3nick
		ChanServ
	}
}	

# # # # # # # # # # # # DO NOT CHANGE ANYTHING BELOW HERE # # # # # # # # # # #

bind dcc * mel ::mel::dcc
bind pubm - * ::mel::chatter
bind join - * ::mel::enter
bind sign - * ::mel::signoff
bind topc - * ::mel::ctopic
bind kick - * ::mel::kicked
bind nick - * ::mel::nickchange
bind mode - * ::mel::cmode
bind part - * ::mel::parting
bind ctcp - "ACTION" ::mel::action

namespace eval mel {
	
	variable settings settings.mel
	variable enabled 0
	variable version "mEL 2.0"
	variable channels
	variable macmode 1
	variable rotate week
	variable keepers
	variable deadchanfile deadchans.mel
	variable nextswitch
	variable weekdays
	variable skipmac 0
	array set weekdays {
		1	monday
		2	tuesday
		3	wednesday
		4	thursday
		5	friday
		6	saturday
		7	sunday
	}

	variable actives [list statslogdir statsdir settings staticlogkeeper stamplogs dodatestamp doyearstamp skipmac macmode rotate weekdays weekly nextswitch unixnames enabled version channels keepers deadchanfile bhosts notify ignorenicks]
	
	proc starttests {} {
		variable actives
		variable starterror
		foreach v $actives {variable $v}
		if {$::tcl_version >= "8.1"} {
			putlog "$version - Tcl version $::tcl_version detected... OK."
		} else {
			variable starterror "Tcl version $::tcl_version detected... FAILED! I need at least Tcl 8.1 to function properly."
			return 1
		}
		if {[string range $::numversion 0 2] >= 106} {
			putlog "$version - Eggdrop version [lindex $::version 0] detected... OK."
		} else {
			variable starterror "Eggdrop version [lindex $::version 0] detected... FAILED! I need at least Eggdrop 1.6.0 to function properly."
			return 1
		}
		if {![file exists $statsdir] || ![file isdirectory $statsdir]} {
			variable starterror "Directory $statsdir is not found!"
			return 1
		} else {
			putlog "$version - $statsdir exists and is a directory... OK."
		}
		if {![file exists $statslogdir] || ![file isdirectory $statslogdir]} {
			variable starterror "Directory $statslogdir is not found!"
			return 1
		} else {
			putlog "$version - $statslogdir exists and is a directory... OK."
		}
		if {[validuser $staticlogkeeper]} {
			variable starterror "$staticlogkeeper is not a user on this bot (handle not found)"
			return 1
		}
		if {[lsearch [string tolower [userlist b]] [string tolower $staticlogkeeper]] != -1} {
			variable starterror "$staticlogkeeper is registered as a bot!"
			return 1
		}
		putlog "$version - $staticlogkeeper is a valid user on this bot... OK."
		return 0
	}
		
	
	proc dcc {handle idx args} {
		set args [split [lindex $args 0]]
		variable actives
		foreach v $actives {variable $v}
		if {![item find keep $handle]} {
			putlog "#$handle# mel $args"
			putidx $idx "$version - You are not allowed to perform maintenance."
			putidx $idx "$version - Contact $staticlogkeeper for more information."
			return 0
		}
		switch -- [lindex [split $args] 0] {
			on {
				putlog "#$handle# mel on"
				if {![array exists channels]} {
					putidx $idx "$version - You should add channels before turning mEL on!"
					return 0
				}
				if {$enabled == 1} {
					putidx $idx "$version - mEL already is on. Try \'.mel status\' for a status overview"
					return 0
				}
				variable enabled 1
				putidx $idx "$version - mEL is now turned on!"
				return 0
			}
			off {
				putlog "#$handle# mel off"
				if {$enabled == 0} {
					putidx $idx "$version - mEL already is off!"
					return 0
				}
				variable enabled 0
				putidx $idx "$version - mEL is now turned off!"
				return 0
			}
			rotation {
				putlog "#$handle# mel rotation"
				if {$enabled == 0} {
					putidx $idx "$version - mEL is disabled. Unable to change rotation settings."
					return 0
				}
				switch -- [lindex $args 1] {
					mac {
						if {$macmode == 0} {
							putlog "$version - Switching to mAC mode..."
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							putlog "$version - Event timers removed..."
							switchlogs
							putlog "$version - Created new logfiles for all channels..."
							variable macmode 1
							variable rotate mac
							arraywrite
							putidx $idx "$version - Now running in mAC mode"
						} else {
							putidx $idx "$version - Already running in mAC mode"
							return 0
						}
					}
					week {
						if {$rotate == "week"} {
							putidx $idx "$version - Already rotating every week"
							return 0
						}
						if {$macmode == 0} {
							variable rotate week
							set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
							variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
							arraywrite
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							if {[string length [expr [lindex $t 3] -1]] == 1} {
								set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
							} else {
								set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
							}
							bind time - $tt ::mel::timer
							putidx $idx "$version - Now rotating logfiles every week"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate week
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
					month {
						if {$rotate == "month"} {
							putidx $idx "$version - Already rotating every month"
							return 0
						}
						if {$macmode == 0} {
							variable rotate month
							set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
							variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
							arraywrite
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							if {[string length [expr [lindex $t 3] -1]] == 1} {
								set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
							} else {
								set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
							}
							bind time - $tt ::mel::timer
							putidx $idx "$version - Now rotating logfiles every month"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate month
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
					year {
						if {$rotate == "year"} {
							putidx $idx "$version - Already rotating every year"
							return 0
						}
						if {$macmode == 0} {
							variable rotate year
							set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
							variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
							arraywrite
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							if {[string length [expr [lindex $t 3] -1]] == 1} {
								set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
							} else {
								set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
							}
							bind time - $tt ::mel::timer
							putidx $idx "$version - Now rotating logfiles every year"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate year
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
					default {
						if {$macmode == 0} {
							if {[string is integer -strict [lindex $args 1]]} {
								if {[expr [lindex $args 1] < 1]} {
									putidx $idx "$version - Invalid argument, expecting integer greater than zero"
									return 0
								}
								variable rotate [lindex $args 1]
								set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
								variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
								arraywrite
								foreach search [binds time] {
									if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
										unbind time - "[lindex $search 2]" ::mel::timer
									}
								}
								if {[string length [expr [lindex $t 3] -1]] == 1} {
									set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
								} else {
									set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
								}
								bind time - $tt ::mel::timer
								putidx $idx "$version - Now rotating logfiles every [lindex $args 1] days"
								return 0
							}
							putidx $idx "$version - Invalid argument, expecting integer"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate [lindex $args 1]
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
				}
			}
			status {
				putlog "#$handle# mel status"
				if {[lindex $args 1] == "all"} {
					showstatus [::hand2idx $handle] all
				} else {
					showstatus [::hand2idx $handle] norm
				}
			}
			+chan {
				set whatchan [lindex $args 1]
				if {$whatchan != ""} {
					putlog "#$handle# mel +chan"
					if {[string index $whatchan 0] != "#"} {set whatchan "#$whatchan"}
					if {[item find chan $whatchan]} {
						putidx $idx "$version - $whatchan is already being logged"
						return 0
					}
					set cflag 0
					foreach c [::channels] {
						if {[string compare -nocase $whatchan $c] == 0} {set cflag 1}
					}
					if {$cflag == 0} {
						putidx $idx "$version - Can't add $whatchan - I am not on that channel"
						return 0
					}
					variable enabled 1
					if {![info exists nextswitch]} {
						variable nextswitch 0
					}
					variable skipmac 1
					item add chan $whatchan
					variable skipmac 0
					putidx $idx "$version - Now logging channel $whatchan"
					return 0
				}
				putidx $idx "$version - You forgot to include a channel!"
				return 0
			}
			-chan {
				set whatchan [lindex [split $args] 1]
				if {$whatchan != ""} {
					putlog "#$handle# mel -chan"
					if {[string index $whatchan 0] != "#"} {set whatchan "#$whatchan"}
					if {![array exists channels]} {
						putidx $idx "$version - Can't remove any channel because no channels have been added yet!"
						return 0
					}
					if {![item find chan $whatchan]} {
						putidx $idx "$version - Can't remove channel $whatchan because channel hasn't been added yet!"
						return 0
					}
					item del chan $whatchan
					putidx $idx "$version - No longer logging channel $whatchan"
					putidx $idx "$version - Use \'.mel erase\' to remove the logfiles for channel $whatchan"
					return 0
				}
				putidx $idx "$version - You forgot to include a channel!"
				return 0
			}
			+keep {
				set who [lindex [split $args] 1]
				if {$who != ""} {
					putlog "#$handle# mel +keep"
					if {[string compare -nocase $handle $staticlogkeeper] != 0} {
						putidx $idx "$version - You can't add or remove logkeepers"
						return 0
					}
					if {![::validuser $who]} {
						putidx $idx "$version - $who is not a valid user on this bot"
						return 0
					}
					if {[item find keep $who]} {
						putidx $idx "$version - $who already is a logkeeper"
						return 0
					}
					item add keep $who
					putidx $idx "$version - $who has been added as a logkeeper"
					return 0
				}
				putidx $idx "$version - You forgot to specify a username!"
				return 0
			}
			-keep {
				set who [lindex [split $args] 1]
				if {$who != ""} {
					putlog "#$handle# mel -keep"
					if {[string compare -nocase $handle $staticlogkeeper] != 0} {
						putidx $idx "$version - You can't add or remove logkeepers"
						return 0
					}
					if {[string compare -nocase $who $staticlogkeeper] == 0} {
						putidx $idx "$version - You can't remove the static logkeeper from the partyline"
						return 0
					}
					if {![item find keep $who]} {
						putidx $idx "$version - $who is not registeren as a logkeeper"
						return 0
					}
					item del keep $who
					putidx $idx "$version - $who has been removed as a logkeeper"
					return 0
				}
				putidx $idx "$version - You forgot to specify a username!"
				return 0
			}
			erase {
				putlog "#$handle# mel erase"
				logfile kill [::hand2idx $handle]
				return 0
			}
			default {
				putidx $idx "\002Usage:\002 .mel <on/off/rotation/status/+chan/-chan/+keep/-keep/erase>"
				putidx $idx "For more details refer to the helpfile or type \'.help mel\'"
				return 0
			}
		}
	}

	proc justify {args} {
		if {![info exists ::spacer]} {set spc " "} else {set spc [string index $::spacer 0]}
		set msg [lindex $args 1]
		set width [lindex $args end]
		switch -- [lindex $args 0] {
			l {
				if {$width <= [string length $msg]} {return $msg}
				return [string replace [string repeat $spc $width] 0 [expr [string length $msg] -1] $msg]
			}
			r {
				if {$width <= [string length $msg]} {return $msg}
				return [string replace [string repeat $spc $width] [expr $width - [string length $msg]] end $msg]
			}
			c {
				set startat [expr [expr $width/2] - [expr [string length $msg]/2]]
				set lastchar [expr $startat + [expr [string length $msg] -1]]
				if {$startat<=0} {return $msg}
				return [string replace [string repeat $spc $width] $startat $lastchar $msg]
			}
			lr {
				set msg1 $msg
				set msg2 [lindex $args 2]
				if {$width <= [expr [string length $msg1] + [string length $msg2]]} {return "$msg1$msg2"}
				return [string replace [string replace [string repeat $spc $width] 0 [expr [string length $msg1] -1] $msg1] [expr $width - [string length $msg2]] end $msg2]
			}
		}
	}
	
	proc showstatus {idx mode} {
		variable actives
		foreach v $actives {variable $v}
		set fline "+[string repeat - 58]+"
		putidx $idx $fline
		putidx $idx "|[justify c "$version Status Overview" 58]|"
		putidx $idx $fline
		putidx $idx "|[justify l " Today is \002[clock format [clock scan now] -format %c]\002" 60]|"
		if {$mode == "all"} {
			if {$enabled == 1} {set st "\002enabled\002"} else {set st "\002disabled\002"}
			putidx $idx "|[justify l " mEL is currently $st" 60]|"
			if {$bhosts == 1} {set st "\002enabled\002"} else {set st "\002disabled\002"}
			putidx $idx "|[justify l " Host blocking is $st" 60]|"
			if {$macmode == 1} {set st "\002enabled\002"} else {set st "\002disabled\002"}
			putidx $idx "|[justify l " mAC mode is currently $st" 60]|"
			
		}
		putidx $idx $fline
		if {[array size channels] > 0} {
			putidx $idx "|[justify l " Currently logging the following channels:" 58]|"
			foreach c [lsort [array names channels]] {
				putidx $idx "|[justify l "  \002$channels($c)\002" 60]|"
			}
			putidx $idx $fline
		} else {
			putidx $idx "|[justify l " Currently no channels are being logged" 58]|"
			putidx $idx $fline
		}
		if {$mode == "all"} {
			putidx $idx "|[justify l " Current logkeepers:" 58]|"
			putidx $idx "|[justify l "  \002$staticlogkeeper\002 (static)" 60]|"
			if {[array size keepers] > 0} {
				foreach k [lsort [array names keepers]] {
					putidx $idx "|[justify l "  \002$keepers($k)\002" 60]|"
				}
			}
			putidx $idx $fline
		}
		if {$macmode == 0} {
			if {[string is integer $rotate]} {
				putidx $idx "|[justify l " Logfiles will rotate every \002$rotate day(s)\002" 60]|"
			} else {
				putidx $idx "|[justify l " Logfiles will rotate every \002$rotate\002" 60]|"
			}
			putidx $idx $fline
			putidx $idx "|[justify l " Next logfile rotation will be at:" 58]|"
			putidx $idx "|[justify l " \002[clock format $nextswitch -format %c]\002" 60]|"
			putidx $idx $fline
		}
		if {$mode == "all"} {
			if {[file pathtype $statsdir] == "relative" } {
				putidx $idx "|[justify l " Storing settings in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename [pwd]/$statsdir]\002" 60]|"
			} else {
				putidx $idx "|[justify l " Storing settings in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename $statsdir]\002" 60]|"
			}
			if {[file pathtype $statslogdir] == "relative" } {
				putidx $idx "|[justify l " Storing logfiles in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename [pwd]/$statslogdir]\002" 60]|"
			} else {
				putidx $idx "|[justify l " Storing logfiles in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename $statslogdir]\002" 60]|"
			}
			putidx $idx $fline
		}
	}
	
	proc logfile {action chan} {
		variable actives
		foreach v $actives {variable $v}
		switch -- $action {
			create {
				set starttime [clock format [clock scan now] -format "%a %b %d %T %Y"]
				set time_current [clock format [clock scan now] -format "%H:%M"]
				if {[expr $unixnames < 1]} {
					set curFilename [string tolower ${chan}.log]
				} else {
					set curFilename [string tolower [string range $chan 1 end].log]
				}
				if {![item find chan $chan]} {
					putlog "$version - Unable to create logfile for channel not in array! Channel: $chan"
					return 0
				}
				if {![file exists [file join $statslogdir $curFilename]]} {
					variable skipmac 1
					writelog sesdata 0 1 2 $chan "Session Start: $starttime"
					writelog sesdata 0 1 2 $chan "\[$time_current\] *** Now talking in $chan"
					variable skipmac 0
					putlog "$version - Created logfile for $chan"
				} else {
					putlog "$version - Can't create logfile for channel $chan - Appending to existing logfile"
					return 0
				}
				return 0
			}
			close {
				set stoptime [clock format [clock scan now] -format "%a %b %d %T %Y"]
				if {[expr $unixnames < 1]} {
					set curFilename [string tolower ${chan}.log]
				} else {
					set curFilename [string tolower [string range $chan 1 end].log]
				}
				if {![item find chan $chan]} {
					putlog "$version - Cannot close logfile for $chan. Channel not in array!"
					return 0
				}
				putlog "$version - Channel $chan has logfile [file join $statslogdir $curFilename]"
				if {![file exists [file join $statslogdir $curFilename]]} {
					putlog "$version - Cannot close logfile for $chan. File does not exist!"
					return 0
				}
				writelog sesdata 0 1 2 $chan "Session Close: $stoptime"
				putlog "$version - Closed logfile for $chan"
				return 0
			}
			kill {
				set handle $chan
				set dffile [file join $statsdir $deadchanfile]
				if {![file exists $dffile]} {
					putidx $handle "All redundant logfiles already removed!"
					return 0
				}
				putidx $handle "Deleting redundant logfiles..."
				set read_dead [open $dffile r]
				while {![eof $read_dead]} {
					set data [gets $read_dead]
					if {[eof $read_dead]} {break}
					if {[expr $unixnames < 1]} {
						set curFilename [string tolower $data].log"
					} else {
						set curFilename [string tolower [string range $data 1 end]]
					}
					foreach dead_chan [glob -nocomplain [file join $statslogdir $curFilename]*] {
						file delete -force $dead_chan
						if {[file pathtype $dead_chan] == "relative"} {putidx $handle "Deleted [pwd]/$dead_chan..."} else {putidx $handle "Deleted $dead_chan..."}
					}
				}
				close $read_dead
				file delete -force $dffile
				putidx $handle "\nFinished deleting redundant logfiles..."
				return 0
			}
			datestamp {
				set starttime [clock format [clock scan now] -format "%a %b %d %T %Y"]
				if {![array exists channels] || [array size channels] < 1} {
					putlog "$version - No channels defined. Use +chan first. Unable to add datestamp in logfile."
					variable enabled 0
					return 0
				}
				foreach c [lsort [array names channels]] {
					writelog sesdata 0 1 2 $channels($c) "Session Time: $starttime"
				}
				return 0
			}
		}
	}

	proc switchlogs {} {
		variable actives
		foreach v $actives {variable $v}
		if {$enabled == 0} {return 0}
		foreach c [lsort [array names channels]] {
			set curChan $channels($c)
			logfile close $curChan
			if {[expr $unixnames < 1]} {
				set curFilename [string tolower $curChan]
			} else {
				set curFilename [string tolower [string range $curChan 1 end]]
			}
			if {$dodatestamp == 1} {
				if {$doyearstamp == 0} {
					set date [clock format [clock scan "now yesterday"] -format %m.%d.%Y]
				} else {
					set date [clock format [clock scan "now yesterday"] -format %Y]
				}
				file rename -force [file join $statslogdir $curFilename].log [file join $statslogdir $curFilename].${date}.log
			} else {
				file rename -force [file join $statslogdir $curFilename].log [file join $statslogdir $curFilename].bak
			}
			logfile create $curChan
		}
		if {$notify == 1} {
			sendnote mEL $staticlogkeeper "$version - Logfiles have rotated at [clock format [clock scan now] -format %c]"
		}
	}
	
	proc checktimer {} {
		variable actives
		foreach v $actives {variable $v}
		if {$nextswitch == ""} {
			putlog "$version - No rotation date found - Binding new timer (logfile switcher)"
			switch -- $rotate {
				week {
					set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
				month {
					set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
				}
				year {
					set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
					variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
				}
				default {
					set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
			}
			if {[string length [expr [lindex $t 3] -1]] == 1} {
				set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
			} else {
				set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
			}
			bind time - $tt ::mel::timer
			arraywrite
			return 0
		}
		if {[expr [clock scan now] > $nextswitch]} {
			putlog "$version - Missed a switch at [clock format $nextswitch -format %c]... switching now"
			switchlogs
			switch -- $rotate {
				week {
					set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
				month {
					set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
				}
				year {
					set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
					variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
				}
				default {
					set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
			}
			arraywrite
		}
		set t [clock format $nextswitch -format "00 00 %d %m %Y"]
		if {[string length [expr [lindex $t 3] -1]] == 1} {
			set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
		} else {
			set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
		}
		bind time - $tt ::mel::timer
		return 0			
	}
	
	proc checkstamptimer {} {
		variable actives
		foreach v $actives {variable $v}
		switch -- $stamplogs {
			0 { 
				foreach search [binds time] {
					if {[string compare [lindex $search 4] "::mel::stamptimer"] == 0} {
						unbind time - "[lindex $search 2]" ::mel::stamptimer
					}
				}
				return 0
			}
			1 {
				set t [clock format [clock scan "now next day"] -format "00 00 %d %m %Y"]
				variable stampat [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
			2 {
				set t [clock format [clock scan "now next monday"] -format "00 00 %d %m %Y"]
				variable stampat [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
			3 {
				set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
				variable stampat [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
			}
		}
		set t [clock format $stampat -format "00 00 %d %m %Y"]
		if {[string length [expr [lindex $t 3] -1]] == 1} {
			set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
		} else {
			set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
		}
		bind time - $tt ::mel::stamptimer
		return 0
	}
			
	proc stamptimer {min hour day month year} {
		variable actives
		foreach v $actives {variable $v}
		logfile datestamp all
		foreach search [binds time] {
			if {[string compare [lindex $search 4] "::mel::stamptimer"] == 0} {
				unbind time - "[lindex $search 2]" ::mel::stamptimer
			}
		}
		if {$enabled == 0} {
			putlog "$version - mEL is disabled - Not binding timed event (log datestamping)"
			return 0
		}
		checkstamptimer
		return 0
	}
	
	proc timer {min hour day month year} {
		variable actives
		foreach v $actives {variable $v}
		if {$enabled == 0} {return 0}
		switchlogs
		foreach search [binds time] {
			if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
				unbind time - "[lindex $search 2]" ::mel::timer
			}
		}
		if {$enabled == 0} {
			putlog "$version - mEL is disabled - Not binding timed event (logfile switching)"
			return 0
		}
		switch -- $rotate {
			week {
				set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
				variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
			month {
				set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
				variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
			}
			year {
				set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
				variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
			}
			default {
				set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
				variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
		}
		arraywrite
		set t [clock format $nextswitch -format "00 00 %d %m %Y"]
		if {[string length [expr [lindex $t 3] -1]] == 1} {
			set tt [lreplace $t 3 3 0[expr [lindex $t 3] -1]]
		} else {
			set tt [lreplace $t 3 3 [expr [lindex $t 3] -1]]
		}
		bind time - $tt ::mel::timer
		putlog "$version - Next switch will occur at [clock format $nextswitch -format %c]"
		return 0
	}


	
	proc arrayinit {} {
		variable actives
		foreach v $actives {variable $v}
		if {![file exists [file join $statsdir $settings]]} {
			variable enabled 0
			return 1
		}
		set readsettings [open [file join $statsdir $settings] r]
		set datatype 0
		while {![eof $readsettings]} {
			set data [gets $readsettings]
			if {[eof $readsettings]} {break}
			if {[string index [lindex $data 0] 0] == "\["} {
				regsub -all {[\[\]]} $data {} type
				switch -- $type {
					channels { set datatype 1 }
					keepers { set datatype 2 }
					rotation { set datatype 3 }
					switch { set datatype 4 }
					EOF { break }
				}
				continue
			}
			switch -- $datatype {
				0 { continue }
				1 { lappend allchans $data ; continue }
				2 { lappend allkeeps $data ; continue }
				3 { set tmac $data ; continue }
				4 { set swdate $data ; continue }
			}
		}
		close $readsettings
		array unset channels
		if {[info exists allchans]} {
			set cnt 0
			foreach c $allchans {
				set channels($cnt) $c
				incr cnt
			}
			variable enabled 1
		} else {
			variable enabled 0
			return 0
		}
		array unset keepers
		if {[info exists allkeeps]} {
			set cnt 0
			foreach k $allkeeps {
				set keepers($cnt) $k
				incr cnt
			}
		}
		switch -- $tmac {
			mac {
				variable macmode 1
			}
			week {
				variable macmode 0
				variable rotate week
			}
			month {
				variable macmode 0
				variable rotate month
			}
			year {
				variable macmode 0
				variable rotate year
			}
			default {
				variable macmode 0
				variable rotate $tmac
			}
		}
		variable nextswitch $swdate
		return 0
	}
	
	proc arraywrite {} {
		variable actives
		foreach v $actives {variable $v}
		if {[file exists [file join $statsdir $settings]]} {
			file rename -force [file join $statsdir $settings] [file join $statsdir $settings].old
		}
		set writesettings [open [file join $statsdir $settings] w]
		puts $writesettings "\[channels\]"
		foreach c [lsort [array names channels]] {
			puts $writesettings $channels($c)
		}
		puts $writesettings "\[keepers\]"
		foreach k [lsort [array names keepers]] {
			puts $writesettings $keepers($k)
		}
		puts $writesettings "\[rotation\]"
		puts $writesettings $rotate
		puts $writesettings "\[switch\]"
		puts $writesettings $nextswitch
		puts $writesettings "\[EOF\]"
		close $writesettings
	}
	
	proc item {action type item} {
		variable actives
		foreach v $actives {variable $v}
		switch -- $action {
			find {
				switch -- $type {
					chan {
						if {[array exists channels]} {
							foreach c [array names channels] {
								if {[string compare -nocase $channels($c) $item] == 0} {
									return 1
								}
							}
						}
						return 0
					}
					keep {
						if {[string compare -nocase $item $staticlogkeeper] == 0} {
							return 1
						}
						if {[array exists keepers]} {
							foreach k [array names keepers] {
								if {[string compare -nocase $keepers($k) $item] == 0} {
									return 1
								}
							}
						}
						return 0
					}
				}
			}
			add {
				switch -- $type {
					chan {
						if {![array exists channels]} {
							set channels(0) $item
						} else {
							set channels([expr [array size channels] + 1]) $item
						}
						logfile create $item
						if {[file exists [file join $statsdir $deadchanfile]]} {
							set read [open [file join $statsdir $deadchanfile] r]
							while {![eof $read]} {
								set data [gets $read]
								if {[eof $read]} {break}
								if {[string compare -nocase $item $data] != 0} {
									set write [open [file join $statsdir $deadchanfile].tmp a]
									puts $write $data
									close $write
								}
							}
							close $read
							if {[file exists [file join $statsdir $deadchanfile].tmp]} {
								file rename -force [file join $statsdir $deadchanfile].tmp [file join $statsdir $deadchanfile]
							} else {
								file delete -force [file join $statsdir $deadchanfile]
							}
						}
						arraywrite
					}
					keep {
						if {![array exists keepers]} {
							set keepers(0) $item
						} else {
							set keepers([expr [array size keepers] + 1]) $item
						}
						arraywrite
					}
				}
			}
			del {
				switch -- $type {
					chan {
						foreach c [array names channels] {
							if {[string compare -nocase $channels($c) $item] == 0} {
								logfile close $item
								unset channels($c)
								set add_dead [open [file join $statsdir $deadchanfile] a]
								puts $add_dead $item
								close $add_dead
								if {[array names channels] == ""} {
									variable enabled 0
									foreach search [binds time] {
										if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
											unbind time - "[lindex $search 2]" ::mel::timer
										}
									}
									putlog "$version - No channels are being logged. mEL turned off, existing time bindings removed."
								}
								arraywrite
							}
						}
					}
					keep {
						foreach k [array names keepers] {
							if {[string compare -nocase $keepers($k) $item] == 0} {
								unset keepers($k)
								arraywrite
							}
						}
					}
				}
			}
		}
	}
	
	proc strip {args} {
		regsub -all -- {((\002|\026|\037|\017|\022)|(\003([0-9]{1,2}(,[0-9]{1,2})?)?))} $args "" args
		foreach char [split $args {}] {
			if {[string is graph $char] || $char == " "} {
				append printable $char
			}
		}
		return $printable
	}
	
	proc writelog {args} {
		variable actives
		foreach v $actives {variable $v}
		if {$enabled == 0} {return 0}
		if {$bhosts == 1 && [isignore [lindex $args 2]]} {return 0}
		set curTime [clock format [clock scan now] -format "%H:%M"]
		set curChannel [string tolower [lindex $args 4]]
		if {![item find chan $curChannel]} { return 0 }
		if {[expr $unixnames < 1]} {
			set curFilename ${curChannel}.log
		} else {
			set curFilename [string range $curChannel 1 end].log
		}
		if {$skipmac == 0} {
			if {$macmode == 1 && ![file exists [file join $statslogdir $curFilename]]} {
				logfile create $curChannel
			}
		}
		switch -- [lindex $args 0] {
			chat {
				if {[lsearch -exact [string tolower $ignorenicks] [string tolower [lindex $args 1]]] == -1} {
					set addline "\[$curTime\] <[lindex $args 1]> [join [strip [lindex $args 5]]]"
				} else {
					return 0
				}
			}
			join {set addline "\[$curTime\] *** [lindex $args 1] ([lindex $args 2]) has joined $curChannel"}
			quit {set addline "\[$curTime\] *** [lindex $args 1] has quit IRC ([join [strip [lindex $args 5]]])"}
			topic {
				if {[lindex $args 1] == "*"} {return}
				set addline "\[$curTime\] *** [lindex $args 1] changes topic to '[join [strip [lindex $args 5]]]'"
			}
			kick {set addline "\[$curTime\] *** [lindex $args 5] was kicked by [lindex $args 1] ([lindex $args 6])"}
			nick {set addline "\[$curTime\] *** [lindex $args 1] is now known as [lindex $args 5]"}
			mode {set addline "\[$curTime\] *** [lindex $args 1] sets mode: [lindex $args 5] [lindex $args 6]"}
			part {set addline "\[$curTime\] *** [lindex $args 1] ([lindex $args 2]) has left [lindex $args 4] ([lindex $args 5])"}
			action {
				if {[lsearch -exact [string tolower $ignorenicks] [string tolower [lindex $args 1]]] == -1} {
					set addline "\[$curTime\] * [lindex $args 1] [join [strip [lindex $args 5]]]"
				} else {
					return 0
				}
			}
			sesdata {set addline [lindex $args 5]}
		}
		set writeout [open [file join $statslogdir $curFilename] a]
		puts $writeout $addline
		close $writeout
	}
	
	proc chatter {nick host handle channel text} {writelog chat $nick $host $handle $channel $text}
	proc enter {nick host handle channel} {writelog join $nick $host $handle $channel}
	proc signoff {nick host handle channel partmsg} {writelog quit $nick $host $handle $channel $partmsg}
	proc ctopic {nick host handle channel topic} {writelog topic $nick $host $handle $channel $topic}
	proc kicked {nick host handle channel target reason} {writelog kick $nick $host $handle $channel $target $reason}
	proc nickchange {nick host handle channel newnick} {writelog nick $nick $host $handle $channel $newnick}
	proc cmode {nick host handle channel change victim} {writelog mode $nick $host $handle $channel $change $victim}
	proc parting {nick host handle channel partmsg} {writelog part $nick $host $handle $channel $partmsg}
	proc action {nick host handle destination keyword arg} {writelog action $nick $host $handle $destination $arg}
	
}
putlog "Initializing $::mel::version...."
putlog "$::mel::version - Running startup tests..."
if {[::mel::starttests]} {
	putlog $::mel::starterror
	die "Fatal error - Can not continue"
} else {
	::mel::arrayinit
	::mel::logfile datestamp all
	if {$::mel::macmode == 0 && $::mel::enabled == 1} {
		::mel::checktimer
	}
	::mel::checkstamptimer
	loadhelp mel.help
	putlog "$::mel::version successfully initialized..."
}

### http://mel.sourceforge.net
### Feel free to alter this tcl to your personal flavour... just don't forget who wrote the
### original code... Also, if you find bugs, or even fix some.. then please let me know!
m
marvz
Halfop
Posts: 64
Joined: Fri Jun 18, 2010 2:37 pm

Post by marvz »

Try this

Code: Select all

#### mIRCStats Eggdrop Logger 2.0
#### (c)1999-2004 Jules <mel@angelbears.org>
#### Multiple Channel Support by SirSir <sirsir@thuntek.net>
#### Unix/Linux Support by T_D <todd6971@msn.com> #cracks2000@EFNet
####
#### This tcl creates mIRC-style channel logfiles for use with the popular
#### mIRCStats <http://www.mircstats.com> program.
#### This script is written for Tcl 8.1 or higher and Eggdrop 1.6.0 or higher.
#### Running this script on any lower version of Tcl or Eggdrop will cause your
#### eggdrop to die.
####
#### For version history see history.txt


#### Change your settings below ####

#### Check readme.txt for explanation of these settings

namespace eval mel {
   
   # Location of logfiles
   variable statslogdir mel/logs
   # Location of configuration files
   variable statsdir mel
   # Static logkeeper
   variable staticlogkeeper storm6699
   # Add datestamp in the log itself at regular intervals (0=never 1=daily 2=weekly 3=monthly)
   variable stamplogs 1
   # Adds datestamp in logfile name
   variable dodatestamp 1
   # Use year (yyyy) instead of date in filename (in case of adding a datestamp)
   variable doyearstamp 1
   # Strips '#' from logfile name
   variable unixnames 1
   # Enable/disable host blocking
   variable bhosts 0
   # Day of week (1 is monday) <- for weekly rotation
   variable weekly 1
   # Notify static logkeeper on logfile rotation?
   variable notify 1
   
   # Ignore nicknames
   variable ignorenicks {
      botnick
      bot2nick
      bot3nick
      ChanServ
   }
}   


# # # # # # # # # # # # DO NOT CHANGE ANYTHING BELOW HERE # # # # # # # # # # #

bind dcc * mel ::mel::dcc
bind pubm - * ::mel::chatter
bind join - * ::mel::enter
bind sign - * ::mel::signoff
bind topc - * ::mel::ctopic
bind kick - * ::mel::kicked
bind nick - * ::mel::nickchange
bind mode - * ::mel::cmode
bind part - * ::mel::parting
bind ctcp - "ACTION" ::mel::action

namespace eval mel {
	
	variable settings settings.mel
	variable enabled 0
	variable version "mEL 2.0"
	variable channels
	variable macmode 1
	variable rotate week
	variable keepers
	variable deadchanfile deadchans.mel
	variable nextswitch
	variable weekdays
	variable skipmac 0
	array set weekdays {
		1	monday
		2	tuesday
		3	wednesday
		4	thursday
		5	friday
		6	saturday
		7	sunday
	}

	variable actives [list statslogdir statsdir settings staticlogkeeper stamplogs dodatestamp doyearstamp skipmac macmode rotate weekdays weekly nextswitch unixnames enabled version channels keepers deadchanfile bhosts notify ignorenicks]
	
	proc starttests {} {
		variable actives
		variable starterror
		foreach v $actives {variable $v}
		if {$::tcl_version >= "8.1"} {
			putlog "$version - Tcl version $::tcl_version detected... OK."
		} else {
			variable starterror "Tcl version $::tcl_version detected... FAILED! I need at least Tcl 8.1 to function properly."
			return 1
		}
		if {[string range $::numversion 0 2] >= 106} {
			putlog "$version - Eggdrop version [lindex $::version 0] detected... OK."
		} else {
			variable starterror "Eggdrop version [lindex $::version 0] detected... FAILED! I need at least Eggdrop 1.6.0 to function properly."
			return 1
		}
		if {![file exists $statsdir] || ![file isdirectory $statsdir]} {
			variable starterror "Directory $statsdir is not found!"
			return 1
		} else {
			putlog "$version - $statsdir exists and is a directory... OK."
		}
		if {![file exists $statslogdir] || ![file isdirectory $statslogdir]} {
			variable starterror "Directory $statslogdir is not found!"
			return 1
		} else {
			putlog "$version - $statslogdir exists and is a directory... OK."
		}
		if {[validuser $staticlogkeeper]} {
			variable starterror "$staticlogkeeper is not a user on this bot (handle not found)"
			return 1
		}
		if {[lsearch [string tolower [userlist b]] [string tolower $staticlogkeeper]] != -1} {
			variable starterror "$staticlogkeeper is registered as a bot!"
			return 1
		}
		putlog "$version - $staticlogkeeper is a valid user on this bot... OK."
		return 0
	}
		
	
	proc dcc {handle idx args} {
		set args [split [lindex $args 0]]
		variable actives
		foreach v $actives {variable $v}
		if {![item find keep $handle]} {
			putlog "#$handle# mel $args"
			putidx $idx "$version - You are not allowed to perform maintenance."
			putidx $idx "$version - Contact $staticlogkeeper for more information."
			return 0
		}
		switch -- [lindex [split $args] 0] {
			on {
				putlog "#$handle# mel on"
				if {![array exists channels]} {
					putidx $idx "$version - You should add channels before turning mEL on!"
					return 0
				}
				if {$enabled == 1} {
					putidx $idx "$version - mEL already is on. Try \'.mel status\' for a status overview"
					return 0
				}
				variable enabled 1
				putidx $idx "$version - mEL is now turned on!"
				return 0
			}
			off {
				putlog "#$handle# mel off"
				if {$enabled == 0} {
					putidx $idx "$version - mEL already is off!"
					return 0
				}
				variable enabled 0
				putidx $idx "$version - mEL is now turned off!"
				return 0
			}
			rotation {
				putlog "#$handle# mel rotation"
				if {$enabled == 0} {
					putidx $idx "$version - mEL is disabled. Unable to change rotation settings."
					return 0
				}
				switch -- [lindex $args 1] {
					mac {
						if {$macmode == 0} {
							putlog "$version - Switching to mAC mode..."
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							putlog "$version - Event timers removed..."
							switchlogs
							putlog "$version - Created new logfiles for all channels..."
							variable macmode 1
							variable rotate mac
							arraywrite
							putidx $idx "$version - Now running in mAC mode"
						} else {
							putidx $idx "$version - Already running in mAC mode"
							return 0
						}
					}
					week {
						if {$rotate == "week"} {
							putidx $idx "$version - Already rotating every week"
							return 0
						}
						if {$macmode == 0} {
							variable rotate week
							set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
							variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
							arraywrite
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
								set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
							} else {
								set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
							}
							bind time - $tt ::mel::timer
							putidx $idx "$version - Now rotating logfiles every week"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate week
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
					month {
						if {$rotate == "month"} {
							putidx $idx "$version - Already rotating every month"
							return 0
						}
						if {$macmode == 0} {
							variable rotate month
							set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
							variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
							arraywrite
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
								set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
							} else {
								set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
							}
							bind time - $tt ::mel::timer
							putidx $idx "$version - Now rotating logfiles every month"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate month
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
					year {
						if {$rotate == "year"} {
							putidx $idx "$version - Already rotating every year"
							return 0
						}
						if {$macmode == 0} {
							variable rotate year
							set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
							variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
							arraywrite
							foreach search [binds time] {
								if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
									unbind time - "[lindex $search 2]" ::mel::timer
								}
							}
							if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
								set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
							} else {
								set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
							}
							bind time - $tt ::mel::timer
							putidx $idx "$version - Now rotating logfiles every year"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate year
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
					default {
						if {$macmode == 0} {
							if {[string is integer -strict [lindex $args 1]]} {
								if {[expr [lindex $args 1] < 1]} {
									putidx $idx "$version - Invalid argument, expecting integer greater than zero"
									return 0
								}
								variable rotate [lindex $args 1]
								set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
								variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
								arraywrite
								foreach search [binds time] {
									if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
										unbind time - "[lindex $search 2]" ::mel::timer
									}
								}
								if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
									set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
								} else {
									set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
								}
								bind time - $tt ::mel::timer
								putidx $idx "$version - Now rotating logfiles every [lindex $args 1] days"
								return 0
							}
							putidx $idx "$version - Invalid argument, expecting integer"
							return 0
						}
						putlog "$version - Disabling mAC mode..."
						variable macmode 0
						variable rotate [lindex $args 1]
						variable nextswitch {}
						checktimer
						switchlogs
						putlog "$version - mAC mode disabled"
						return 0
					}
				}
			}
			status {
				putlog "#$handle# mel status"
				if {[lindex $args 1] == "all"} {
					showstatus [::hand2idx $handle] all
				} else {
					showstatus [::hand2idx $handle] norm
				}
			}
			+chan {
				set whatchan [lindex $args 1]
				if {$whatchan != ""} {
					putlog "#$handle# mel +chan"
					if {[string index $whatchan 0] != "#"} {set whatchan "#$whatchan"}
					if {[item find chan $whatchan]} {
						putidx $idx "$version - $whatchan is already being logged"
						return 0
					}
					set cflag 0
					foreach c [::channels] {
						if {[string compare -nocase $whatchan $c] == 0} {set cflag 1}
					}
					if {$cflag == 0} {
						putidx $idx "$version - Can't add $whatchan - I am not on that channel"
						return 0
					}
					variable enabled 1
					if {![info exists nextswitch]} {
						variable nextswitch 0
					}
					variable skipmac 1
					item add chan $whatchan
					variable skipmac 0
					putidx $idx "$version - Now logging channel $whatchan"
					return 0
				}
				putidx $idx "$version - You forgot to include a channel!"
				return 0
			}
			-chan {
				set whatchan [lindex [split $args] 1]
				if {$whatchan != ""} {
					putlog "#$handle# mel -chan"
					if {[string index $whatchan 0] != "#"} {set whatchan "#$whatchan"}
					if {![array exists channels]} {
						putidx $idx "$version - Can't remove any channel because no channels have been added yet!"
						return 0
					}
					if {![item find chan $whatchan]} {
						putidx $idx "$version - Can't remove channel $whatchan because channel hasn't been added yet!"
						return 0
					}
					item del chan $whatchan
					putidx $idx "$version - No longer logging channel $whatchan"
					putidx $idx "$version - Use \'.mel erase\' to remove the logfiles for channel $whatchan"
					return 0
				}
				putidx $idx "$version - You forgot to include a channel!"
				return 0
			}
			+keep {
				set who [lindex [split $args] 1]
				if {$who != ""} {
					putlog "#$handle# mel +keep"
					if {[string compare -nocase $handle $staticlogkeeper] != 0} {
						putidx $idx "$version - You can't add or remove logkeepers"
						return 0
					}
					if {![::validuser $who]} {
						putidx $idx "$version - $who is not a valid user on this bot"
						return 0
					}
					if {[item find keep $who]} {
						putidx $idx "$version - $who already is a logkeeper"
						return 0
					}
					item add keep $who
					putidx $idx "$version - $who has been added as a logkeeper"
					return 0
				}
				putidx $idx "$version - You forgot to specify a username!"
				return 0
			}
			-keep {
				set who [lindex [split $args] 1]
				if {$who != ""} {
					putlog "#$handle# mel -keep"
					if {[string compare -nocase $handle $staticlogkeeper] != 0} {
						putidx $idx "$version - You can't add or remove logkeepers"
						return 0
					}
					if {[string compare -nocase $who $staticlogkeeper] == 0} {
						putidx $idx "$version - You can't remove the static logkeeper from the partyline"
						return 0
					}
					if {![item find keep $who]} {
						putidx $idx "$version - $who is not registeren as a logkeeper"
						return 0
					}
					item del keep $who
					putidx $idx "$version - $who has been removed as a logkeeper"
					return 0
				}
				putidx $idx "$version - You forgot to specify a username!"
				return 0
			}
			erase {
				putlog "#$handle# mel erase"
				logfile kill [::hand2idx $handle]
				return 0
			}
			default {
				putidx $idx "\002Usage:\002 .mel <on/off/rotation/status/+chan/-chan/+keep/-keep/erase>"
				putidx $idx "For more details refer to the helpfile or type \'.help mel\'"
				return 0
			}
		}
	}

	proc justify {args} {
		if {![info exists ::spacer]} {set spc " "} else {set spc [string index $::spacer 0]}
		set msg [lindex $args 1]
		set width [lindex $args end]
		switch -- [lindex $args 0] {
			l {
				if {$width <= [string length $msg]} {return $msg}
				return [string replace [string repeat $spc $width] 0 [expr [string length $msg] -1] $msg]
			}
			r {
				if {$width <= [string length $msg]} {return $msg}
				return [string replace [string repeat $spc $width] [expr $width - [string length $msg]] end $msg]
			}
			c {
				set startat [expr [expr $width/2] - [expr [string length $msg]/2]]
				set lastchar [expr $startat + [expr [string length $msg] -1]]
				if {$startat<=0} {return $msg}
				return [string replace [string repeat $spc $width] $startat $lastchar $msg]
			}
			lr {
				set msg1 $msg
				set msg2 [lindex $args 2]
				if {$width <= [expr [string length $msg1] + [string length $msg2]]} {return "$msg1$msg2"}
				return [string replace [string replace [string repeat $spc $width] 0 [expr [string length $msg1] -1] $msg1] [expr $width - [string length $msg2]] end $msg2]
			}
		}
	}
	
	proc showstatus {idx mode} {
		variable actives
		foreach v $actives {variable $v}
		set fline "+[string repeat - 58]+"
		putidx $idx $fline
		putidx $idx "|[justify c "$version Status Overview" 58]|"
		putidx $idx $fline
		putidx $idx "|[justify l " Today is \002[clock format [clock scan now] -format %c]\002" 60]|"
		if {$mode == "all"} {
			if {$enabled == 1} {set st "\002enabled\002"} else {set st "\002disabled\002"}
			putidx $idx "|[justify l " mEL is currently $st" 60]|"
			if {$bhosts == 1} {set st "\002enabled\002"} else {set st "\002disabled\002"}
			putidx $idx "|[justify l " Host blocking is $st" 60]|"
			if {$macmode == 1} {set st "\002enabled\002"} else {set st "\002disabled\002"}
			putidx $idx "|[justify l " mAC mode is currently $st" 60]|"
			
		}
		putidx $idx $fline
		if {[array size channels] > 0} {
			putidx $idx "|[justify l " Currently logging the following channels:" 58]|"
			foreach c [lsort [array names channels]] {
				putidx $idx "|[justify l "  \002$channels($c)\002" 60]|"
			}
			putidx $idx $fline
		} else {
			putidx $idx "|[justify l " Currently no channels are being logged" 58]|"
			putidx $idx $fline
		}
		if {$mode == "all"} {
			putidx $idx "|[justify l " Current logkeepers:" 58]|"
			putidx $idx "|[justify l "  \002$staticlogkeeper\002 (static)" 60]|"
			if {[array size keepers] > 0} {
				foreach k [lsort [array names keepers]] {
					putidx $idx "|[justify l "  \002$keepers($k)\002" 60]|"
				}
			}
			putidx $idx $fline
		}
		if {$macmode == 0} {
			if {[string is integer $rotate]} {
				putidx $idx "|[justify l " Logfiles will rotate every \002$rotate day(s)\002" 60]|"
			} else {
				putidx $idx "|[justify l " Logfiles will rotate every \002$rotate\002" 60]|"
			}
			putidx $idx $fline
			putidx $idx "|[justify l " Next logfile rotation will be at:" 58]|"
			putidx $idx "|[justify l " \002[clock format $nextswitch -format %c]\002" 60]|"
			putidx $idx $fline
		}
		if {$mode == "all"} {
			if {[file pathtype $statsdir] == "relative" } {
				putidx $idx "|[justify l " Storing settings in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename [pwd]/$statsdir]\002" 60]|"
			} else {
				putidx $idx "|[justify l " Storing settings in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename $statsdir]\002" 60]|"
			}
			if {[file pathtype $statslogdir] == "relative" } {
				putidx $idx "|[justify l " Storing logfiles in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename [pwd]/$statslogdir]\002" 60]|"
			} else {
				putidx $idx "|[justify l " Storing logfiles in:" 58]|"
				putidx $idx "|[justify l " \002[file nativename $statslogdir]\002" 60]|"
			}
			putidx $idx $fline
		}
	}
	
	proc logfile {action chan} {
		variable actives
		foreach v $actives {variable $v}
		switch -- $action {
			create {
				set starttime [clock format [clock scan now] -format "%a %b %d %T %Y"]
				set time_current [clock format [clock scan now] -format "%H:%M"]
				if {[expr $unixnames < 1]} {
					set curFilename [string tolower ${chan}.log]
				} else {
					set curFilename [string tolower [string range $chan 1 end].log]
				}
				if {![item find chan $chan]} {
					putlog "$version - Unable to create logfile for channel not in array! Channel: $chan"
					return 0
				}
				if {![file exists [file join $statslogdir $curFilename]]} {
					variable skipmac 1
					writelog sesdata 0 1 2 $chan "Session Start: $starttime"
					writelog sesdata 0 1 2 $chan "\[$time_current\] *** Now talking in $chan"
					variable skipmac 0
					putlog "$version - Created logfile for $chan"
				} else {
					putlog "$version - Can't create logfile for channel $chan - Appending to existing logfile"
					return 0
				}
				return 0
			}
			close {
				set stoptime [clock format [clock scan now] -format "%a %b %d %T %Y"]
				if {[expr $unixnames < 1]} {
					set curFilename [string tolower ${chan}.log]
				} else {
					set curFilename [string tolower [string range $chan 1 end].log]
				}
				if {![item find chan $chan]} {
					putlog "$version - Cannot close logfile for $chan. Channel not in array!"
					return 0
				}
				putlog "$version - Channel $chan has logfile [file join $statslogdir $curFilename]"
				if {![file exists [file join $statslogdir $curFilename]]} {
					putlog "$version - Cannot close logfile for $chan. File does not exist!"
					return 0
				}
				writelog sesdata 0 1 2 $chan "Session Close: $stoptime"
				putlog "$version - Closed logfile for $chan"
				return 0
			}
			kill {
				set handle $chan
				set dffile [file join $statsdir $deadchanfile]
				if {![file exists $dffile]} {
					putidx $handle "All redundant logfiles already removed!"
					return 0
				}
				putidx $handle "Deleting redundant logfiles..."
				set read_dead [open $dffile r]
				while {![eof $read_dead]} {
					set data [gets $read_dead]
					if {[eof $read_dead]} {break}
					if {[expr $unixnames < 1]} {
						set curFilename [string tolower $data].log"
					} else {
						set curFilename [string tolower [string range $data 1 end]]
					}
					foreach dead_chan [glob -nocomplain [file join $statslogdir $curFilename]*] {
						file delete -force $dead_chan
						if {[file pathtype $dead_chan] == "relative"} {putidx $handle "Deleted [pwd]/$dead_chan..."} else {putidx $handle "Deleted $dead_chan..."}
					}
				}
				close $read_dead
				file delete -force $dffile
				putidx $handle "\nFinished deleting redundant logfiles..."
				return 0
			}
			datestamp {
				set starttime [clock format [clock scan now] -format "%a %b %d %T %Y"]
				if {![array exists channels] || [array size channels] < 1} {
					putlog "$version - No channels defined. Use +chan first. Unable to add datestamp in logfile."
					variable enabled 0
					return 0
				}
				foreach c [lsort [array names channels]] {
					writelog sesdata 0 1 2 $channels($c) "Session Time: $starttime"
				}
				return 0
			}
		}
	}

	proc switchlogs {} {
		variable actives
		foreach v $actives {variable $v}
		if {$enabled == 0} {return 0}
		foreach c [lsort [array names channels]] {
			set curChan $channels($c)
			logfile close $curChan
			if {[expr $unixnames < 1]} {
				set curFilename [string tolower $curChan]
			} else {
				set curFilename [string tolower [string range $curChan 1 end]]
			}
			if {$dodatestamp == 1} {
				if {$doyearstamp == 0} {
					set date [clock format [clock scan "now yesterday"] -format %m.%d.%Y]
				} else {
					set date [clock format [clock scan "now yesterday"] -format %Y]
				}
				file rename -force [file join $statslogdir $curFilename].log [file join $statslogdir $curFilename].${date}.log
			} else {
				file rename -force [file join $statslogdir $curFilename].log [file join $statslogdir $curFilename].bak
			}
			logfile create $curChan
		}
		if {$notify == 1} {
			sendnote mEL $staticlogkeeper "$version - Logfiles have rotated at [clock format [clock scan now] -format %c]"
		}
	}
	
	proc checktimer {} {
		variable actives
		foreach v $actives {variable $v}
		if {$nextswitch == ""} {
			putlog "$version - No rotation date found - Binding new timer (logfile switcher)"
			switch -- $rotate {
				week {
					set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
				month {
					set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
				}
				year {
					set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
					variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
				}
				default {
					set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
			}
			if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
				set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
			} else {
				set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
			}
			bind time - $tt ::mel::timer
			arraywrite
			return 0
		}
		if {[expr [clock scan now] > $nextswitch]} {
			putlog "$version - Missed a switch at [clock format $nextswitch -format %c]... switching now"
			switchlogs
			switch -- $rotate {
				week {
					set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
				month {
					set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
				}
				year {
					set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
					variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
				}
				default {
					set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
					variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
				}
			}
			arraywrite
		}
		set t [clock format $nextswitch -format "00 00 %d %m %Y"]
		if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
			set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
		} else {
			set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
		}
		bind time - $tt ::mel::timer
		return 0			
	}
	
	proc checkstamptimer {} {
		variable actives
		foreach v $actives {variable $v}
		switch -- $stamplogs {
			0 { 
				foreach search [binds time] {
					if {[string compare [lindex $search 4] "::mel::stamptimer"] == 0} {
						unbind time - "[lindex $search 2]" ::mel::stamptimer
					}
				}
				return 0
			}
			1 {
				set t [clock format [clock scan "now next day"] -format "00 00 %d %m %Y"]
				variable stampat [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
			2 {
				set t [clock format [clock scan "now next monday"] -format "00 00 %d %m %Y"]
				variable stampat [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
			3 {
				set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
				variable stampat [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
			}
		}
		set t [clock format $stampat -format "00 00 %d %m %Y"]
		if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
			set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
		} else {
			set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
		}
		bind time - $tt ::mel::stamptimer
		return 0
	}
			
	proc stamptimer {min hour day month year} {
		variable actives
		foreach v $actives {variable $v}
		logfile datestamp all
		foreach search [binds time] {
			if {[string compare [lindex $search 4] "::mel::stamptimer"] == 0} {
				unbind time - "[lindex $search 2]" ::mel::stamptimer
			}
		}
		if {$enabled == 0} {
			putlog "$version - mEL is disabled - Not binding timed event (log datestamping)"
			return 0
		}
		checkstamptimer
		return 0
	}
	
	proc timer {min hour day month year} {
		variable actives
		foreach v $actives {variable $v}
		if {$enabled == 0} {return 0}
		switchlogs
		foreach search [binds time] {
			if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
				unbind time - "[lindex $search 2]" ::mel::timer
			}
		}
		if {$enabled == 0} {
			putlog "$version - mEL is disabled - Not binding timed event (logfile switching)"
			return 0
		}
		switch -- $rotate {
			week {
				set t [clock format [clock scan "now next $weekdays($weekly)"] -format "00 00 %d %m %Y"]
				variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
			month {
				set t [clock format [clock scan "now next month"] -format "00 00 01 %m %Y"]
				variable nextswitch [clock scan "[lindex $t 4][lindex $t 3]01T000000"]
			}
			year {
				set t [clock format [clock scan "now next year"] -format "00 00 01 01 %Y"]
				variable nextswitch [clock scan "[lindex $t 4]0101T000000"]
			}
			default {
				set t [clock format [clock scan "now next $rotate days"] -format "00 00 %d %m %Y"]
				variable nextswitch [clock scan "[lindex $t 4][lindex $t 3][lindex $t 2]T000000"]
			}
		}
		arraywrite
		set t [clock format $nextswitch -format "00 00 %d %m %Y"]
		if {[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1} {
			set tt [lreplace $t 3 3 0[expr [string trimleft [lindex $t 3] 0] -1]]
		} else {
			set tt [lreplace $t 3 3 [expr [string trimleft [lindex $t 3] 0] -1]]
		}
		bind time - $tt ::mel::timer
		putlog "$version - Next switch will occur at [clock format $nextswitch -format %c]"
		return 0
	}


	
	proc arrayinit {} {
		variable actives
		foreach v $actives {variable $v}
		if {![file exists [file join $statsdir $settings]]} {
			variable enabled 0
			return 1
		}
		set readsettings [open [file join $statsdir $settings] r]
		set datatype 0
		while {![eof $readsettings]} {
			set data [gets $readsettings]
			if {[eof $readsettings]} {break}
			if {[string index [lindex $data 0] 0] == "\["} {
				regsub -all {[\[\]]} $data {} type
				switch -- $type {
					channels { set datatype 1 }
					keepers { set datatype 2 }
					rotation { set datatype 3 }
					switch { set datatype 4 }
					EOF { break }
				}
				continue
			}
			switch -- $datatype {
				0 { continue }
				1 { lappend allchans $data ; continue }
				2 { lappend allkeeps $data ; continue }
				3 { set tmac $data ; continue }
				4 { set swdate $data ; continue }
			}
		}
		close $readsettings
		array unset channels
		if {[info exists allchans]} {
			set cnt 0
			foreach c $allchans {
				set channels($cnt) $c
				incr cnt
			}
			variable enabled 1
		} else {
			variable enabled 0
			return 0
		}
		array unset keepers
		if {[info exists allkeeps]} {
			set cnt 0
			foreach k $allkeeps {
				set keepers($cnt) $k
				incr cnt
			}
		}
		switch -- $tmac {
			mac {
				variable macmode 1
			}
			week {
				variable macmode 0
				variable rotate week
			}
			month {
				variable macmode 0
				variable rotate month
			}
			year {
				variable macmode 0
				variable rotate year
			}
			default {
				variable macmode 0
				variable rotate $tmac
			}
		}
		variable nextswitch $swdate
		return 0
	}
	
	proc arraywrite {} {
		variable actives
		foreach v $actives {variable $v}
		if {[file exists [file join $statsdir $settings]]} {
			file rename -force [file join $statsdir $settings] [file join $statsdir $settings].old
		}
		set writesettings [open [file join $statsdir $settings] w]
		puts $writesettings "\[channels\]"
		foreach c [lsort [array names channels]] {
			puts $writesettings $channels($c)
		}
		puts $writesettings "\[keepers\]"
		foreach k [lsort [array names keepers]] {
			puts $writesettings $keepers($k)
		}
		puts $writesettings "\[rotation\]"
		puts $writesettings $rotate
		puts $writesettings "\[switch\]"
		puts $writesettings $nextswitch
		puts $writesettings "\[EOF\]"
		close $writesettings
	}
	
	proc item {action type item} {
		variable actives
		foreach v $actives {variable $v}
		switch -- $action {
			find {
				switch -- $type {
					chan {
						if {[array exists channels]} {
							foreach c [array names channels] {
								if {[string compare -nocase $channels($c) $item] == 0} {
									return 1
								}
							}
						}
						return 0
					}
					keep {
						if {[string compare -nocase $item $staticlogkeeper] == 0} {
							return 1
						}
						if {[array exists keepers]} {
							foreach k [array names keepers] {
								if {[string compare -nocase $keepers($k) $item] == 0} {
									return 1
								}
							}
						}
						return 0
					}
				}
			}
			add {
				switch -- $type {
					chan {
						if {![array exists channels]} {
							set channels(0) $item
						} else {
							set channels([expr [array size channels] + 1]) $item
						}
						logfile create $item
						if {[file exists [file join $statsdir $deadchanfile]]} {
							set read [open [file join $statsdir $deadchanfile] r]
							while {![eof $read]} {
								set data [gets $read]
								if {[eof $read]} {break}
								if {[string compare -nocase $item $data] != 0} {
									set write [open [file join $statsdir $deadchanfile].tmp a]
									puts $write $data
									close $write
								}
							}
							close $read
							if {[file exists [file join $statsdir $deadchanfile].tmp]} {
								file rename -force [file join $statsdir $deadchanfile].tmp [file join $statsdir $deadchanfile]
							} else {
								file delete -force [file join $statsdir $deadchanfile]
							}
						}
						arraywrite
					}
					keep {
						if {![array exists keepers]} {
							set keepers(0) $item
						} else {
							set keepers([expr [array size keepers] + 1]) $item
						}
						arraywrite
					}
				}
			}
			del {
				switch -- $type {
					chan {
						foreach c [array names channels] {
							if {[string compare -nocase $channels($c) $item] == 0} {
								logfile close $item
								unset channels($c)
								set add_dead [open [file join $statsdir $deadchanfile] a]
								puts $add_dead $item
								close $add_dead
								if {[array names channels] == ""} {
									variable enabled 0
									foreach search [binds time] {
										if {[string compare [lindex $search 4] "::mel::timer"] == 0} {
											unbind time - "[lindex $search 2]" ::mel::timer
										}
									}
									putlog "$version - No channels are being logged. mEL turned off, existing time bindings removed."
								}
								arraywrite
							}
						}
					}
					keep {
						foreach k [array names keepers] {
							if {[string compare -nocase $keepers($k) $item] == 0} {
								unset keepers($k)
								arraywrite
							}
						}
					}
				}
			}
		}
	}
	
	proc strip {args} {
		regsub -all -- {((\002|\026|\037|\017|\022)|(\003([0-9]{1,2}(,[0-9]{1,2})?)?))} $args "" args
		foreach char [split $args {}] {
			if {[string is graph $char] || $char == " "} {
				append printable $char
			}
		}
		return $printable
	}
	
	proc writelog {args} {
		variable actives
		foreach v $actives {variable $v}
		if {$enabled == 0} {return 0}
		if {$bhosts == 1 && [isignore [lindex $args 2]]} {return 0}
		set curTime [clock format [clock scan now] -format "%H:%M"]
		set curChannel [string tolower [lindex $args 4]]
		if {![item find chan $curChannel]} { return 0 }
		if {[expr $unixnames < 1]} {
			set curFilename ${curChannel}.log
		} else {
			set curFilename [string range $curChannel 1 end].log
		}
		if {$skipmac == 0} {
			if {$macmode == 1 && ![file exists [file join $statslogdir $curFilename]]} {
				logfile create $curChannel
			}
		}
		switch -- [lindex $args 0] {
			chat {
				if {[lsearch -exact [string tolower $ignorenicks] [string tolower [lindex $args 1]]] == -1} {
					set addline "\[$curTime\] <[lindex $args 1]> [join [strip [lindex $args 5]]]"
				} else {
					return 0
				}
			}
			join {set addline "\[$curTime\] *** [lindex $args 1] ([lindex $args 2]) has joined $curChannel"}
			quit {set addline "\[$curTime\] *** [lindex $args 1] has quit IRC ([join [strip [lindex $args 5]]])"}
			topic {
				if {[lindex $args 1] == "*"} {return}
				set addline "\[$curTime\] *** [lindex $args 1] changes topic to '[join [strip [lindex $args 5]]]'"
			}
			kick {set addline "\[$curTime\] *** [lindex $args 5] was kicked by [lindex $args 1] ([lindex $args 6])"}
			nick {set addline "\[$curTime\] *** [lindex $args 1] is now known as [lindex $args 5]"}
			mode {set addline "\[$curTime\] *** [lindex $args 1] sets mode: [lindex $args 5] [lindex $args 6]"}
			part {set addline "\[$curTime\] *** [lindex $args 1] ([lindex $args 2]) has left [lindex $args 4] ([lindex $args 5])"}
			action {
				if {[lsearch -exact [string tolower $ignorenicks] [string tolower [lindex $args 1]]] == -1} {
					set addline "\[$curTime\] * [lindex $args 1] [join [strip [lindex $args 5]]]"
				} else {
					return 0
				}
			}
			sesdata {set addline [lindex $args 5]}
		}
		set writeout [open [file join $statslogdir $curFilename] a]
		puts $writeout $addline
		close $writeout
	}
	
	proc chatter {nick host handle channel text} {writelog chat $nick $host $handle $channel $text}
	proc enter {nick host handle channel} {writelog join $nick $host $handle $channel}
	proc signoff {nick host handle channel partmsg} {writelog quit $nick $host $handle $channel $partmsg}
	proc ctopic {nick host handle channel topic} {writelog topic $nick $host $handle $channel $topic}
	proc kicked {nick host handle channel target reason} {writelog kick $nick $host $handle $channel $target $reason}
	proc nickchange {nick host handle channel newnick} {writelog nick $nick $host $handle $channel $newnick}
	proc cmode {nick host handle channel change victim} {writelog mode $nick $host $handle $channel $change $victim}
	proc parting {nick host handle channel partmsg} {writelog part $nick $host $handle $channel $partmsg}
	proc action {nick host handle destination keyword arg} {writelog action $nick $host $handle $destination $arg}
	
}
putlog "Initializing $::mel::version...."
putlog "$::mel::version - Running startup tests..."
if {[::mel::starttests]} {
	putlog $::mel::starterror
	die "Fatal error - Can not continue"
} else {
	::mel::arrayinit
	::mel::logfile datestamp all
	if {$::mel::macmode == 0 && $::mel::enabled == 1} {
		::mel::checktimer
	}
	::mel::checkstamptimer
	loadhelp mel.help
	putlog "$::mel::version successfully initialized..."
}

### http://mel.sourceforge.net
### Feel free to alter this tcl to your personal flavour... just don't forget who wrote the
### original code... Also, if you find bugs, or even fix some.. then please let me know!
s
storm6699
Voice
Posts: 4
Joined: Mon Sep 20, 2010 9:15 am

Post by storm6699 »

marvz: you are a king, now is working perfectly thnx m8 :-D
m
marvz
Halfop
Posts: 64
Joined: Fri Jun 18, 2010 2:37 pm

Post by marvz »

No prob! Glad I could help.

For future reference, it looks like the script has changed again and this is what was causing the problem:

Code: Select all

{[string length [expr [lindex $t 3] -1]] == 1}
Locate that in the script and replace it with this

Code: Select all

{[string length [expr [string trimleft [lindex $t 3] 0] -1]] == 1}
This may not be a problem for all so I suppose it can be fixed on a case by case basis.
Post Reply