NextInLine for mIRC (hop to channel with unread messages)

By Tritonio on Jan 08, 2015

Pressing F4 will take you to a channel with unread messages. A very fast way to hop from channel to channel talking to many people. Should work with private messages too but the whole script hasn't been tested a lot.

EDIT: It now works with Query windows too.

;NextInLine by Tritonio

alias F4 {
  var %i = 1
  var %winner = none
  var %best = $ticks
  while ($hget(firstnotseen, %i).item) {
    var %value = $hget(firstnotseen,$v1)
    var %index = $v1
    if (%value < %best) {
      %best = %value
      %winner = %index
    }
    inc %i
  }
  if (%winner == none) {
    echo 13 -ga Can't find a room with new messages.
  }
  else {
    tokenize 126 %winner
    hdel firstnotseen %winner
    echo 13 -ga =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    ;echo 13 -gs Moved to %winner
    scid $$1
    var %l = $left($$2 ,1)
    if ( %l == $!(#) ) {
      join $$2
    }
    else {
      query $$2
    }
  }
}

on *:START:{
  hmake firstnotseen 15
}

on *:ACTIVE:*: {
  hdel firstnotseen $+($cid,~,$active)
}

on *:TEXT:*:*: {
  var %title
  if ($chan) {
    %title = $chan
  }
  else {
    %title = $nick
  }
  if (%title != $active) {
    var %index = $+($cid,~,%title)
    ;echo -gs %index
    if (!$hget(firstnotseen,%index)) {
      hadd firstnotseen $+($cid,~,%title) $ticks
      ;echo 13 -gs Added $+($cid,~,%title) $ticks
    }
  }
}

Comments

Sign in to comment.
raccoon   -  Jan 10, 2015

What ordering are you using to determine the next channel to hop to?

Yawhatnever  -  Jan 10, 2015

It looks like it goes to the channel with the oldest unseen message.

raccoon  -  Jan 10, 2015

This version doesn't keep track of any hash tables. It merely looks for windows with a message or highlight switchbar color, and compares their idle times for the highest value. Highlights take priority. It works across multiple server connections for windows of all types: channels, queries, chats, and then any other window-type that has an /echo -m color. It keeps 2 temporary global variables that expire after 2 seconds.

F4 { unset %_f4.* | scon -a _F4 | if (%_f4.wid) window -a $v1 }
_F4 { ; by Raccoon 2015
  var %i = 1
  while ($window(*,%i)) {
    var %win = $v1, %wid = @ $+ $window(%win).wid
    if ($chan(%win).idle) || ($query(%win).idle) $&
      || $calc($chat(%win).idle) { var %idle = $v1 }
    if ($window(%wid).sbcolor == highlight) { 
      set -eu2 %_f4.wid %wid | set -eu2 %_f4.idle 999999
      break 
    }
    if ($v1 == message) && ((!%_f4.wid) || (%idle > %_f4.idle)) {
      set -eu2 %_f4.wid %wid | set -eu2 %_f4.idle %idle
    }
    inc %i
} }
Tritonio  -  Jan 11, 2015

If you join the version with the highest idle, and you take your time between calls of the script, your cycle over the windows might miss some for a loooong time if they are getting a lot of messages very fast.

If you join the lowest idle time, you might miss windows that have messages in them in favour of those that are getting a lot of new messages right now. Unless of course you call your script fast enough, which you won't if you have many channels open.

If you use the ticks of the oldest unread message, you are guaranteed to cycle over all windows with unread messages regardless of how often you call your script.

But I didn't know about the .idle before yesterday when you showed me that other script of your. hehe. Thanks Racoon.

biase  -  Feb 16, 2015

nice idea

raccoon  -  Apr 13, 2015

I would say a better way is to create a single variable with a tokenized list of channel @wids that are $addtok'd with On Text. As $addtok won't add a duplicate, the list should only build as new unread messages come in, and you can pop them off the beginning of the list On Active. It wouldn't be a stand-alone alias, but would only require those two events.

Sign in to comment

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.