; ########### SETUP START ###########
; put the name of your channel
alias -l utime.chan { return #yourchannel }
; put more excluded nicknames (e.g. services/bots) after "$me" (separated by spaces)
alias -l utime.exclude { return $me }
; ########### SETUP END ###########
; mirc start
on *:start: {
; create "master-table" (to hold sums) and load previously stored data into it
hmake utime 500
if ($isfile(utime.hsh)) { hload utime utime.hsh }
}
; you join the channel
on me:*:join:$($utime.chan): {
; set marker "waiting for end of /names of #"
hadd -m utime.wait # x
}
; reply "end of /names"
raw 366 :*: {
; target is the channel and chan is marked "waiting": remove marker and start count for all the nicks currently in the channel
if ($hget(utime.wait,$2)) {
hfree utime.wait
utime.startall
}
}
; some other user joins the channel
on !*:join:$($utime.chan): {
; not waiting for /names reply: start count for this nick
if (!$hget(utime.wait)) { utime.start $nick }
}
; you part the channel
on me:*:part:$($utime.chan): {
; remove possible "waiting for /names reply" marker, or (not waiting for /names reply) update count for all the nicks of the channel in master-table
if ($hget(utime.wait)) { hfree $v1 }
else { utime.stopall }
}
; some other user parts the channel
on !*:part:$($utime.chan): {
; not waiting for /names reply: update count for this nick in master-table
if (!$hget(utime.wait)) { utime.stop $nick }
}
; some other user quits the network
on !*:quit:{
; not waiting for /names reply: update count for this nick in master-table
if (!$hget(utime.wait)) { utime.stop $nick }
}
; you quit / get disconnected from the network / exit mirc
on *:disconnect: {
; remove possible "waiting for /names reply" marker, or (not waiting for /names reply) update count for all the nicks of the channel in master-table
if ($hget(utime.wait)) { hfree $v1 }
else { utime.stopall }
; save (and thus update) master-table to hard disk
hsave utime utime.hsh
}
; a kick occurs in the channel
on *:kick:$($utime.chan): {
; you're the kicked user
if ($knick == $me) {
; remove possible "waiting for /names reply" marker, or (not waiting for /names reply) update count for all the nicks of the channel in master-table
if ($hget(utime.wait)) { hfree $v1 }
else { utime.stopall }
}
; you're not the kicked user
else {
; not waiting for /names reply: update count for this nick in master-table
if (!$hget(utime.wait)) { utime.stop $knick }
}
}
; store "session" start time for a nick to a temp-table
alias -l utime.start { if (!$istok($utime.exclude,$1,32)) hadd -m utime.start $1 $ctime }
; update count for a nick: add session duration (current time minus session start time) to total time (master-table) and delete session-item
alias -l utime.stop {
if ($hget(utime.start,$1)) { hinc utime $1 $calc($ctime - $v1) | hdel utime.start $1 }
}
; mass-aliases for utime.start/utime.stop
alias -l utime.startall {
var %n = 1
while ($nick($utime.chan,%n)) { utime.start $v1 | inc %n }
}
alias -l utime.stopall {
var %n = 1
while ($nick($utime.chan,%n)) { utime.stop $v1 | inc %n }
}
; menu
menu channel {
$iif(($active == $utime.chan),Create user-time Log...)
.formatted
..by time
...ascending : utime.log duration time
...descending : utime.log duration time desc
..by nick
...ascending : utime.log duration name
...descending : utime.log duration name desc
.plain seconds (for spreadsheet)
..by time
...ascending : utime.log spread time
...descending : utime.log spread time desc
..by nick
...ascending : utime.log spread name
...descending : utime.log spread name desc
.-
.reset : utime.purge
}
; create/show logfile
alias -l utime.log {
; flush session data (data of temp-table) to master-table
utime.stopall | utime.startall
; create blank text-file
var %f = utime.txt
write -c %f
; save master-table to file (ini format) and remove first line (ini-header)
hsave -i utime %f
write -dl1 %f
if (!$lines(%f)) { echo -agc info * Usertime-Log: No data collected as yet... | return }
; load file into binvar to replace all "=" chars with tabstops
bread %f 0 $file(%f).size &utime
breplace &utime 61 9
; write result back to file, sort file
bwrite %f 0 -1 &utime
if ($2 == time) { filter -ffctu $+ $iif(($3 == desc),e) 2 9 %f %f }
else { filter -ffct $+ $iif(($3 == desc),e) 1 9 %f %f }
; option "formatted output"
if ($1 == duration) {
; loadbuf sorted file to a hidden window
window -h @utime
loadbuf -r @utime %f
; add to each line a zeropadded index-No. and replace the numeric seconds-value with a $duration
var %n = 1, %base = $len($line(@utime,0))
while ($line(@utime,%n)) {
rline @utime %n $base(%n,10,10,%base) $+ . $gettok($v1,1,9) : $duration($gettok($v1,2,9))
inc %n
}
; dump the formatted text back into the file and close the window
savebuf @utime %f
window -c @utime
}
; insert header line (channel, sort mode, date and time)
write -il1 %f $crlf
write -il1 %f Total attendance time $iif(($1 == spread),(seconds)) on $utime.chan $&
(sorted $iif(($3 == desc),downward) by $iif(($2 == time),$v1,nickname) $+ ) - $fulldate
; open file (or show location)
if (!$lock(run)) { run %f }
else { echo -agc info * Usertime-Log created at: $longfn(%f) }
}
; reset
alias -l utime.purge {
; remove tables and hash-file
hfree -w utime*
if ($isfile(utime.hsh)) { .remove -b utime.hsh }
; if != unload: recreate master-table and start count for all the nicks currently in the channel
if (!$1) {
hmake utime 500
if ($me ison $utime.chan) { utime.startall }
}
}
on *:unload: { utime.purge unload }