mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2009
Posts: 6
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Oct 2009
Posts: 6
I would like to create either a text file (log) or remote script that keeps track of how long a user has been in a channel that I can look at, something like a time length log. Can someone help me? Thanks.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Creating this kind a custom logfile requires a remote script in any case.

1) Do you chat on multiple networks (has the script to account for different networks)? Do you want to log for
(a) all channels
(b) multiple channels or
(c) only one specific chan?

For 1a/b: Do you want to create a single log, or one log per channel?

2) How do you want to log the duration:
(a) per stay (e.g. "xyz joined <#channel> at <time> and left after <duration>") or
(b) add durations to a sum (e.g. "xyz attended #chan for <duration> in total)?
For 2b: shall the log be sorted ("top users")?

3) How do you define "user"? I.e.: shall logging be based on
(a) nickname (as nicks can be changed, the same user could appear under different nicks in the log)
- log acc. to the nickname used at the moment of join (tracing nickchanges), or log acc. to the "actual" nickname use (creating a new- or adding to a different item on nickchange)
(b) hostmask (*!*@host.domain) (multiple users may appear under the same hostmask due to proxys/BNCs/vHosts/dynamic IP addresses; one user may appear under different hostmasks for the same reasons)
(c) another mask type (e.g. *!user@host.domain or nick!user@host.domain)?

4) Do you have scripting experience (looking for an approach/suggestions only)?

Joined: Oct 2009
Posts: 6
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Oct 2009
Posts: 6
1. It is only on one specific channel on one specific network.
2. Add duration to the sum, I really don't need sorting.
3. Nickname. The network I'm on doesn't allow nickname changes.
4. I have created some scripts but nothing like this so no I have no scripting experience for this particular situation.

Thanks for the help and the reply. laugh

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Code:
; ########### 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 }
...please note that I tested only a wee bit... smile

Edit: you have to paste the code into a file and load it - or restart mirc after you pasted the code directly into a blank new "remote" (and saved it of course).
Edit2: added reset option and unload event, fixed a typo

Last edited by Horstl; 25/10/09 02:44 AM.
Joined: Oct 2009
Posts: 6
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Oct 2009
Posts: 6
Thank you for your time into this. I really appreciate it. Everything works fine.


Link Copied to Clipboard