mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2003
Posts: 2,737
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,737
Show someone's idle times for the server and each channel you share in common.
Handy if you're being a nosy stalker. Replaces /whois in most cases.

Usage: /idle Raccoon

* Raccoon signed on 2w1d, idle 1s, @#raccoon[1s] Query[1m5s] Chat[1m12s] @#irchelp[2h9m] +#politics[15h6m] #efnet[2w1d]

http://www.hawkee.com/snippet/10010/

Code:
; Use: /idle <nickname>
ALIAS idle { ; by Raccoon 10-July-2013 13-aug-2013
  .raw WHOIS $$1 $1
  .enable #idle_whois
  hinc -mu5 idle_whois cnt 1
  .timerIDLE_WHOIS 1 5 .disable #idle_whois
}
#idle_whois off
RAW 319:*: { hadd -mu5 idle_whois $cid $+ $2 $+ .chans $hget(idle_whois,$cid $+ $2 $+ .chans) $3- | halt }
RAW 317:*: { hadd -mu5 idle_whois $cid $+ $2 $+ .idle $3-4 | halt }
RAW 318:*: { 
  VAR %PRECISION = 2
  var %nick = $2
  var %chans = $hget(idle_whois,$cid $+ $2 $+ .chans)
  var %idles = $hget(idle_whois,$cid $+ $2 $+ .idle)
  var %idle = $gettok(%idles,1,32), %signon = $gettok(%idles,2,32)
  var %i = 1, %cidles, %rchans = %chans
  if ($query(%nick)) { var %cidles = $query(%nick).idle $+ :Query }
  if ($chat(%nick)) { var %cidles = %cidles $chat(%nick).idle $+ :Chat }
  WHILE $gettok(%chans,%i,32) {
    var %pchan = $v1
    var %chan = $regsubex(%pchan,/^[^ $chantypes ]*/x,)
    var %cidle = $nick(%chan,%nick).idle
    if (%cidle != $null) { 
      var %cidles = %cidles %cidle $+ : $+ %pchan
      var %rchans = $remtok(%rchans,%pchan,1,32)
    }
    inc %i
  }
  var %cidles = $sorttok(%cidles,32,n)
  var %i = 1, %chanidles
  WHILE $gettok(%cidles,%i,32) {
    var %pchan = $gettok($v1,2,58)
    var %cidle = $gettok($v1,1,58)
    var %chanidles = %chanidles %pchan $+ [[ $+ $dur(%cidle,%PRECISION) $+ ]]
    inc %i
  }
  echo -atic whois * $2 signed on $dur($calc($ctime - %signon),2) $+ , idle $dur(%idle,2) $+ , %chanidles %rchans
  hdel -w idle_whois $cid $+ $2 $+ .*
  hdec -m idle_whois cnt 1
  if (!$hget(idle_whois,cnt)) { .disable #idle_whois | hfree -w idle_whois }
  halt
}
RAW *:*: halt
#idle_whois end

;$duration(12345678) = 20wks 2days 21hrs 21mins 18secs / $dur(12345678) = 20w2d21h21m18s / $dur(12345678,2) = 20w2d
ALIAS dur { return $remove($gettok($regsubex($duration($1),/(\d+\w)\S*/g,\t),1- $+ $2,32),$chr(32)) } ; by Raccoon


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Feb 2003
Posts: 2,737
Raccoon Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,737
Any suggestions on simplifying this script? It works nicely but doesn't look very elegant.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
D
Deega
Deega
D
Couple of things I see at a quick look

There's no reason for "var %nick = $2", just use $2.

Why loop channel/query/chat's twice?

Also just declare %rchans blank and add chans as needed.



Code:
  var %i = 1, %cidles, %rchans
  if ($query($2)) { %cidles = $+(Query[,$dur($query($2).idle,%PRECISION),]) }
  if ($chat($2)) { %cidles = %cidles $+(Chat[,$dur($chat($2).idle,%PRECISION),]) }
  WHILE $gettok(%chans,%i,32) {
    var %pchan = $v1, %chan = $regsubex(%pchan,/^[^ $chantypes ]*/x,)
    if ($nick(%chan,$2).idle isnum) { %cidles = %cidles $+(%pchan,[,$dur($v1,%PRECISION),]) }
    else %rchans = %rchans %pchan
    inc %i
  }


Also
Code:
alias dur return $regsubex($gettok($duration($1),1- $2,32),/[kayrinec ]s?/g,)


Last edited by Deega; 18/08/13 11:05 PM.
Joined: Jan 2004
Posts: 1,330
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
There is a reason to use var %nick = $2; readability and maintainability.

D
Deega
Deega
D
If you look at his original code you'll see that both "%nick" and "$2" are being used throughout (even after setting %nick), there goes readability laugh
As for maintainability, "$2" is always going to be... "$2" That will not change. wink

Joined: Jan 2004
Posts: 1,330
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
But %nick might not always be $2

Joined: Sep 2005
Posts: 2,630
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,630
I prefer to initialise everything at the start, but that's just a preference thing I guess. Also, as previously suggested you should use %nick for readability purposes. You may one day forget what $2 is in the context of a whois reply, but you'll always know what %nick means smile

Code:
; Use: /idle <nickname>
ALIAS idle { ; by Raccoon 10-July-2013 13-aug-2013
  .raw WHOIS $$1 $1
  .enable #idle_whois
  hinc -mu5 idle_whois cnt 1
  .timerIDLE_WHOIS 1 5 .disable #idle_whois
}
#idle_whois off
RAW 319:*: { hadd -mu5 idle_whois $cid $+ $2 $+ .chans $hget(idle_whois,$cid $+ $2 $+ .chans) $3- | halt }
RAW 317:*: { hadd -mu5 idle_whois $cid $+ $2 $+ .idle $3-4 | halt }
RAW 318:*: { 
  VAR %PRECISION = 2, %nick = $2, %chans = $hget(idle_whois,$cid $+ $2 $+ .chans), %idles = $hget(idle_whois,$cid $+ $2 $+ .idle), $&
  %idle = $gettok(%idles,1,32), %signon = $gettok(%idles,2,32), %i = 1, %cidles, %rchans = %chans, %pchan, %chan, %cidles, %cidle, %chanidles
  if ($query(%nick)) { %cidles = $query(%nick).idle $+ :Query }
  if ($chat(%nick)) { %cidles = %cidles $chat(%nick).idle $+ :Chat }
  WHILE $gettok(%chans,%i,32) {
    %pchan = $v1
    %chan = $regsubex(%pchan,/^[^ $chantypes ]*/x,)
    %cidle = $nick(%chan,%nick).idle
    if (%cidle != $null) { 
      %cidles = %cidles %cidle $+ : $+ %pchan
      %rchans = $remtok(%rchans,%pchan,1,32)
    }
    inc %i
  }
  %cidles = $sorttok(%cidles,32,n)
  %i = 1
  %chanidles = 
  WHILE $gettok(%cidles,%i,32) {
    %pchan = $gettok($v1,2,58)
    %cidle = $gettok($v1,1,58)
    %chanidles = %chanidles %pchan $+ [[ $+ $dur(%cidle,%PRECISION) $+ ]]
    inc %i
  }
  echo -atic whois * %nick signed on $dur($calc($ctime - %signon),2) $+ , idle $dur(%idle,2) $+ , %chanidles %rchans
  hdel -w idle_whois $cid $+ %nick $+ .*
  hdec -m idle_whois cnt 1
  if (!$hget(idle_whois,cnt)) { .disable #idle_whois | hfree -w idle_whois }
  halt
}
RAW *:*: halt
#idle_whois end

;$duration(12345678) = 20wks 2days 21hrs 21mins 18secs / $dur(12345678) = 20w2d21h21m18s / $dur(12345678,2) = 20w2d
ALIAS dur { return $remove($gettok($regsubex($duration($1),/(\d+\w)\S*/g,\t),1- $+ $2,32),$chr(32)) } ; by Raccoon

Joined: Feb 2025
Posts: 3
abi Offline
Self-satisfied door
Offline
Self-satisfied door
Joined: Feb 2025
Posts: 3
Originally Posted by Raccoon
Show someone's idle times for the server and each channel you share in common.
Handy if you're being a nosy stalker. Replaces /whois in most cases.

Usage: /idle Raccoon

* Raccoon signed on 2w1d, idle 1s, @#raccoon[1s] Query[1m5s] Chat[1m12s] @#irchelp[2h9m] +#politics[15h6m] #efnet[2w1d]

http://www.hawkee.com/snippet/10010/

Code
; Use: /idle <nickname>
ALIAS idle { ; by Raccoon 10-July-2013 13-aug-2013
  .raw WHOIS $$1 $1
  .enable #idle_whois
  hinc -mu5 idle_whois cnt 1
  .timerIDLE_WHOIS 1 5 .disable #idle_whois
}
#idle_whois off
RAW 319:*: { hadd -mu5 idle_whois $cid $+ $2 $+ .chans $hget(idle_whois,$cid $+ $2 $+ .chans) $3- | halt }
RAW 317:*: { hadd -mu5 idle_whois $cid $+ $2 $+ .idle $3-4 | halt }
RAW 318:*: { 
  VAR %PRECISION = 2
  var %nick = $2
  var %chans = $hget(idle_whois,$cid $+ $2 $+ .chans)
  var %idles = $hget(idle_whois,$cid $+ $2 $+ .idle)
  var %idle = $gettok(%idles,1,32), %signon = $gettok(%idles,2,32)
  var %i = 1, %cidles, %rchans = %chans
  if ($query(%nick)) { var %cidles = $query(%nick).idle $+ :Query }
  if ($chat(%nick)) { var %cidles = %cidles $chat(%nick).idle $+ :Chat }
  WHILE $gettok(%chans,%i,32) {
    var %pchan = $v1
    var %chan = $regsubex(%pchan,/^[^ $chantypes ]*/x,)
    var %cidle = $nick(%chan,%nick).idle
    if (%cidle != $null) { 
      var %cidles = %cidles %cidle $+ : $+ %pchan
      var %rchans = $remtok(%rchans,%pchan,1,32)
    }
    inc %i
  }
  var %cidles = $sorttok(%cidles,32,n)
  var %i = 1, %chanidles
  WHILE $gettok(%cidles,%i,32) {
    var %pchan = $gettok($v1,2,58)
    var %cidle = $gettok($v1,1,58)
    var %chanidles = %chanidles %pchan $+ [[ $+ $dur(%cidle,%PRECISION) $+ ]]
    inc %i
  }
  echo -atic whois * $2 signed on $dur($calc($ctime - %signon),2) $+ , idle $dur(%idle,2) $+ , %chanidles %rchans
  hdel -w idle_whois $cid $+ $2 $+ .*
  hdec -m idle_whois cnt 1
  if (!$hget(idle_whois,cnt)) { .disable #idle_whois | hfree -w idle_whois }
  halt
}
RAW *:*: halt
#idle_whois end

;$duration(12345678) = 20wks 2days 21hrs 21mins 18secs / $dur(12345678) = 20w2d21h21m18s / $dur(12345678,2) = 20w2d
ALIAS dur { return $remove($gettok($regsubex($duration($1),/(\d+\w)\S*/g,\t),1- $+ $2,32),$chr(32)) } ; by Raccoon
If it's just idle without having to have a whois script, is that possible?

Joined: Dec 2002
Posts: 254
T
Fjord artisan
Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 254
One form of simplification I could suggest is abusing regex for all this and avoid the while loops entirely.

While this doesn't go as deep as your /whois to grab sign-on time and reported server-idle, it's still a good example:
NOTE: looks bigger than what it is... remove the comments it's quite small.
Code
alias idl {
  ;== Set who we're going to check
  var %who = $1

  ;== 1st Regsubex: make a string of spaces one less than the number of common channels, replace the zero-width spots in-between with the common channel name
  ;== 2nd Regsubex: Find all "channels" within said string, replace it with [idle]:[modeprefix][channel]
  var %ret = $regsubex($regsubex($str($chr(32),$calc($comchan($me,0) -1)),//g,$comchan($me,\n)),/([^ ]+)/g,$+($nick(\1,%who).idle,:,$left($nick(\1,%who,a,r).pnick,1),\1))

  ;== prepend query/dcc-chat info to the end [idle]:[type]
  if ($query(%who)) { var %ret = %ret $+($query(%who).idle,:Query) }
  if ($chat(%who)) { var %ret = %ret $+($chat(%who).idle,:Chat) }

  ;== Regsubex: Sort all by number via $sorttok() (lowest idle) find [(digits)]:[(not space or end of string)] and reformat to <word>[<duration>]
  ;NOTE: we started each "token" with a number (idle) so we can hack $sorttok() in our favor. and use regsubex to "reformat" to your preference.
  var %ret = $regsubex($sorttok(%ret,32,n),/(\d+)\x3a([^ ]+|$)/g,$+(\2,[,$dur(\1),]))

  ;== return if called as an $identifier() else echo to active.
  ;NOTE: Here's where you could prepend your "sign-on" and "whois-idle" before %ret

  $iif($isid,return,echo -a) %ret
}

;== Forgot yours was posted in your snippet so I just whipped up this one....
alias dur { return $regsubex(dur,$duration($1),/([a-z]+|\s)/gi,$iif(\1 != $chr(32),$left(\1,1))) }

/idl Talon
+#minecraft[5m39s] Query[23m34s] %#swiftirc[24m44s] #programming[24m44s]

Joined: Dec 2002
Posts: 254
T
Fjord artisan
Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 254
Sorry, ignore my first post, I found a bug (return of ":" I didn't consider), and also forgot to replace $me with %who on the two $comchan()'s, still a good reference for the comments. I also reduced the double regex, while it was shorter character wise, it felt wasteful to use the 2nd just to reference $comchan() as \1 for the 3 spots...

Code
alias idl {
  var %who = $1 , %ret = $regsubex($str($chr(32),$calc($comchan(%who,0) -1)),//g,$+($nick($comchan(%who,\n),%who).idle,:,$left($nick($comchan(%who,\n),%who,a,r).pnick,1),$comchan(%who,\n)))

  ;== If $str(<space>,-1) (IE no common channels) we wind up with ONE zero-width spot (since $str() returned $null), which has no idle and no channel name so you wind up getting a return of ":", reset the var to null.
  if (%ret == :) { var %ret = $null }

  if ($query(%who)) { var %ret = %ret $+($query(%who).idle,:Query) }
  if ($chat(%who)) { var %ret = %ret $+($chat(%who).idle,:Chat) }

  var %ret = $regsubex($sorttok(%ret,32,n),/(\d+)\x3a([^ ]+|$)/g,$+(\2,[,$dur(\1),]))

  $iif($isid,return,echo -a) %ret
}
alias dur { return $regsubex(dur,$duration($1),/([a-z]+|\s)/gi,$iif(\1 != $chr(32),$left(\1,1))) }

/idl Talon
%#swiftirc[23m34s] +#minecraft[40m54s] Query[58m49s] #programming[59m59s]

/idl Dragon
@#swiftirc[15m3s] ~#programming[36m30s] ~#minecraft[36m30s]

Joined: Jul 2006
Posts: 4,022
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,022
Since you mentioned shorter character stuff, I'll point out that you're bringing $calc to the $str just to be able to use the empty pattern // to get the correct number of match, is the arguement there that using // as a pattern is much faster than using a pattern /C/g? Because the $regsubex that doesn't use $calc (GM of slowness) and use such a pattern would be shorter (and probably just as fast pcre wise) than what you used:



%ret = $regsubex($str($chr(32),$calc($comchan(%who,0) -1)),//g,$+($nick($comchan(%who,\n),%who).idle,:,$left($nick($comchan(%who,\n),%who,a,r).pnick,1),$comchan(%who,\n)))
vs
%ret = $regsubex($str(a,$comchan(%who,0)),/a/g,$+($nick($comchan(%who,\n),%who).idle,:,$left($nick($comchan(%who,\n),%who,a,r).pnick,1),$comchan(%who,\n)))


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 254
T
Fjord artisan
Offline
Fjord artisan
T
Joined: Dec 2002
Posts: 254
No it's more in keeping it "correct" in terms of tokens, as your replace combines them all into one garbled string, sure you could do it that way but you'd have to include $chr(32) in your regex substitution to space them out, and possibly $mid(,1,-1) to remove the trailing space at the end (if more regexes done on it which could throw off matches not accounting for the extra space at the end, token identifiers wouldn't care...)

Joined: Jul 2006
Posts: 4,022
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,022
$chr(32) can be added to the $+() and it is still shorter that way, the trailing space should be gone by itself because you're using a variable assignment which doesn't store single trailing space.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard