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 # 2019-05-13, HubbeKing <hubbe128@gmail.com>
77 # v2.6: -add: send "logger_backlog" signal on buffer open if logging is enabled
78 # 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>:
79 # v2.5: -add: clearbar command to clear bar output
80 # -add: firstrun output prompt to check the help text for set up hints as they were being missed
81 # and update hint for conditions to use eval
82 # -change: Make all outputs use the date callback for more accurate timestamps (thanks Germainz)
83 # 2013-12-04, KenjiE20 <longbow@longbowslair.co.uk>:
84 # v2.4: -add: Support for eval style colour codes in time format used for bar output
85 # 2013-10-22, KenjiE20 <longbow@longbowslair.co.uk>:
86 # v2.3.3.2: -fix: Typo in fix command
87 # 2013-10-10, KenjiE20 <longbow@longbowslair.co.uk>:
88 # v2.3.3.1: -fix: Typo in closed buffer warning
89 # 2013-10-07, KenjiE20 <longbow@longbowslair.co.uk>:
90 # v2.3.3: -add: Warning and fixer for accidental buffer closes
91 # 2013-01-15, KenjiE20 <longbow@longbowslair.co.uk>:
92 # v2.3.2: -fix: Let bar output use the string set in weechat's config option
94 # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
95 # v2.3.1: -fix: Colour tags in bar timestamp string
96 # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>:
97 # v2.3: -feature: Added merge_private option to display private messages (default: off)
98 # -fix: Channel name colours now show correctly when set to on
99 # 2011-08-07, Sitaktif <romainchossart_at_gmail.com>:
100 # v2.2.1: -feature: Add "bar_scrolldown" option to have the bar display the latest hl at anytime
101 # -fix: Set up bar-specific config at startup if 'output' is already configured as 'bar'
102 # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>:
103 # v2.2: -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours
104 # 2010-12-13, idl0r & KenjiE20 <longbow@longbowslair.co.uk>:
105 # v2.1.3: -fix: perl errors caused by bar line counter
106 # -fix: Add command list to inbuilt help
107 # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>:
108 # v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing)
109 # -version sync w/ chanmon
110 # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>:
111 # v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name
112 # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>:
113 # v2.0: Release as version 2.0
114 # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>:
115 # v1.9: Rewrite for v2.0
116 # Bring feature set in line with chanmon 2.0
117 # -code change: Made more subs to shrink the code down in places
118 # -fix: Stop highmon attempting to double load/hook
119 # -fix: Add version dependant check for away status
120 # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
121 # v1.7: -fixture: Let highmon be aware of nick_prefix/suffix
122 # and allow custom prefix/suffix for chanmon buffer
123 # (Defaults to <> if nothing set, and blank if there is)
124 # (Thanks to m4v for these)
125 # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
126 # v1.6: -feature: colored buffer names
127 # -change: version sync with chanmon
128 # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
129 # v1.2: -fix: disable buffer highlight
130 # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
131 # v.1.1.1 -change: Stop unsightly text block on '/help'
132 # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
133 # v1.1: In-client help added
134 # 2009-08-02, KenjiE20 <longbow@longbowslair.co.uk>:
135 # v1.0: Initial Public Release
137 # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
139 # This program is free software; you can redistribute it and/or modify
140 # it under the terms of the GNU General Public License as published by
141 # the Free Software Foundation; either version 3 of the License, or
142 # (at your option) any later version.
144 # This program is distributed in the hope that it will be useful,
145 # but WITHOUT ANY WARRANTY; without even the implied warranty of
146 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
147 # GNU General Public License for more details.
149 # You should have received a copy of the GNU General Public License
150 # along with this program. If not, see <http://www.gnu.org/licenses/>.
154 @bar_lines_time = ();
155 # Replicate info earlier for in-client help
157 $highmonhelp = weechat
::color
("bold")."/highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar".weechat
::color
("-bold")."
158 Command wrapper for highmon commands
160 ".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
162 ".weechat
::color
("bold")."/highmon clearbar".weechat
::color
("-bold")." will clear the contents of highmon's bar output
164 ".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
166 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.alignment".weechat
::color
("-bold")."
167 The config setting \"alignment\" can be changed to;
168 \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\"
169 to change how the monitor appears
170 The 'channel' value will show: \"#weechat\"
171 The 'schannel' value will show: \"6\"
172 The 'nchannel' value will show: \"6:#weechat\"
174 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.short_names".weechat
::color
("-bold")."
175 Setting this to 'on' will trim the network name from highmon, ala buffers.pl
177 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.merge_private".weechat
::color
("-bold")."
178 Setting this to 'on' will merge private messages to highmon's display
180 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.color_buf".weechat
::color
("-bold")."
181 This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
182 This ".weechat
::color
("bold")."must".weechat
::color
("-bold")." be a valid color name, or weechat will likely do unexpected things :)
184 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.hotlist_show".weechat
::color
("-bold")."
185 Setting this to 'on' will let the highmon buffer appear in hotlists (status bar/buffer.pl)
187 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.away_only".weechat
::color
("-bold")."
188 Setting this to 'on' will only put messages in the highmon buffer when you set your status to away
190 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.logging".weechat
::color
("-bold")."
191 Toggles logging status for highmon buffer (default: off)
193 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.output".weechat
::color
("-bold")."
194 Changes where output method of highmon; takes either \"bar\" or \"buffer\" (default; buffer)
195 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_lines".weechat
::color
("-bold")."
196 Changes the amount of lines the output bar will hold.
197 (Only appears once output has been set to bar, defaults to 10)
198 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_scrolldown".weechat
::color
("-bold")."
199 Toggles the bar scrolling at the bottom when new highlights are received
200 (Only appears once output has been set to bar, defaults to off)
202 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_prefix".weechat
::color
("-bold")."
203 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_suffix".weechat
::color
("-bold")."
204 Sets the prefix and suffix chars in the highmon buffer
205 (Defaults to <> if nothing set, and blank if there is)
207 ".weechat
::color
("bold")."servername.#channel".weechat
::color
("-bold")."
208 servername is the internal name for the server (set when you use /server add)
209 #channel is the channel name, (where # is whatever channel type that channel happens to be)
211 ".weechat
::color
("bold")."Optional, set up tweaks;".weechat
::color
("-bold")." Hide the status and input lines on highmon
213 ".weechat
::color
("bold")."/set weechat.bar.status.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat
::color
("-bold")."
214 ".weechat
::color
("bold")."/set weechat.bar.input.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat
::color
("-bold");
218 weechat
::print("", "\t".weechat
::color
("bold")."Highmon Help".weechat
::color
("-bold")."\n\n");
219 weechat
::print("", "\t".$highmonhelp);
220 return weechat
::WEECHAT_RC_OK
;
224 sub highmon_bar_build
227 $max_lines = weechat
::config_get_plugin
("bar_lines");
228 $max_lines = $max_lines ? $max_lines : 10;
232 # Keep lines within max
233 while ($#bar_lines > $max_lines)
236 shift(@bar_lines_time);
238 # So long as we have some lines, build a string
242 $sep = " ".weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_suffix"))." ";
245 # Find max align needed
246 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
247 $align_num = $prefix_num if ($prefix_num > $align_num);
251 # Get align for this line
252 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
255 $str = $str.$bar_lines_time[$count]." ".(" " x
($align_num - $prefix_num)).$_."\n";
256 # Increment count for sync with time list
267 weechat
::bar_item_new
("highmon", "highmon_bar_build", "");
269 $highmon_bar = weechat
::bar_new
("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "highmon");
271 return weechat
::WEECHAT_RC_OK
;
274 sub highmon_bar_close
277 $highmon_bar = weechat
::bar_search
("highmon");
278 # If is does, close it
279 if ($highmon_bar ne "")
281 weechat
::bar_remove
($highmon_bar);
284 # Find if bar item exists
285 $highmon_bar_item = weechat
::bar_item_search
("highmon_bar");
286 # If is does, close it
287 if ($highmon_bar_item ne "")
289 weechat
::bar_remove
($highmon_bar_item);
293 return weechat
::WEECHAT_RC_OK
;
297 sub highmon_buffer_open
299 # Search for pre-existing buffer
300 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
303 if ($highmon_buffer eq "")
305 $highmon_buffer = weechat
::buffer_new
("highmon", "highmon_buffer_input", "", "highmon_buffer_close", "");
308 # Turn off notify, highlights
309 if ($highmon_buffer ne "")
311 if (weechat
::config_get_plugin
("hotlist_show") eq "off")
313 weechat
::buffer_set
($highmon_buffer, "notify", "0");
315 weechat
::buffer_set
($highmon_buffer, "highlight_words", "-");
316 weechat
::buffer_set
($highmon_buffer, "title", "Highlight Monitor");
318 if (weechat
::config_get_plugin
("logging") eq "off")
320 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
322 # send "logger_backlog" signal if logging is enabled to display backlog
323 if (weechat
::config_get_plugin
("logging") eq "on")
325 weechat
::hook_signal_send
("logger_backlog", weechat
::WEECHAT_HOOK_SIGNAL_POINTER
, $highmon_buffer)
328 return weechat
::WEECHAT_RC_OK
;
330 # Buffer input has no action
331 sub highmon_buffer_input
333 return weechat
::WEECHAT_RC_OK
;
336 sub highmon_buffer_close
338 $highmon_buffer = "";
339 # If user hasn't changed output style warn user
340 if (weechat
::config_get_plugin
("output") eq "buffer")
342 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"));
344 return weechat
::WEECHAT_RC_OK
;
347 # Highmon command wrapper
348 sub highmon_command_cb
359 @arg_array = split(/ /,$args);
360 # Take first as command
361 $cmd = shift(@arg_array);
362 # Rebuild string to pass to subs
365 $arg = join(" ", @arg_array);
370 if ($cmd eq "" || $cmd eq "help")
375 elsif ($cmd eq "monitor")
377 highmon_toggle
($data, $buffer, $arg);
380 elsif ($cmd eq "clean")
382 highmon_config_clean
($data, $buffer, $arg);
385 elsif ($cmd eq "clearbar")
387 if (weechat
::config_get_plugin
("output") eq "bar")
390 weechat
::bar_item_update
("highmon");
394 elsif ($cmd eq "fix")
396 if (weechat
::config_get_plugin
("output") eq "buffer" && $highmon_buffer eq "")
398 highmon_buffer_open
();
401 return weechat
::WEECHAT_RC_OK
;
404 # Clean up config entries
405 sub highmon_config_clean
411 # Don't do anything if bad option given
412 if ($args ne "default" && $args ne "orphan" && $args ne "all")
414 weechat
::print("", "\thighmon.pl: Unknown option");
415 return weechat
::WEECHAT_RC_OK
;
419 # Load an infolist of highmon options
420 $infolist = weechat
::infolist_get
("option", "", "*highmon*");
421 while (weechat
::infolist_next
($infolist))
423 $name = weechat
::infolist_string
($infolist, "option_name");
424 $name =~ s/perl\.highmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/;
425 if ($name =~ /^(.*)\.([#&\+!])(.*)$/)
429 if ($args eq "default" || $args eq "all")
431 # If value in config is "on"
432 if (weechat
::config_get_plugin
($name) eq "on")
434 # Unset and if successful flag as changed
435 $rc = weechat
::config_unset_plugin
($name);
436 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
443 if ($args eq "orphan" || $args eq "all")
445 # If we can't find the buffer for this entry
446 if (weechat
::buffer_search
("irc", $name) eq "")
448 # Unset and if successful flag as changed
449 $rc = weechat
::config_unset_plugin
($name);
450 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
456 # Add changed entry names to list
457 push (@chans, $name) if ($action);
460 weechat
::infolist_free
($infolist);
461 # If channels were cleaned from config
467 $str = "\thighmon.pl: Cleaned ".@chans." entry from the config:";
471 $str = "\thighmon.pl: Cleaned ".@chans." entries from the config:";
473 # Build a list of channels
478 # Print what happened
479 weechat
::print("",$str);
481 # Config seemed to be clean
484 weechat
::print("", "\thighmon.pl: No entries removed");
486 return weechat
::WEECHAT_RC_OK
;
489 # Check config elements
490 sub highmon_config_init
493 if (!(weechat
::config_is_set_plugin
("first_run")))
495 if (weechat
::config_get_plugin
("first_run") ne "true")
497 weechat
::print("", "\tThis appears to be the first time highmon has been run. For help and common set up hints see /highmon help");
498 weechat
::config_set_plugin
("first_run", "true");
502 if (!(weechat
::config_is_set_plugin
("alignment")))
504 weechat
::config_set_plugin
("alignment", "channel");
506 if (weechat
::config_get_plugin
("alignment") eq "")
508 weechat
::config_set_plugin
("alignment", "none");
512 if (!(weechat
::config_is_set_plugin
("short_names")))
514 weechat
::config_set_plugin
("short_names", "off");
517 # Coloured names default
518 if (!(weechat
::config_is_set_plugin
("color_buf")))
520 weechat
::config_set_plugin
("color_buf", "on");
523 # Hotlist show default
524 if (!(weechat
::config_is_set_plugin
("hotlist_show")))
526 weechat
::config_set_plugin
("hotlist_show", "off");
530 if (!(weechat
::config_is_set_plugin
("away_only")))
532 weechat
::config_set_plugin
("away_only", "off");
535 # highmon log default
536 if (!(weechat
::config_is_set_plugin
("logging")))
538 weechat
::config_set_plugin
("logging", "off");
542 if (!(weechat
::config_is_set_plugin
("output")))
544 weechat
::config_set_plugin
("output", "buffer");
547 # Private message merging
548 if (!(weechat
::config_is_set_plugin
("merge_private")))
550 weechat
::config_set_plugin
("merge_private", "off");
553 # Set bar config in case output was set to "bar" before even changing the setting
554 if (weechat
::config_get_plugin
("output") eq "bar")
556 # Output bar lines default
557 if (!(weechat
::config_is_set_plugin
("bar_lines")))
559 weechat
::config_set_plugin
("bar_lines", "10");
561 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
563 weechat
::config_set_plugin
("bar_scrolldown", "off");
567 # Check for exisiting prefix/suffix chars, and setup accordingly
568 $prefix = weechat
::config_get
("irc.look.nick_prefix");
569 $prefix = weechat
::config_string
($prefix);
570 $suffix = weechat
::config_get
("irc.look.nick_suffix");
571 $suffix = weechat
::config_string
($suffix);
573 if (!(weechat
::config_is_set_plugin
("nick_prefix")))
575 if ($prefix eq "" && $suffix eq "")
577 weechat
::config_set_plugin
("nick_prefix", "<");
581 weechat
::config_set_plugin
("nick_prefix", "");
585 if (!(weechat
::config_is_set_plugin
("nick_suffix")))
587 if ($prefix eq "" && $suffix eq "")
589 weechat
::config_set_plugin
("nick_suffix", ">");
593 weechat
::config_set_plugin
("nick_suffix", "");
599 sub highmon_config_cb
605 $name =~ s/^plugins\.var\.perl\.highmon\.//;
607 # Set logging on buffer
608 if ($name eq "logging")
610 # Search for pre-existing buffer
611 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
614 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
618 weechat
::buffer_set
($highmon_buffer, "localvar_del_no_log", "");
622 elsif ($name eq "output")
626 # Search for pre-existing buffer
627 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
629 if ($highmon_buffer ne "")
631 weechat
::buffer_close
($highmon_buffer)
634 # Output bar lines default
635 if (!(weechat
::config_is_set_plugin
("bar_lines")))
637 weechat
::config_set_plugin
("bar_lines", "10");
639 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
641 weechat
::config_set_plugin
("bar_scrolldown", "off");
643 # Make a bar if doesn't exist
646 elsif ($value eq "buffer")
648 # If a bar exists, close it
651 highmon_buffer_open
();
655 # Change if hotlist config changes
656 elsif ($name eq "hotlist_show")
658 # Search for pre-existing buffer
659 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
660 if ($value eq "off" && $highmon_buffer)
662 weechat
::buffer_set
($highmon_buffer, "notify", "0");
664 elsif ($value ne "off" && $highmon_buffer)
666 weechat
::buffer_set
($highmon_buffer, "notify", "3");
669 elsif ($name eq "weechat.look.prefix_suffix")
671 if (weechat
::config_get_plugin
("output") eq "bar")
674 weechat
::print("", "\thighmon: weechat.look.prefix_suffix changed, clearing highmon bar");
675 weechat
::bar_item_update
("highmon");
678 return weechat
::WEECHAT_RC_OK
;
681 # Set up weechat hooks / commands
684 weechat
::hook_print
("", "", "", 0, "highmon_new_message", "");
685 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", "");
687 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", "");
689 weechat
::hook_config
("plugins.var.perl.highmon.*", "highmon_config_cb", "");
690 weechat
::hook_config
("weechat.look.prefix_suffix", "highmon_config_cb", "");
693 # Main body, Callback for hook_print
694 sub highmon_new_message
700 my $window_displayed = "";
704 # $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
705 # weechat::print("", "\t".$string);
716 # Only work on highlighted messages or private message when enabled
717 if ($cb_high == "1" || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/))
719 # Pre bug #29618 (0.3.3) away detect
720 if (weechat
::info_get
("version_number", "") <= 197120)
723 # Get infolist for this server
724 $infolist = weechat
::infolist_get
("irc_server", "", weechat
::buffer_get_string
($cb_bufferp, "localvar_server"));
725 while (weechat
::infolist_next
($infolist))
727 # Get away message is is_away is on
728 $away = weechat
::infolist_string
($infolist, "away_message") if (weechat
::infolist_integer
($infolist, "is_away"));
730 weechat
::infolist_free
($infolist);
732 # Post bug #29618 fix
735 $away = weechat
::buffer_get_string
($cb_bufferp, "localvar_away");
737 if (weechat
::config_get_plugin
("away_only") ne "on" || ($away ne ""))
739 # Check buffer name is an IRC channel
740 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
741 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
743 # Are we running on this channel
744 if (weechat
::config_get_plugin
($bufname) ne "off" && $cb_disp eq "1")
747 # Line isn't action or topic notify
748 if (!($cb_tags =~ /irc_action/) && !($cb_tags =~ /irc_topic/))
751 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
753 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
756 elsif ($cb_tags =~ /irc_topic/)
758 $nick = " ".$cb_prefix.weechat
::color
("reset");
763 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
764 $nick = weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset");
767 highmon_print
($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags);
770 # Or is private message
771 elsif (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/)
774 $uncolnick = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
776 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
778 highmon_print
($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags);
782 return weechat
::WEECHAT_RC_OK
;
785 # Output formatter and printer takes (msg bufpointer nick)
789 my $cb_bufferp = $_[1] if ($_[1]);
790 my $nick = $_[2] if ($_[2]);
791 my $cb_date = $_[3] if ($_[3]);
792 my $cb_tags = $_[4] if ($_[4]);
794 #Normal channel message
795 if ($cb_bufferp && $nick)
798 $bufname = format_buffer_name
($cb_bufferp);
800 # If alignment is #channel | nick msg
801 if (weechat
::config_get_plugin
("alignment") eq "channel")
803 $nick =~ s/\s(.*)/$1/;
805 $outstr = $bufname."\t".$nick." ".$cb_msg;
807 # or if it is channel number | nick msg
808 elsif (weechat
::config_get_plugin
("alignment") eq "schannel")
810 $nick =~ s/\s(.*)/$1/;
811 # Use channel number instead
812 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
814 $outstr = $bufname."\t".$nick." ".$cb_msg;
816 # or if it is number:#channel | nick msg
817 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel")
819 $nick =~ s/\s(.*)/$1/;
820 # Place channel number in front of formatted name
821 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
823 $outstr = $bufname."\t".$nick." ".$cb_msg;
825 # or if it is #channel nick | msg
826 elsif (weechat
::config_get_plugin
("alignment") eq "channel,nick")
829 $outstr = $bufname.":".$nick."\t".$cb_msg;
831 # or if it is channel number nick | msg
832 elsif (weechat
::config_get_plugin
("alignment") eq "schannel,nick")
834 # Use channel number instead
835 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
837 $outstr = $bufname.":".$nick."\t".$cb_msg;
839 # or if it is number:#channel nick | msg
840 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel,nick")
842 # Place channel number in front of formatted name
843 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
845 $outstr = $bufname.":".$nick."\t".$cb_msg;
847 # or finally | #channel nick msg
851 $outstr = "\t".$bufname.":".$nick." ".$cb_msg;
854 # highmon channel toggle message
855 elsif ($cb_bufferp && !$nick)
858 $bufname = format_buffer_name
($cb_bufferp);
860 # If alignment is #channel * | *
861 if (weechat
::config_get_plugin
("alignment") =~ /channel/)
863 # If it's actually channel number * | *
864 if (weechat
::config_get_plugin
("alignment") =~ /schannel/)
866 # Use channel number instead
867 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
869 # Or if it's actually number:#channel * | *
870 if (weechat
::config_get_plugin
("alignment") =~ /nchannel/)
872 # Place channel number in front of formatted name
873 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
875 $outstr = $bufname."\t".$cb_msg;
877 # or if alignment is | *
880 $outstr = $bufname.": ".$cb_msg;
884 elsif (!$cb_bufferp && !$nick)
886 $outstr = "\t".$cb_msg;
889 # Send string to buffer
890 if (weechat
::config_get_plugin
("output") eq "buffer")
892 # Search for and confirm buffer
893 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
897 weechat
::print_date_tags
($highmon_buffer, $cb_date, $cb_tags, $outstr);
901 weechat
::print($highmon_buffer, $outstr);
904 elsif (weechat
::config_get_plugin
("output") eq "bar")
907 use POSIX
qw(strftime);
910 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime($cb_date));
914 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime);
917 if ($time =~ /\$\{(?:color:)?[\w,]+\}/) # Coloured string
919 while ($time =~ /\$\{(?:color:)?([\w,]+)\}/)
921 $color = weechat
::color
($1);
922 $time =~ s/\$\{(?:color:)?[\w,]+\}/$color/;
924 $time .= weechat
::color
("reset");
926 else # Default string
928 $colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_time_delimiters")));
929 $reset = weechat
::color
("reset");
930 $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g;
932 # Push updates to bar lists
933 push (@bar_lines_time, $time);
936 $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")." ";
937 $outstr =~ s/\t/$delim/;
939 push (@bar_lines, $outstr);
941 weechat
::bar_item_update
("highmon");
943 if (weechat
::config_get_plugin
("bar_scrolldown") eq "on")
945 weechat
::command
("", "/bar scroll highmon * ye")
950 # Start the output display
953 if (weechat
::config_get_plugin
("output") eq "buffer")
955 highmon_buffer_open
();
957 elsif (weechat
::config_get_plugin
("output") eq "bar")
963 # Takes two optional args (channel server), toggles monitoring on/off
970 # Check if we've been told what channel to act on
974 @arg_array = split(/ /,$args);
975 # Check if a server was given
979 $bufp = weechat
::buffer_search
("irc", $arg_array[1].".".$arg_array[0]);
984 # Loop through defined servers
985 $infolist = weechat
::infolist_get
("buffer", "", "");
986 while (weechat
::infolist_next
($infolist))
988 # Only interesting in IRC buffers
989 if (weechat
::infolist_string
($infolist, "plugin_name") eq "irc")
991 # Find buffers that maych
992 $sname = weechat
::infolist_string
($infolist, "short_name");
993 if ($sname eq $arg_array[0])
996 $bufp = weechat
::infolist_pointer
($infolist, "pointer");
1000 weechat
::infolist_free
($infolist);
1001 # If the infolist found more than one channel, halt as we need to know which one
1002 if ($found_chans > 1)
1004 weechat
::print("", "Channel name is not unique, please define server");
1005 return weechat
::WEECHAT_RC_OK
;
1008 # Something didn't return right
1011 weechat
::print("", "Could not find buffer");
1012 return weechat
::WEECHAT_RC_OK
;
1017 # Get pointer from where we are
1018 $bufp = weechat
::current_buffer
();
1021 $bufname = weechat
::buffer_get_string
($bufp, 'name');
1022 # Test if buffer is an IRC channel
1023 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
1025 if (weechat
::config_get_plugin
($bufname) eq "off")
1027 # If currently off, set on
1028 weechat
::config_set_plugin
($bufname, "on");
1030 # Send to output formatter
1031 highmon_print
("Highlight Monitoring Enabled", $bufp);
1032 return weechat
::WEECHAT_RC_OK
;
1034 elsif (weechat
::config_get_plugin
($bufname) eq "on" || weechat
::config_get_plugin
($bufname) eq "")
1036 # If currently on, set off
1037 weechat
::config_set_plugin
($bufname, "off");
1039 # Send to output formatter
1040 highmon_print
("Highlight Monitoring Disabled", $bufp);
1041 return weechat
::WEECHAT_RC_OK
;
1046 # Takes a buffer pointer and returns a formatted name
1047 sub format_buffer_name
1049 $cb_bufferp = $_[0];
1050 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
1052 # Set colour from buffer name
1053 if (weechat
::config_get_plugin
("color_buf") eq "on")
1055 # Determine what colour to use
1056 $color = weechat
::info_get
("irc_nick_color", $bufname);
1060 @char_array = split(//,$bufname);
1061 foreach $char (@char_array)
1063 $color += ord($char);
1066 $color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
1067 $color = weechat
::config_get
($color);
1068 $color = weechat
::config_string
($color);
1069 $color = weechat
::color
($color);
1072 # Private message just show network
1073 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1075 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1077 # Format name to short or 'nicename'
1078 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1080 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1084 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1087 # Build a coloured string
1088 $bufname = $color.$bufname.weechat
::color
("reset");
1090 # User set colour name
1091 elsif (weechat
::config_get_plugin
("color_buf") ne "off")
1093 # Private message just show network
1094 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1096 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1098 # Format name to short or 'nicename'
1099 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1101 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1105 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1108 $color = weechat
::config_get_plugin
("color_buf");
1109 $bufname = weechat
::color
($color).$bufname.weechat
::color
("reset");
1111 # Stick with default colour
1114 # Private message just show network
1115 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1117 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1119 # Format name to short or 'nicename'
1120 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1122 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1126 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1133 # Check result of register, and attempt to behave in a sane manner
1134 if (!weechat
::register
("highmon", "KenjiE20", "2.6", "GPL3", "Highlight Monitor", "", ""))
1137 weechat
::print ("", "\tHighmon is already loaded");
1138 return weechat
::WEECHAT_RC_OK
;
1144 highmon_config_init
();