ZNC buffer playback

By Ryck on Jan 16, 2010

Simple ZNC buffer playback handler script r19 by László Tamás Szabó /// Ryck @ IRCnet, Freenode or EFnet

Report any bugs, ideas or suggestions to laszlo.tamas.szabo@gmail.com

This script formats the messages received from ZNC and its buffextras module to look like the default mIRC messages. You can modify its output and integrate it into other scripts by replacing znc_*_msg aliases with custom ones.

; =======================================================================
; /// ChangeLog ///
;
; r19:
; - fixed a bug when a user was connecting to multiple servers
;   %znc.mirc.* variables were reset unexpectedly causing timestamps
;   to disappear
; r18:
; - the script reads settings for timestamps, highlighting and the format of
;  join/part messages from mirc.ini, so everything is displayed in
; - obsolete menu items (Enable/disable highlighting & timestamps) are removed
; - nick coloring works as set in Address Book / Nick Colors
; - channel and status window popup menu items for clearing channel buffers
;
; r17:
; - the format of messages from buffextras now confoms to the mIRC option
;  Options / IRC / Options / "Show short joins/parts"
; - lots of cosmetic changes by tappi, including:
;   square brackets are replaced by parentheses in quit/kick messages
;   highlighting is only applied where appropriate
;   Many thanks for these!
; =======================================================================

; ======
; events
; ======

on 1:load:{
  echo -sc info * Setting up ZNC buffer playback handler...
  auser znc *!*@znc.in
  set %znc.enabled 1
}

on ^znc:text:*:#:{
  if (%znc.enabled == 1) {
    if ($nick == ***) {
      if ($1- == Buffer Playback...) {
        set -e %znc.playback. [ $+ [ $cid ] $+ . $+ [ $chan ] ] 1
        znc_read_mirc_settings
      }
      if ($1- == Playback Complete.) {
        unset %znc.playback. [ $+ [ $cid ] $+ . $+ [ $chan ] ]
      }
      ;haltdef
    }
    elseif ($nick == *buffextras) {
      if ($3 == joined) { znc_join_msg $1 $2 }
      elseif ($3 == parted) { znc_part_msg $1 $2 }
      elseif ($3 == quit) { znc_quit_msg $1 $2 $6- }
      elseif (($5 == known) && ($6 == as)) { znc_nickchange_msg $1 $2 $7 }
      elseif (($3 == set) && ($4 == mode:)) { znc_modechange_msg $1 $2 $5- }
      elseif (($3 == changed) && ($5 == topic)) { znc_topicchange_msg $1 $2 $7- }
      elseif (($3 == kicked) && ($5 == Reason:)) { znc_kick_msg $1 $2 $4 $6- }
      haltdef
    }
  }
}

on ^*:text:*:#:{
  if ((%znc.enabled == 1) && ($znc_getplayback == 1)) {
    znc_text_msg $1 $nick $2-
    haltdef
  }
}

on ^*:action:*:#:{
  if ((%znc.enabled == 1) && ($znc_getplayback == 1)) {
    znc_action_msg $1 $nick $2-
    haltdef
  }
}

on ^*:notice:*:#:{
  if ((%znc.enabled == 1) && ($znc_getplayback == 1)) {
    znc_notice_msg $1 $nick $chan $2-
    haltdef
  }
}

on *:disconnect:{
  unset %znc.playback. [ $+ [ $cid ] $+ * ]
}

; =============
; menubar items
; =============

menu menubar {
  ZNC buffer playback
  . $znc_menuitem(%znc.enabled) playback handler:znc_toggle znc.enabled
}

menu status {
  ZNC buffer playback
  .Clear all channel buffers:msg *status ClearAllChannelBuffers
}

menu channel {
  ZNC buffer playback
  .Clear channel buffer for $chan:msg *status ClearBuffer $chan
}

alias znc_toggle { if ([ % $+ [ $1 ] ] == 1) { set [ % $+ [ $1 ] ] 0 } | else { set [ % $+ [ $1 ] ] 1 }  }
alias znc_menuitem { if ($1 == 1) { return Disable } | else { return Enable } }

; ==================================
; override these for custom messages
; ==================================
; znc_text_msg        [timestamp] [nick] [message]
; znc_action_msg      [timestamp] [nick] [message]
; znc_notice_msg      [timestamp] [nick] [channel] [message]
; znc_join_msg        [timestamp] [nick!ident@host]
; znc_part_msg        [timestamp] [nick!ident@host]
; znc_quit_msg        [timestamp] [nick!ident@host] [message]
; znc_nickchange_msg  [timestamp] [nick!ident@host] [newnick]
; znc_modechange_msg  [timestamp] [nick!ident@host] [list_of_modes]
; znc_topicchange_msg [timestamp] [nick!ident@host] [topic]
; znc_kick_msg        [timestamp] [nick!ident@host] [kicked_nick] [reason]

alias znc_text_msg {
  echo -i2rn $+ $znc_gettextcolor $chan $znc_timestamp($1) < $+ $chr(3) $+ $cnick($2).color $+ $2 $+ $chr(15) $+ > $3-
}
alias znc_action_msg {
  echo -i2rn $+ $znc_getactioncolor $chan $znc_timestamp($1) * $2 $3-
}
alias znc_notice_msg {
  echo -i2rnc notice $chan $znc_timestamp($1) - $+ $2 $+ : $+ $3 $+ - $4-
}
alias znc_join_msg {
  if (%znc.mirc.shortjoins == 1) {
    echo -i2nc join $chan $znc_timestamp($1) * Joins: $znc_getnick($2) ( $+ $znc_getidenthost($2) $+ )
  }
  else {
    echo -i2nc join $chan $znc_timestamp($1) * $znc_getnick($2) ( $+ $znc_getidenthost($2) $+ ) has joined $chan
  }
}

; NOTE: unlike quit messages buffextras module ignores part messages!
alias znc_part_msg {
  if (%znc.mirc.shortjoins == 1) {
    echo -i2nc part $chan $znc_timestamp($1) * Parts: $znc_getnick($2) ( $+ $znc_getidenthost($2) $+ ) $3-
  }
  else {
    echo -i2nc part $chan $znc_timestamp($1) * $znc_getnick($2) ( $+ $znc_getidenthost($2) $+ ) has left $chan
  } 
}

alias znc_quit_msg {
  if (%znc.mirc.shortjoins == 1) {
    echo -i2nc quit $chan $znc_timestamp($1) * Quits: $znc_getnick($2) ( $+ $znc_getidenthost($2) $+ ) $znc_change_brackets($3-)
  }
  else {
    echo -i2nc quit $chan $znc_timestamp($1) * $znc_getnick($2) ( $+ $znc_getidenthost($2) $+ ) Quit $znc_change_brackets($3-)
  }
}

alias znc_nickchange_msg {
  echo -i2nc nick $chan $znc_timestamp($1) * $znc_getnick($2) is now known as $3
}

alias znc_modechange_msg {
  echo -i2nc mode $chan $znc_timestamp($1) * $znc_getnick($2) sets mode: $3-
}
alias znc_topicchange_msg {
  echo -i2nc topic $chan $znc_timestamp($1) * $znc_getnick($2) changes topic to ' $+ $3- $+ '
}
alias znc_kick_msg {
  echo -i2nc kick $chan $znc_timestamp($1) * $3 was kicked by $znc_getnick($2) $znc_change_brackets($4-)
}

; ============================
; identifiers for internal use
; ============================

alias znc_timestamp { if (%znc.mirc.timestamps == 1) return $1 | else return $null }
alias znc_getplayback { return %znc.playback. [ $+ [ $cid ] $+ . $+ [ $chan ] ] }

alias znc_gettextcolor {
  if ($nick == $me) return -c own
  else if (%znc.mirc.highlight == 1) return -lc normal | else return -c normal
}
alias znc_getactioncolor {
  if ($nick == $me) {
    if ($color(own) == 1) return -c action | else return -c own
  }
  else if (%znc.mirc.highlight == 1) return -lc action | else return -c action
}

alias znc_getnick {
  if ($pos($1, !, 0) != 0) return $left($1, $calc($pos($1, !, 1) - 1))
  else if ($pos($1, @, 0) != 0) return  $left($1, $calc($pos($1, @, 1) - 1))
  else return $1
}
alias znc_getident {
  if ($pos($1, !, 0) == 0) return $null
  var %s, %n
  %s = $pos($1, !, 1) + 1
  if ($pos($1, @, 0) == 0) %n = $len($1) - %s + 1
  else %n = $pos($1, @, 1) - %s
  return $mid($1, %s, %n)
}
alias znc_gethost {
  if ($pos($1, @, 0) == 0) return $null
  else return $right($1, $calc($len($1) - $pos($1, @, 1)))
}
alias znc_getidenthost { 
  if ($pos($1, !, 0) != 0) return $right($1, $calc($len($1) - $pos($1, !, 1)))
  else if ($pos($1, @, 0) != 0) return $right($1, $calc($len($1) - $pos($1, @, 1)))
  else return $null
}

alias znc_change_brackets {
  return ( $+ $mid($1, 2, $calc($len($1) - 2)) $+ )
}

; reads mIRC settings from mirc.ini
; more info: http://www.mirc-support.de/help/mircini/n2.htm
alias znc_read_mirc_settings {
  ; Options / IRC / Options / Show short joins/parts
  set -e %znc.mirc.shortjoins $gettok($readini($mircini,n,options,n2),19,44)
  ; Address Book / Highlight / Enable highlight
  set -e %znc.mirc.highlight $gettok($readini($mircini,n,options,n0),5,44)
  ; Options / IRC / Messages / Timestamp events
  set -e %znc.mirc.timestamps $gettok($readini($mircini,n,options,n4),12,44)
}
Sign in to comment.
janolapin   -  Jul 28, 2011

Really great with one server. But I have 3 accounts on my ZNC (for 3 servers), and on the 2nd & 3rd server my playback is like that :

Hello all What's up guys ?

Instead of

[10:25:32] Hello all [10:25:35] What's up guys ?

1st word is inverted with the nickname, and no timestamp ... Strange, isn't it ? :P

Thanks for your Job !

 Respond  
Ryck   -  Aug 11, 2010

@madninja: Sorry for the late reply :) I've fixed that bug.

 Respond  
madninja   -  Apr 10, 2010

It doesn't trigger highlights. Is it possible to fix this?

 Respond  
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.