2 # highmon.pl - Highlight Monitoring for weechat 0.3.0 
   5 # Add 'Highlight Monitor' buffer/bar to log all highlights in one spot 
   8 # /highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar 
   9 #  Command wrapper for highmon commands 
  11 # /highmon clean default|orphan|all will clean the config section of default 'on' entries, 
  12 #  channels you are no longer joined, or both 
  14 # /highmon clearbar will clear the contents of highmon's bar output 
  16 # /highmon monitor [channel] [server] is used to toggle a highlight monitoring on and off, this 
  17 #  can be used in the channel buffer for the channel you wish to toggle, or be given 
  18 #  with arguments e.g. /highmon monitor #weechat freenode 
  20 # /set plugins.var.perl.highmon.alignment 
  21 #  The config setting "alignment" can be changed to; 
  22 #  "channel", "schannel", "nchannel", "channel,nick", "schannel,nick", "nchannel,nick" 
  23 #  to change how the monitor appears 
  24 #  The 'channel'  value will show: "#weechat" 
  25 #  The 'schannel' value will show: "6" 
  26 #  The 'nchannel' value will show: "6:#weechat" 
  28 # /set plugins.var.perl.highmon.short_names 
  29 #  Setting this to 'on' will trim the network name from highmon, ala buffers.pl 
  31 # /set plugins.var.perl.highmon.merge_private 
  32 #  Setting this to 'on' will merge private messages to highmon's display 
  34 # /set plugins.var.perl.highmon.color_buf 
  35 #  This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name. 
  36 #  This *must* be a valid color name, or weechat will likely do unexpected things :) 
  38 # /set plugins.var.perl.highmon.hotlist_show 
  39 #  Setting this to 'on' will let the highmon buffer appear in hotlists 
  40 #  (status bar/buffer.pl) 
  42 # /set plugins.var.perl.highmon.away_only 
  43 #  Setting this to 'on' will only put messages in the highmon buffer when 
  44 #  you set your status to away 
  46 # /set plugins.var.perl.highmon.logging 
  47 #  Toggles logging status for highmon buffer (default: off) 
  49 # /set plugins.var.perl.highmon.output 
  50 #  Changes where output method of highmon; takes either "bar" or "buffer" (default; buffer) 
  51 # /set plugins.var.perl.highmon.bar_lines 
  52 #  Changes the amount of lines the output bar will hold. 
  53 #  (Only appears once output has been set to bar, defaults to 10) 
  54 # /set plugins.var.perl.highmon.bar_scrolldown 
  55 #  Toggles the bar scrolling at the bottom when new highlights are received 
  56 #  (Only appears once output has been set to bar, defaults to off) 
  58 # /set plugins.var.perl.highmon.nick_prefix 
  59 # /set plugins.var.perl.highmon.nick_suffix 
  60 #  Sets the prefix and suffix chars in the highmon buffer 
  61 #  (Defaults to <> if nothing set, and blank if there is) 
  64 #  servername is the internal name for the server (set when you use /server add) 
  65 #  #channel is the channel name, (where # is whatever channel type that channel happens to be) 
  67 # Optional, set up tweaks; Hide the status and input lines on highmon 
  69 # /set weechat.bar.status.conditions "${window.buffer.full_name} != perl.highmon" 
  70 # /set weechat.bar.input.conditions "${window.buffer.full_name} != perl.highmon" 
  73 # Bugs and feature requests at: https://github.com/KenjiE20/highmon 
  76 # 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>: 
  77 #       v2.5:   -add: clearbar command to clear bar output 
  78 #                       -add: firstrun output prompt to check the help text for set up hints as they were being missed 
  79 #                       and update hint for conditions to use eval 
  80 #                       -change: Make all outputs use the date callback for more accurate timestamps (thanks Germainz) 
  81 # 2013-12-04, KenjiE20 <longbow@longbowslair.co.uk>: 
  82 #       v2.4:   -add: Support for eval style colour codes in time format used for bar output 
  83 # 2013-10-22, KenjiE20 <longbow@longbowslair.co.uk>: 
  84 #       v2.3.3.2:       -fix: Typo in fix command 
  85 # 2013-10-10, KenjiE20 <longbow@longbowslair.co.uk>: 
  86 #       v2.3.3.1:       -fix: Typo in closed buffer warning 
  87 # 2013-10-07, KenjiE20 <longbow@longbowslair.co.uk>: 
  88 #       v2.3.3: -add: Warning and fixer for accidental buffer closes 
  89 # 2013-01-15, KenjiE20 <longbow@longbowslair.co.uk>: 
  90 #       v2.3.2: -fix: Let bar output use the string set in weechat's config option 
  92 # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>: 
  93 #       v2.3.1: -fix: Colour tags in bar timestamp string 
  94 # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>: 
  95 #       v2.3:   -feature: Added merge_private option to display private messages (default: off) 
  96 #                       -fix: Channel name colours now show correctly when set to on 
  97 # 2011-08-07, Sitaktif <romainchossart_at_gmail.com>: 
  98 #       v2.2.1: -feature: Add "bar_scrolldown" option to have the bar display the latest hl at anytime 
  99 #                       -fix: Set up bar-specific config at startup if 'output' is already configured as 'bar' 
 100 # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>: 
 101 #       v2.2:   -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours 
 102 # 2010-12-13, idl0r & KenjiE20 <longbow@longbowslair.co.uk>: 
 103 #       v2.1.3: -fix: perl errors caused by bar line counter 
 104 #                       -fix: Add command list to inbuilt help 
 105 # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>: 
 106 #       v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing) 
 107 #                       -version sync w/ chanmon 
 108 # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>: 
 109 #       v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name 
 110 # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>: 
 111 #       v2.0:   Release as version 2.0 
 112 # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>: 
 113 #       v1.9:   Rewrite for v2.0 
 114 #               Bring feature set in line with chanmon 2.0 
 115 #               -code change: Made more subs to shrink the code down in places 
 116 #               -fix: Stop highmon attempting to double load/hook 
 117 #               -fix: Add version dependant check for away status 
 118 # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>: 
 119 #       v1.7:   -fixture: Let highmon be aware of nick_prefix/suffix 
 120 #                       and allow custom prefix/suffix for chanmon buffer 
 121 #                       (Defaults to <> if nothing set, and blank if there is) 
 122 #               (Thanks to m4v for these) 
 123 # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>: 
 124 #       v1.6:   -feature: colored buffer names 
 125 #               -change: version sync with chanmon 
 126 # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>: 
 127 #       v1.2:   -fix: disable buffer highlight 
 128 # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>: 
 129 #       v.1.1.1 -change: Stop unsightly text block on '/help' 
 130 # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>: 
 131 #       v1.1:   In-client help added 
 132 # 2009-08-02, KenjiE20 <longbow@longbowslair.co.uk>: 
 133 #       v1.0:   Initial Public Release 
 135 # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk> 
 137 # This program is free software; you can redistribute it and/or modify 
 138 # it under the terms of the GNU General Public License as published by 
 139 # the Free Software Foundation; either version 3 of the License, or 
 140 # (at your option) any later version. 
 142 # This program is distributed in the hope that it will be useful, 
 143 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 144 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 145 # GNU General Public License for more details. 
 147 # You should have received a copy of the GNU General Public License 
 148 # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 152 @bar_lines_time = (); 
 153 # Replicate info earlier for in-client help 
 155 $highmonhelp = weechat
::color
("bold")."/highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar".weechat
::color
("-bold")." 
 156  Command wrapper for highmon commands 
 158 ".weechat
::color
("bold")."/highmon clean default|orphan|all".weechat
::color
("-bold")." will clean the config section of default 'on' entries, channels you are no longer joined, or both 
 160 ".weechat
::color
("bold")."/highmon clearbar".weechat
::color
("-bold")." will clear the contents of highmon's bar output 
 162 ".weechat
::color
("bold")."/highmon monitor [channel] [server]".weechat
::color
("-bold")." is used to toggle a highlight monitoring on and off, this can be used in the channel buffer for the channel you wish to toggle, or be given with arguments e.g. /highmon monitor #weechat freenode 
 164 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.alignment".weechat
::color
("-bold")." 
 165  The config setting \"alignment\" can be changed to; 
 166  \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\" 
 167  to change how the monitor appears 
 168  The 'channel'  value will show: \"#weechat\" 
 169  The 'schannel' value will show: \"6\" 
 170  The 'nchannel' value will show: \"6:#weechat\" 
 172 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.short_names".weechat
::color
("-bold")." 
 173  Setting this to 'on' will trim the network name from highmon, ala buffers.pl 
 175 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.merge_private".weechat
::color
("-bold")." 
 176  Setting this to 'on' will merge private messages to highmon's display 
 178 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.color_buf".weechat
::color
("-bold")." 
 179  This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name. 
 180  This ".weechat
::color
("bold")."must".weechat
::color
("-bold")." be a valid color name, or weechat will likely do unexpected things :) 
 182 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.hotlist_show".weechat
::color
("-bold")." 
 183 Setting this to 'on' will let the highmon buffer appear in hotlists (status bar/buffer.pl) 
 185 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.away_only".weechat
::color
("-bold")." 
 186 Setting this to 'on' will only put messages in the highmon buffer when you set your status to away 
 188 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.logging".weechat
::color
("-bold")." 
 189  Toggles logging status for highmon buffer (default: off) 
 191 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.output".weechat
::color
("-bold")." 
 192  Changes where output method of highmon; takes either \"bar\" or \"buffer\" (default; buffer) 
 193 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_lines".weechat
::color
("-bold")." 
 194  Changes the amount of lines the output bar will hold. 
 195  (Only appears once output has been set to bar, defaults to 10) 
 196 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_scrolldown".weechat
::color
("-bold")." 
 197  Toggles the bar scrolling at the bottom when new highlights are received 
 198  (Only appears once output has been set to bar, defaults to off) 
 200 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_prefix".weechat
::color
("-bold")." 
 201 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_suffix".weechat
::color
("-bold")." 
 202  Sets the prefix and suffix chars in the highmon buffer 
 203  (Defaults to <> if nothing set, and blank if there is) 
 205 ".weechat
::color
("bold")."servername.#channel".weechat
::color
("-bold")." 
 206  servername is the internal name for the server (set when you use /server add) 
 207  #channel is the channel name, (where # is whatever channel type that channel happens to be) 
 209 ".weechat
::color
("bold")."Optional, set up tweaks;".weechat
::color
("-bold")." Hide the status and input lines on highmon 
 211 ".weechat
::color
("bold")."/set weechat.bar.status.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat
::color
("-bold")." 
 212 ".weechat
::color
("bold")."/set weechat.bar.input.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat
::color
("-bold"); 
 216         weechat
::print("", "\t".weechat
::color
("bold")."Highmon Help".weechat
::color
("-bold")."\n\n"); 
 217         weechat
::print("", "\t".$highmonhelp); 
 218         return weechat
::WEECHAT_RC_OK
; 
 222 sub highmon_bar_build
 
 225         $max_lines = weechat
::config_get_plugin
("bar_lines"); 
 226         $max_lines = $max_lines ? $max_lines : 10; 
 230         # Keep lines within max 
 231         while ($#bar_lines > $max_lines) 
 234                 shift(@bar_lines_time); 
 236         # So long as we have some lines, build a string 
 240                 $sep = " ".weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_suffix"))." "; 
 243                         # Find max align needed 
 244                         $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep)); 
 245                         $align_num = $prefix_num if ($prefix_num > $align_num); 
 249                         # Get align for this line 
 250                         $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep)); 
 253                         $str = $str.$bar_lines_time[$count]." ".(" " x 
($align_num - $prefix_num)).$_."\n"; 
 254                         # Increment count for sync with time list 
 265         weechat
::bar_item_new
("highmon", "highmon_bar_build", ""); 
 267         $highmon_bar = weechat
::bar_new 
("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "highmon"); 
 269         return weechat
::WEECHAT_RC_OK
; 
 272 sub highmon_bar_close
 
 275         $highmon_bar = weechat
::bar_search
("highmon"); 
 276         # If is does, close it 
 277         if ($highmon_bar ne "") 
 279                 weechat
::bar_remove
($highmon_bar); 
 282         # Find if bar item exists 
 283         $highmon_bar_item = weechat
::bar_item_search
("highmon_bar"); 
 284         # If is does, close it 
 285         if ($highmon_bar_item ne "") 
 287                 weechat
::bar_remove
($highmon_bar_item); 
 291         return weechat
::WEECHAT_RC_OK
; 
 295 sub highmon_buffer_open
 
 297         # Search for pre-existing buffer 
 298         $highmon_buffer = weechat
::buffer_search
("perl", "highmon"); 
 301         if ($highmon_buffer eq "") 
 303                 $highmon_buffer = weechat
::buffer_new
("highmon", "highmon_buffer_input", "", "highmon_buffer_close", ""); 
 306         # Turn off notify, highlights 
 307         if ($highmon_buffer ne "") 
 309                 if (weechat
::config_get_plugin
("hotlist_show" eq "off")) 
 311                         weechat
::buffer_set
($highmon_buffer, "notify", "0"); 
 313                 weechat
::buffer_set
($highmon_buffer, "highlight_words", "-"); 
 314                 weechat
::buffer_set
($highmon_buffer, "title", "Highlight Monitor"); 
 316                 if (weechat
::config_get_plugin
("logging") eq "off") 
 318                         weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1"); 
 321         return weechat
::WEECHAT_RC_OK
; 
 323 # Buffer input has no action 
 324 sub highmon_buffer_input
 
 326         return weechat
::WEECHAT_RC_OK
; 
 329 sub highmon_buffer_close
 
 331         $highmon_buffer = ""; 
 332         # If user hasn't changed output style warn user 
 333         if (weechat
::config_get_plugin
("output") eq "buffer") 
 335                 weechat
::print("", "\tHighmon buffer has been closed but output is still set to buffer, unusual results may occur. To recreate the buffer use ".weechat
::color
("bold")."/highmon fix".weechat
::color
("-bold")); 
 337         return weechat
::WEECHAT_RC_OK
; 
 340 # Highmon command wrapper 
 341 sub highmon_command_cb
 
 352                 @arg_array = split(/ /,$args); 
 353                 # Take first as command 
 354                 $cmd = shift(@arg_array); 
 355                 # Rebuild string to pass to subs 
 358                         $arg = join(" ", @arg_array); 
 363         if ($cmd eq "" || $cmd eq "help") 
 368         elsif ($cmd eq "monitor") 
 370                 highmon_toggle
($data, $buffer, $arg); 
 373         elsif ($cmd eq "clean") 
 375                 highmon_config_clean
($data, $buffer, $arg); 
 378         elsif ($cmd eq "clearbar") 
 380                 if (weechat
::config_get_plugin
("output") eq "bar") 
 383                         weechat
::bar_item_update
("highmon"); 
 387         elsif ($cmd eq "fix") 
 389                 if (weechat
::config_get_plugin
("output") eq "buffer" && $highmon_buffer eq "") 
 391                         highmon_buffer_open
(); 
 394         return weechat
::WEECHAT_RC_OK
; 
 397 # Clean up config entries 
 398 sub highmon_config_clean
 
 404         # Don't do anything if bad option given 
 405         if ($args ne "default" && $args ne "orphan"  && $args ne "all") 
 407                 weechat
::print("", "\thighmon.pl: Unknown option"); 
 408                 return weechat
::WEECHAT_RC_OK
; 
 412         # Load an infolist of highmon options 
 413         $infolist = weechat
::infolist_get
("option", "", "*highmon*"); 
 414         while (weechat
::infolist_next
($infolist)) 
 416                 $name = weechat
::infolist_string
($infolist, "option_name"); 
 417                 $name =~ s/perl\.highmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/; 
 418                 if ($name =~ /^(.*)\.([#&\+!])(.*)$/) 
 422                         if ($args eq "default" || $args eq "all") 
 424                                 # If value in config is "on" 
 425                                 if (weechat
::config_get_plugin
($name) eq "on") 
 427                                         # Unset and if successful flag as changed 
 428                                         $rc = weechat
::config_unset_plugin
($name); 
 429                                         if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
) 
 436                         if ($args eq "orphan" || $args eq "all") 
 438                                 # If we can't find the buffer for this entry 
 439                                 if (weechat
::buffer_search
("irc", $name) eq "") 
 441                                         # Unset and if successful flag as changed 
 442                                         $rc = weechat
::config_unset_plugin
($name); 
 443                                         if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
) 
 449                         # Add changed entry names to list 
 450                         push (@chans, $name) if ($action); 
 453         weechat
::infolist_free
($infolist); 
 454         # If channels were cleaned from config 
 460                         $str = "\thighmon.pl: Cleaned ".@chans." entry from the config:"; 
 464                         $str = "\thighmon.pl: Cleaned ".@chans." entries from the config:"; 
 466                 # Build a list of channels 
 471                 # Print what happened 
 472                 weechat
::print("",$str); 
 474         # Config seemed to be clean 
 477                 weechat
::print("", "\thighmon.pl: No entries removed"); 
 479         return weechat
::WEECHAT_RC_OK
; 
 482 # Check config elements 
 483 sub highmon_config_init
 
 486         if (!(weechat
::config_is_set_plugin 
("first_run"))) 
 488                 if (weechat
::config_get_plugin
("first_run") ne "true") 
 490                         weechat
::print("", "\tThis appears to be the first time highmon has been run. For help and common set up hints see /highmon help"); 
 491                         weechat
::config_set_plugin
("first_run", "true"); 
 495         if (!(weechat
::config_is_set_plugin 
("alignment"))) 
 497                 weechat
::config_set_plugin
("alignment", "channel"); 
 499         if (weechat
::config_get_plugin
("alignment") eq "") 
 501                 weechat
::config_set_plugin
("alignment", "none"); 
 505         if (!(weechat
::config_is_set_plugin 
("short_names"))) 
 507                 weechat
::config_set_plugin
("short_names", "off"); 
 510         # Coloured names default 
 511         if (!(weechat
::config_is_set_plugin 
("color_buf"))) 
 513                 weechat
::config_set_plugin
("color_buf", "on"); 
 516         # Hotlist show default 
 517         if (!(weechat
::config_is_set_plugin 
("hotlist_show"))) 
 519                 weechat
::config_set_plugin
("hotlist_show", "off"); 
 523         if (!(weechat
::config_is_set_plugin 
("away_only"))) 
 525                 weechat
::config_set_plugin
("away_only", "off"); 
 528         # highmon log default 
 529         if (!(weechat
::config_is_set_plugin 
("logging"))) 
 531                 weechat
::config_set_plugin
("logging", "off"); 
 535         if (!(weechat
::config_is_set_plugin 
("output"))) 
 537                 weechat
::config_set_plugin
("output", "buffer"); 
 540         # Private message merging 
 541         if (!(weechat
::config_is_set_plugin 
("merge_private"))) 
 543                 weechat
::config_set_plugin
("merge_private", "off"); 
 546         # Set bar config in case output was set to "bar" before even changing the setting 
 547         if (weechat
::config_get_plugin
("output") eq "bar") 
 549                 # Output bar lines default 
 550                 if (!(weechat
::config_is_set_plugin 
("bar_lines"))) 
 552                         weechat
::config_set_plugin
("bar_lines", "10"); 
 554                 if (!(weechat
::config_is_set_plugin 
("bar_scrolldown"))) 
 556                         weechat
::config_set_plugin
("bar_scrolldown", "off"); 
 560         # Check for exisiting prefix/suffix chars, and setup accordingly 
 561         $prefix = weechat
::config_get
("irc.look.nick_prefix"); 
 562         $prefix = weechat
::config_string
($prefix); 
 563         $suffix = weechat
::config_get
("irc.look.nick_suffix"); 
 564         $suffix = weechat
::config_string
($suffix); 
 566         if (!(weechat
::config_is_set_plugin
("nick_prefix"))) 
 568                 if ($prefix eq "" && $suffix eq "") 
 570                         weechat
::config_set_plugin
("nick_prefix", "<"); 
 574                         weechat
::config_set_plugin
("nick_prefix", ""); 
 578         if (!(weechat
::config_is_set_plugin
("nick_suffix"))) 
 580                 if ($prefix eq "" && $suffix eq "") 
 582                         weechat
::config_set_plugin
("nick_suffix", ">"); 
 586                         weechat
::config_set_plugin
("nick_suffix", ""); 
 592 sub highmon_config_cb
 
 598         $name =~ s/^plugins\.var\.perl\.highmon\.//; 
 600         # Set logging on buffer 
 601         if ($name eq "logging") 
 603                 # Search for pre-existing buffer 
 604                 $highmon_buffer = weechat
::buffer_search
("perl", "highmon"); 
 607                         weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1"); 
 611                         weechat
::buffer_set
($highmon_buffer, "localvar_del_no_log", ""); 
 615         elsif ($name eq "output") 
 619                         # Search for pre-existing buffer 
 620                         $highmon_buffer = weechat
::buffer_search
("perl", "highmon"); 
 622                         if ($highmon_buffer ne "") 
 624                                 weechat
::buffer_close
($highmon_buffer) 
 627                         # Output bar lines default 
 628                         if (!(weechat
::config_is_set_plugin 
("bar_lines"))) 
 630                                 weechat
::config_set_plugin
("bar_lines", "10"); 
 632                         if (!(weechat
::config_is_set_plugin 
("bar_scrolldown"))) 
 634                                 weechat
::config_set_plugin
("bar_scrolldown", "off"); 
 636                         # Make a bar if doesn't exist 
 639                 elsif ($value eq "buffer") 
 641                         # If a bar exists, close it 
 644                         highmon_buffer_open
(); 
 648         # Change if hotlist config changes 
 649         elsif ($name eq "hotlist_show") 
 651                 # Search for pre-existing buffer 
 652                 $highmon_buffer = weechat
::buffer_search
("perl", "highmon"); 
 653                 if ($value eq "off" && $highmon_buffer) 
 655                         weechat
::buffer_set
($highmon_buffer, "notify", "0"); 
 657                 elsif ($value ne "off" && $highmon_buffer) 
 659                         weechat
::buffer_set
($highmon_buffer, "notify", "3"); 
 662         elsif ($name eq "weechat.look.prefix_suffix") 
 664                 if (weechat
::config_get_plugin
("output") eq "bar") 
 667                         weechat
::print("", "\thighmon: weechat.look.prefix_suffix changed, clearing highmon bar"); 
 668                         weechat
::bar_item_update
("highmon"); 
 671         return weechat
::WEECHAT_RC_OK
; 
 674 # Set up weechat hooks / commands 
 677         weechat
::hook_print
("", "", "", 0, "highmon_new_message", ""); 
 678         weechat
::hook_command
("highclean", "Highmon config clean up", "default|orphan|all", " default: Cleans all config entries with the default \"on\" value\n  orphan: Cleans all config entries for channels you aren't currently joined\n     all: Does both defaults and orphan", "default|orphan|all", "highmon_config_clean", ""); 
 680         weechat
::hook_command
("highmon", "Highmon help", "[help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar", "    help: Print help on config options for highmon\n monitor: Toggles monitoring for a channel\n   clean: Highmon config clean up (/highclean)\nclearbar: Clear Highmon bar", "help || monitor %(irc_channels) %(irc_servers) || clean default|orphan|all || clearbar", "highmon_command_cb", ""); 
 682         weechat
::hook_config
("plugins.var.perl.highmon.*", "highmon_config_cb", ""); 
 683         weechat
::hook_config
("weechat.look.prefix_suffix", "highmon_config_cb", ""); 
 686 # Main body, Callback for hook_print 
 687 sub highmon_new_message
 
 693         my $window_displayed = ""; 
 697 #       $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7]; 
 698 #       weechat::print("", "\t".$string); 
 709         # Only work on highlighted messages or private message when enabled 
 710         if ($cb_high == "1" || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/)) 
 712                 # Pre bug #29618 (0.3.3) away detect 
 713                 if (weechat
::info_get
("version_number", "") <= 197120) 
 716                         # Get infolist for this server 
 717                         $infolist = weechat
::infolist_get
("irc_server", "", weechat
::buffer_get_string
($cb_bufferp, "localvar_server")); 
 718                         while (weechat
::infolist_next
($infolist)) 
 720                                 # Get away message is is_away is on 
 721                                 $away = weechat
::infolist_string
($infolist, "away_message") if (weechat
::infolist_integer
($infolist, "is_away")); 
 723                         weechat
::infolist_free
($infolist); 
 725                 # Post bug #29618 fix 
 728                         $away = weechat
::buffer_get_string
($cb_bufferp, "localvar_away"); 
 730                 if (weechat
::config_get_plugin
("away_only") ne "on" || ($away ne "")) 
 732                         # Check buffer name is an IRC channel 
 733                         $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name'); 
 734                         if ($bufname =~ /(.*)\.([#&\+!])(.*)/) 
 736                                 # Are we running on this channel 
 737                                 if (weechat
::config_get_plugin
($bufname) ne "off" && $cb_disp eq "1") 
 740                                         # Line isn't action or topic notify 
 741                                         if (!($cb_tags =~ /irc_action/) && !($cb_tags =~ /irc_topic/)) 
 744                                                 $uncolnick = weechat
::string_remove_color
($cb_prefix, ""); 
 746                                                 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix"); 
 749                                         elsif ($cb_tags =~ /irc_topic/) 
 751                                                 $nick = " ".$cb_prefix.weechat
::color
("reset"); 
 756                                                 $uncolnick = weechat
::string_remove_color
($cb_prefix, ""); 
 757                                                 $nick = weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset"); 
 760                                         highmon_print 
($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags); 
 763                         # Or is private message 
 764                         elsif (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/) 
 767                                 $uncolnick = weechat
::buffer_get_string
($cb_bufferp, 'short_name'); 
 769                                 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix"); 
 771                                 highmon_print 
($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags); 
 775         return weechat
::WEECHAT_RC_OK
; 
 778 # Output formatter and printer takes (msg bufpointer nick) 
 782         my $cb_bufferp = $_[1] if ($_[1]); 
 783         my $nick = $_[2] if ($_[2]); 
 784         my $cb_date = $_[3] if ($_[3]); 
 785         my $cb_tags = $_[4] if ($_[4]); 
 787         #Normal channel message 
 788         if ($cb_bufferp && $nick) 
 791                 $bufname = format_buffer_name
($cb_bufferp); 
 793                 # If alignment is #channel | nick msg 
 794                 if (weechat
::config_get_plugin
("alignment") eq "channel") 
 796                         $nick =~ s/\s(.*)/$1/; 
 798                         $outstr = $bufname."\t".$nick." ".$cb_msg; 
 800                 # or if it is channel number | nick msg 
 801                 elsif (weechat
::config_get_plugin
("alignment") eq "schannel") 
 803                         $nick =~ s/\s(.*)/$1/; 
 804                         # Use channel number instead 
 805                         $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset"); 
 807                         $outstr = $bufname."\t".$nick." ".$cb_msg; 
 809                 # or if it is number:#channel | nick msg 
 810                 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel") 
 812                         $nick =~ s/\s(.*)/$1/; 
 813                         # Place channel number in front of formatted name 
 814                         $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname; 
 816                         $outstr = $bufname."\t".$nick." ".$cb_msg; 
 818                 # or if it is #channel nick | msg 
 819                 elsif (weechat
::config_get_plugin
("alignment") eq "channel,nick") 
 822                         $outstr = $bufname.":".$nick."\t".$cb_msg; 
 824                 # or if it is channel number nick | msg 
 825                 elsif (weechat
::config_get_plugin
("alignment") eq "schannel,nick") 
 827                         # Use channel number instead 
 828                         $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset"); 
 830                         $outstr = $bufname.":".$nick."\t".$cb_msg; 
 832                 # or if it is number:#channel nick | msg 
 833                 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel,nick") 
 835                         # Place channel number in front of formatted name 
 836                         $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname; 
 838                         $outstr = $bufname.":".$nick."\t".$cb_msg; 
 840                 # or finally | #channel nick msg 
 844                         $outstr = "\t".$bufname.":".$nick." ".$cb_msg; 
 847         # highmon channel toggle message 
 848         elsif ($cb_bufferp && !$nick) 
 851                 $bufname = format_buffer_name
($cb_bufferp); 
 853                 # If alignment is #channel * | * 
 854                 if (weechat
::config_get_plugin
("alignment") =~ /channel/) 
 856                         # If it's actually channel number * | * 
 857                         if (weechat
::config_get_plugin
("alignment") =~ /schannel/) 
 859                                 # Use channel number instead 
 860                                 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset"); 
 862                         # Or if it's actually number:#channel * | * 
 863                         if (weechat
::config_get_plugin
("alignment") =~ /nchannel/) 
 865                                 # Place channel number in front of formatted name 
 866                         $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname; 
 868                         $outstr = $bufname."\t".$cb_msg; 
 870                 # or if alignment is | * 
 873                         $outstr = $bufname.": ".$cb_msg; 
 877         elsif (!$cb_bufferp && !$nick) 
 879                 $outstr = "\t".$cb_msg; 
 882         # Send string to buffer 
 883         if (weechat
::config_get_plugin
("output") eq "buffer") 
 885                 # Search for and confirm buffer 
 886                 $highmon_buffer = weechat
::buffer_search
("perl", "highmon"); 
 890                         weechat
::print_date_tags
($highmon_buffer, $cb_date, $cb_tags, $outstr); 
 894                         weechat
::print($highmon_buffer, $outstr); 
 897         elsif (weechat
::config_get_plugin
("output") eq "bar") 
 900                 use POSIX 
qw(strftime); 
 903                         $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime($cb_date)); 
 907                         $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime); 
 910                 if ($time =~ /\$\{(?:color:)?[\w,]+\}/) # Coloured string 
 912                         while ($time =~ /\$\{(?:color:)?([\w,]+)\}/) 
 914                                 $color = weechat
::color
($1); 
 915                                 $time =~ s/\$\{(?:color:)?[\w,]+\}/$color/; 
 917                         $time .= weechat
::color
("reset"); 
 919                 else # Default string 
 921                         $colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_time_delimiters"))); 
 922                         $reset = weechat
::color
("reset"); 
 923                         $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g; 
 925                 # Push updates to bar lists 
 926                 push (@bar_lines_time, $time); 
 929                 $delim = " ".weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_delimiters"))).weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_suffix")).weechat
::color
("reset")." "; 
 930                 $outstr =~ s/\t/$delim/; 
 932                 push (@bar_lines, $outstr); 
 934                 weechat
::bar_item_update
("highmon"); 
 936                 if (weechat
::config_get_plugin
("bar_scrolldown") eq "on") 
 938                         weechat
::command
("", "/bar scroll highmon * ye") 
 943 # Start the output display 
 946         if (weechat
::config_get_plugin
("output") eq "buffer") 
 948                 highmon_buffer_open
(); 
 950         elsif (weechat
::config_get_plugin
("output") eq "bar") 
 956 # Takes two optional args (channel server), toggles monitoring on/off 
 963         # Check if we've been told what channel to act on 
 967                 @arg_array = split(/ /,$args); 
 968                 # Check if a server was given 
 972                         $bufp = weechat
::buffer_search
("irc", $arg_array[1].".".$arg_array[0]); 
 977                         # Loop through defined servers 
 978                         $infolist = weechat
::infolist_get
("buffer", "", ""); 
 979                         while (weechat
::infolist_next
($infolist)) 
 981                                 # Only interesting in IRC buffers 
 982                                 if (weechat
::infolist_string
($infolist, "plugin_name") eq "irc") 
 984                                         # Find buffers that maych 
 985                                         $sname = weechat
::infolist_string
($infolist, "short_name"); 
 986                                         if ($sname eq $arg_array[0]) 
 989                                                 $bufp = weechat
::infolist_pointer
($infolist, "pointer"); 
 993                         weechat
::infolist_free
($infolist); 
 994                         # If the infolist found more than one channel, halt as we need to know which one 
 995                         if ($found_chans > 1) 
 997                                 weechat
::print("", "Channel name is not unique, please define server"); 
 998                                 return weechat
::WEECHAT_RC_OK
; 
1001                 # Something didn't return right 
1004                         weechat
::print("", "Could not find buffer"); 
1005                         return weechat
::WEECHAT_RC_OK
; 
1010                 # Get pointer from where we are 
1011                 $bufp = weechat
::current_buffer
(); 
1014         $bufname = weechat
::buffer_get_string
($bufp, 'name'); 
1015         # Test if buffer is an IRC channel 
1016         if ($bufname =~ /(.*)\.([#&\+!])(.*)/) 
1018                 if (weechat
::config_get_plugin
($bufname) eq "off") 
1020                         # If currently off, set on 
1021                         weechat
::config_set_plugin
($bufname, "on"); 
1023                         # Send to output formatter 
1024                         highmon_print
("Highlight Monitoring Enabled", $bufp); 
1025                         return weechat
::WEECHAT_RC_OK
; 
1027                 elsif (weechat
::config_get_plugin
($bufname) eq "on" || weechat
::config_get_plugin
($bufname) eq "") 
1029                         # If currently on, set off 
1030                         weechat
::config_set_plugin
($bufname, "off"); 
1032                         # Send to output formatter 
1033                         highmon_print
("Highlight Monitoring Disabled", $bufp); 
1034                         return weechat
::WEECHAT_RC_OK
; 
1039 # Takes a buffer pointer and returns a formatted name 
1040 sub format_buffer_name
 
1042         $cb_bufferp = $_[0]; 
1043         $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name'); 
1045         # Set colour from buffer name 
1046         if (weechat
::config_get_plugin
("color_buf") eq "on") 
1048                 # Determine what colour to use 
1049                 $color = weechat
::info_get
("irc_nick_color", $bufname); 
1053                         @char_array = split(//,$bufname); 
1054                         foreach $char (@char_array) 
1056                                 $color += ord($char); 
1059                         $color = sprintf "weechat.color.chat_nick_color%02d", $color+1; 
1060                         $color = weechat
::config_get
($color); 
1061                         $color = weechat
::config_string
($color); 
1062                         $color = weechat
::color
($color); 
1065                 # Private message just show network 
1066                 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private") 
1068                         $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server"); 
1070                 # Format name to short or 'nicename' 
1071                 elsif (weechat
::config_get_plugin
("short_names") eq "on") 
1073                         $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name'); 
1077                         $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/; 
1080                 # Build a coloured string 
1081                 $bufname = $color.$bufname.weechat
::color
("reset"); 
1083         # User set colour name 
1084         elsif (weechat
::config_get_plugin
("color_buf") ne "off") 
1086                 # Private message just show network 
1087                 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private") 
1089                         $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server"); 
1091                 # Format name to short or 'nicename' 
1092                 elsif (weechat
::config_get_plugin
("short_names") eq "on") 
1094                         $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name'); 
1098                         $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/; 
1101                 $color = weechat
::config_get_plugin
("color_buf"); 
1102                 $bufname = weechat
::color
($color).$bufname.weechat
::color
("reset"); 
1104         # Stick with default colour 
1107                 # Private message just show network 
1108                 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private") 
1110                         $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server"); 
1112                 # Format name to short or 'nicename' 
1113                 elsif (weechat
::config_get_plugin
("short_names") eq "on") 
1115                         $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name'); 
1119                         $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/; 
1126 # Check result of register, and attempt to behave in a sane manner 
1127 if (!weechat
::register
("highmon", "KenjiE20", "2.5", "GPL3", "Highlight Monitor", "", "")) 
1130         weechat
::print ("", "\tHighmon is already loaded"); 
1131         return weechat
::WEECHAT_RC_OK
; 
1137         highmon_config_init
();