nbs-irc icon indicating copy to clipboard operation
nbs-irc copied to clipboard

logg command does not work with a dot in the channel name

Open bw4518 opened this issue 7 months ago • 1 comments

/logg #ab.c only opens #ab log (if #ab log exists), works ok if there is no #ab log.

bw4518 avatar May 30 '25 11:05 bw4518

Ok, AI came up with a solution/workaround in https://github.com/ElectronicWar/nbs-irc/blob/master/scripts/main.nbs

➡️ The behavior depends on whether you're currently joined to the channel.

🔍 What’s Actually Happening? In your logviewer alias, when the channel is joined, this block runs first:

if ($window($1)) {
  set %lv.dir $nofile($window($1).logfile)
  var %load = $n.log($1)
}

Problem: $window(#ab.c) exists (you're joined) $window(#ab.c).logfile returns something like: C:\mIRC\logs\network#ab.log instead of #ab.c.log ❌

Why? Because mIRC assigns the same logfile to similar-looking channel names if not explicitly configured

This causes: $n.log($1) to return the wrong file %load to be set incorrectly Your fallback elseif logic never runs since the if ($window(...)) matched first

✅ Solution: Prioritize Exact Match Instead of Relying on $window() We need to skip the $window($1) path if it doesn't actually point to the correct log file. Here's a safe and robust way to do that.

alias logviewer {
  if ($window(@logviewer)) {
    window -a @logviewer
    return
  }

  set %lv.dir $logdir
  var %chan = $1-

  ; Try to build an exact path first
  var %exactlog = $logdir $+ $network $+ \ $+ %chan $+ .log

  ; If the exact log file exists, use it
  if ($exists(%exactlog)) {
    set %lv.dir $logdir $+ $network $+ \
    var %load = %exactlog
  }
  ; Otherwise, fallback to $window() method (only if necessary)
  elseif ($window(%chan)) {
    set %lv.dir $nofile($window(%chan).logfile)
    var %load = $n.log(%chan)
  }

  window -l25eazk0 @Logviewer

  if (%load) aline -l @logviewer $chr(91) .. $chr(93)

  var %a = $finddir(%lv.dir,*,0,1,aline -l @logviewer $chr(91) $nopath($1-) $chr(93))
  var %b = $findfile(%lv.dir,*.log,0,1,aline -l @logviewer $nopath($1-))

  if (%load) {
    if ($file(%load).size > 10000000) {
      if (!$n.input(This is a very large log file ( $+ $round($calc($file(%load).size /1024/1024),2) MB) $+ $c44 loading will take some time. Do you want to continue?,y/n)) return
    }
    echo @logviewer $npre loading %load $+ ...
    loadbuf -pi4 @logviewer $+(",%load,")
    echo @logviewer $npre $kl:($nopath(%load)) $lines(%load) lines, $round($calc($file(%load).size /1024),2) KB
  }

  ; %b log files and %a folders found in %lv.dir
}

bw4518 avatar May 31 '25 10:05 bw4518