mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2007
Posts: 214
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Oct 2007
Posts: 214
Hello,

How would I go about tracking how long a user has been in a channel from the time they joined the channe; to the time they left the channel.

Id like to have an On Part message saying: "User has left the channel Duration: 15 mins and 30 secs.

and when I right click on their name in the nicklist while they are still in the channel, will echo me there current duration in the channel.

Thanks a bunch in advance.

Cheers,

Jay

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
If it's ok to start tacking when you joined that channel, thus not taking previous presence into account, it would be quite easy (as one could use mIRCs internal $nick().idle identifier). Would that be ok?

Joined: Oct 2007
Posts: 214
B
Fjord artisan
OP Offline
Fjord artisan
B
Joined: Oct 2007
Posts: 214
Hello,

Its's not that I am trying to track how long they have been idle for, its just mainly how long they have been in the channel overall from join to part.

Thanks

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
ok, my mistake smile I'll have a look at it.

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Try this (untested) code:

Code:

on *:CONNECT:*:{
  if ($hget(jt.,$cid)) hfree $+(jt.,$cid)
  hmake $+(jt.,$cid) 10
}

on *:JOIN:*:{
  hadd -m $+(jt.,$cid) $+($nick,.,$chan) $ctime
  if ($nick == $me) {
    var %c = 1, %cc = $nick($chan,0)
    while (%c < %cc) {
      hadd -m $+(jt.,$cid) $+($nick($chan,%c),.,$chan) $ctime
      inc %c
    }
  }
}

on *:PART:*:{
  hdel $+(jt.,$cid) $+($nick,.,$chan)
  if ($nick == $me) hdel -w $+(jt.,$cid) $+(*.,$chan)
}

on *:KICK:*:{
  hdel $+(jt.,$cid) $+($nick,.,$chan)
  if ($nick == $me) hdel -w $+(jt.,$cid) $+(*.,$chan)
}

on *:QUIT:{
  hdel -w $+(jt.,$cid) $+($nick,.*)
  if (($nick == $me) && ($hget($+(jt.,$cid)))) hfree $+(jt.,$cid)
}

on *:DISCONNECT:{
  if ($hget($+(jt.,$cid))) hfree $+(jt.,$cid)
}


on *:NICK:{
  var %c = 1, %cc = $hfind($+(jt.,$cid),$+($nick,.*),0,w)
  while (%c < %cc) {
    var %chan = $gettok($hfind($+(jt.,$cid),$+($nick,.*),%c,w),2,46)
    hadd $+(jt.,$cid) $+($newnick,.,%chan) $hget($+(jt.,$cid),$+($nick,.,%chan))
  }
  hdel -w $+(jt.,$cid) $+($nick,.*)
}

alias jointime {
  if ($2 == $null) return
  var %cid = $cid
  if ($3 != $null) %cid = $3
  if ($isid) return $hget($+(jt.,%cid),$+($1,.,$2))
  echo -a $hget($+(jt.,%cid),$+($1,.,$2)
}



Automatically keeps track of all nicks on all channels on all networks. Multi-network safe (uses $cid). When you join a channel, all other users on the channel get the same join time as you. To retrieve data:

/jointime <nick> <channel> [cid]

//echo -a $jointime(<nick>,<channel>,[cid])

The alias only returns the $ctime when the user joined the specified channel. You can perform whatever calculations you want using the $jointime() returned value. Returns/displays $null for invalid/nonexistant nick and channel.

Report any bugs.

-genius_at_work

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Beaten to it, but here's my similar, jet less 'modular' approach

Code:
; ••• add data after own join of a chan ('end of names list') •••
RAW 366:*: {
  ; no table existing (it's the first /names reply)
  if (!$hget($+(Presence,$chr(9),$network,$chr(9),$2))) {
    ; add all nicks with value 'current time' to a hash table
    var %nr = 1
    while ($nick($2,%nr)) {
      hadd -m $+(Presence,$chr(9),$network,$chr(9),$2) $v1 $ctime
      inc %nr
    }
  }
}

; ••• add data on join •••
on !*:JOIN:#: {
  ; if table had been created, add nick with value 'current time'
  if ($hget($+(Presence,$chr(9),$network,$chr(9),$chan))) { hadd $v1 $nick $ctime }
}

; ••• update data on nick •••
on *:NICK: {
  ; cycle all hash tables
  var %nr = 1
  while ($hget(%nr)) {
    var %table = $v1
    ; it's a 'presence' table and it contains an entry for $nick
    if (($gettok(%table,1,9) === Presence) && ($hget(%table,$nick))) {
      ; add a new item $newnick with the value of $nick and delete the old entry for $nick
      hadd %table $newnick $v1
      hdel %table $nick
    }
    inc %nr
  }
}

; ••• delete data on kick •••
on *:KICK:#: { 
  ; someone had been kicked
  if ($knick != $me) { 
    ; remove data of kicked user for this chan
    if ($hget($+(Presence,$chr(9),$network,$chr(9),$chan),$knick)) {
      hdel $+(Presence,$chr(9),$network,$chr(9),$chan) $knick
    }
  }
  ; you're kicked: remove ALL the chan's data
  elseif ($hget($+(Presence,$chr(9),$network,$chr(9),$chan))) { hfree $v1 }
}

; ••• delete all data for the chan you parted •••
on me:*:PART:#: {
  if ($hget($+(Presence,$chr(9),$network,$chr(9),$chan))) { hfree $v1 }
}

; ••• someone parted: custom part output, delete data of parting nick •••
on ^!*:PART:#: {
  if ($hget($+(Presence,$chr(9),$network,$chr(9),$chan),$nick))  {


    ; this is the part output:
    ; ---------------------------------------------------------------------------------------------------------------------
    ECHO -tbfrc part $chan *** $nick parts $chan (had been $duration($calc($ctime - $v1)) present on $chan $+ )
    ; ---------------------------------------------------------------------------------------------------------------------
    ; if you want to replace the default part message, remove the ; at the beginning of the next line
    ; HALTDEF


    hdel $+(Presence,$chr(9),$network,$chr(9),$chan) $nick

  }
}

; ••• delete all tables if you quit •••
on me:*:QUIT: {
  ; cycle all hash tables 
  var %nr = 1
  while ($hget(%nr)) {
    var %table = $v1
    ; it's a 'presence' table and it is a table for network: delete it
    if (($gettok(%table,1,9) === Presence) && ($gettok(%table,2,9) == $network)) { hfree %table }
    inc %nr
  }
}

; ••• someone quitted: custom quit output, delete all data of quitting nick •••
on ^!*:QUIT: {
  ; cycle all hash tables 
  var %nr = 1
  while ($hget(%nr)) {
    var %table = $v1
    tokenize 9 $v1
    if (($1 === Presence) && ($2 == $network) && ($me ison $3) && ($hget(%table,$nick))) {


      ; this is the quit output
      ; ---------------------------------------------------------------------------------------------------------------------
      ECHO -tbfrc quit $3 *** $nick left $3 (had been $duration($calc($ctime - $v1)) present on $3 $+ )
      ; ---------------------------------------------------------------------------------------------------------------------
      ; if you want to replace the default quit message, remove the ; at the beginning of the next line
      ; HALTDEF


      hdel %table $nick
    }
    inc %nr
  }
}


Popups example:
Code:
menu nicklist {
-
$iif(($hget($+(Presence,$chr(9),$network,$chr(9),$chan),$$1)),$$1 present $duration($calc($ctime - $v1)) on $active) : noop
-
}


Last edited by Horstl; 15/05/08 04:40 AM.

Link Copied to Clipboard