idlech - Channel Idle Times

By Meta on Sep 15, 2013

UPDATE: Incorporated Wiz126's $safe() alias to prevent unwanted evaluation caused by the timers. (informational link within comment in script)

Based on DBN's feature suggestion on the official mIRC forums.

This script will keep an auto-updating list of channel idle times ($chan(#).idle) which can then be used to get the time in seconds elapsed since the last message. (i.e. text or action) -- $chan(#).idle will always return 0 when used in an on TEXT or ACTION event.

[i]* Note: If you load this script while you are already in a/some channel(s), you can either:
]Manually add the channel(s) to the idlech list
[]Disconnect and reconnect from the server
]/hop or /cycle the channel(s)

Specific instructions of use are provided in a comment within the script.

NOTE: This requires that $network is filled in order to work. (I've never come across a network that doesn't fill it, but apparently, according to the mIRC help file, they can exist...)

  Questions, comments, bugs, or suggestions? I am:
  Meta on,,
  Xse on,, (phone nick)

  ** Except for, wherever I am Xse, I am NOT Meta.
  ** However, wherever I am Meta does NOT necessarily indicate that
     I am not Xse.
; ----------------------------- ;
; The following events will automatically add, remove, and clear the idlech
; List for a channel or network (Depending)
on me:*:JOIN:#:.idlech -a #
on me:*:PART:#:.idlech -r #
on *:DISCONNECT:.idlech -r
; ----------------------------- ;
  To manually add a channel to a network's idlech list: /idlech -a #channel
  ** NOTE: You must be on the channel for this command to work.

  To remove a channel from a network's idlech list: /idlech -r #channel

  To manually clear a network's idlech list: /idlech -r

  To list a network's idlech list: /idlech -l [network] OR /iclist [network]
  NOTE: If [network] isn't specified, the active network is assumed.
  $iclist(NETWORK) - Returns $true if NETWORK's idlech list exists, else $false

  $iclist(NETWORK,CHANNEL) - Returns the idle time for CHANNEL on NETWORK if
    it is in NETWORK's idlech list

  $iclist(NETWORK,N) - Returns the Nth channel in NETWORK's idlech list
  If N is 0, returns the total number of channels in NETWORK's idlech list
alias iclist {
  if (!$isid) idlech -l $iif($1,$1,$network)
  elseif ($2 isnum) return $hfind($1_idle,*,$2,w)
  else return $iif($2,$hget($1_idle,$2),$iif($hget($1_idle),$true,$false))
alias idlech {
  if ($0 < 2) && (!$istok(-l -r,$1,32)) echo -gaec i * /idlech: insufficient parameters
  elseif (!$network) echo -gaecq i * /idlech: you are not on a network  
  else { 
    var %tmr $+(.timer_idle_,$network,_,$2), %hsh $network $+ _idle, %eco echo -gaecq i * 
    if ($1 == -a) {    
      if ($me !ison $2) %eco /idlech: not on channel $2
      elseif (!$iclist($network,$2)) {
        %tmr 0 0 hadd -m %hsh $safe($2) $!chan( $safe($2) ).idle
        %eco $2 added to $network idlech list
    elseif ($1 == -r) {
      if (!$2) {
        if ($iclist($network)) hfree %hsh
        %tmr $+ * off
        %eco $network idlech list cleared
      elseif (!$iclist($network,$2)) %eco $2 is not on $network idlech list
      else {
        %tmr off
        hdel %hsh $2
        %eco $2 removed from $network idlech list
        if (!$iclist($network,0)) hfree %hsh
    elseif ($1 == -l) {
      var %net $iif($2,$2,$network), %i 1
      if (!$iclist(%net)) %eco %net idlech list empty
      else {
        while ($iclist(%net,%i)) {
          echo -gac i * $v1
          inc %i
        echo -gaec i * End of %net idlech list
; ----------------------------- ;
; $safe() by Wiz126 - Prevents unwanted evaluation in timers and scon/scid
; For more info,
alias safe return $!decode( $encode($1-, m) ,m)

Example script:

When someone types !chanidle, !chidle, or !idlech in a channel that is in the network's idlech list, the scriptholder will reply with the time elapsed since the last message...

on $*:TEXT:/^!(ch(an)?idle|idlech)/Si:#:{
  if ($iclist($network,#) != $null) .msg # Time since last message: $duration($v1)
  else .msg # I am not tracking the idle time for this channel.

Example of use:

[03:04 09/15/13] <@Meta> !idlech
[03:04 09/15/13] Time since last message: 18mins 45secs


Sign in to comment.
RIcko   -  Sep 15, 2013

Nice snippet

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.