2 # highmon.pl - Highlight Monitoring for weechat 0.3.0
4 # Add 'Highlight Monitor' buffer/bar to log all highlights in one spot
7 # /highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar
8 # Command wrapper for highmon commands
10 # /highmon clean default|orphan|all will clean the config section of default 'on' entries,
11 # channels you are no longer joined, or both
13 # /highmon clearbar will clear the contents of highmon's bar output
15 # /highmon monitor [channel] [server] is used to toggle a highlight monitoring on and off, this
16 # can be used in the channel buffer for the channel you wish to toggle, or be given
17 # with arguments e.g. /highmon monitor #weechat freenode
19 # /set plugins.var.perl.highmon.alignment
20 # The config setting "alignment" can be changed to;
21 # "channel", "schannel", "nchannel", "channel,nick", "schannel,nick", "nchannel,nick"
22 # to change how the monitor appears
23 # The 'channel' value will show: "#weechat"
24 # The 'schannel' value will show: "6"
25 # The 'nchannel' value will show: "6:#weechat"
27 # /set plugins.var.perl.highmon.short_names
28 # Setting this to 'on' will trim the network name from highmon, ala buffers.pl
30 # /set plugins.var.perl.highmon.merge_private
31 # Setting this to 'on' will merge private messages to highmon's display
33 # /set plugins.var.perl.highmon.color_buf
34 # This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
35 # This *must* be a valid color name, or weechat will likely do unexpected things :)
37 # /set plugins.var.perl.highmon.hotlist_show
38 # Setting this to 'on' will let the highmon buffer appear in hotlists
39 # (status bar/buffer.pl)
41 # /set plugins.var.perl.highmon.away_only
42 # Setting this to 'on' will only put messages in the highmon buffer when
43 # you set your status to away
45 # /set plugins.var.perl.highmon.logging
46 # Toggles logging status for highmon buffer (default: off)
48 # /set plugins.var.perl.highmon.output
49 # Changes where output method of highmon; takes either "bar" or "buffer" (default; buffer)
50 # /set plugins.var.perl.highmon.bar_lines
51 # Changes the amount of lines the output bar will hold.
52 # (Only appears once output has been set to bar, defaults to 10)
53 # /set plugins.var.perl.highmon.bar_scrolldown
54 # Toggles the bar scrolling at the bottom when new highlights are received
55 # (Only appears once output has been set to bar, defaults to off)
57 # /set plugins.var.perl.highmon.nick_prefix
58 # /set plugins.var.perl.highmon.nick_suffix
59 # Sets the prefix and suffix chars in the highmon buffer
60 # (Defaults to <> if nothing set, and blank if there is)
63 # servername is the internal name for the server (set when you use /server add)
64 # #channel is the channel name, (where # is whatever channel type that channel happens to be)
66 # Optional, set up tweaks; Hide the status and input lines on highmon
68 # /set weechat.bar.status.conditions "${window.buffer.full_name} != perl.highmon"
69 # /set weechat.bar.input.conditions "${window.buffer.full_name} != perl.highmon"
72 # Bugs and feature requests at: https://github.com/KenjiE20/highmon
75 # 2020-06-21, Sebastien Helleu <flashcode@flashtux.org>:
76 # v2.7: make call to bar_new compatible with WeeChat >= 2.9
77 # 2019-05-13, HubbeKing <hubbe128@gmail.com>
78 # v2.6: -add: send "logger_backlog" signal on buffer open if logging is enabled
79 # 2014-08-16, KenjiE20 <longbow@longbowslair.co.uk>:
80 # v2.5: -add: clearbar command to clear bar output
81 # -add: firstrun output prompt to check the help text for set up hints as they were being missed
82 # and update hint for conditions to use eval
83 # -change: Make all outputs use the date callback for more accurate timestamps (thanks Germainz)
84 # 2013-12-04, KenjiE20 <longbow@longbowslair.co.uk>:
85 # v2.4: -add: Support for eval style colour codes in time format used for bar output
86 # 2013-10-22, KenjiE20 <longbow@longbowslair.co.uk>:
87 # v2.3.3.2: -fix: Typo in fix command
88 # 2013-10-10, KenjiE20 <longbow@longbowslair.co.uk>:
89 # v2.3.3.1: -fix: Typo in closed buffer warning
90 # 2013-10-07, KenjiE20 <longbow@longbowslair.co.uk>:
91 # v2.3.3: -add: Warning and fixer for accidental buffer closes
92 # 2013-01-15, KenjiE20 <longbow@longbowslair.co.uk>:
93 # v2.3.2: -fix: Let bar output use the string set in weechat's config option
95 # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
96 # v2.3.1: -fix: Colour tags in bar timestamp string
97 # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>:
98 # v2.3: -feature: Added merge_private option to display private messages (default: off)
99 # -fix: Channel name colours now show correctly when set to on
100 # 2011-08-07, Sitaktif <romainchossart_at_gmail.com>:
101 # v2.2.1: -feature: Add "bar_scrolldown" option to have the bar display the latest hl at anytime
102 # -fix: Set up bar-specific config at startup if 'output' is already configured as 'bar'
103 # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>:
104 # v2.2: -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours
105 # 2010-12-13, idl0r & KenjiE20 <longbow@longbowslair.co.uk>:
106 # v2.1.3: -fix: perl errors caused by bar line counter
107 # -fix: Add command list to inbuilt help
108 # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>:
109 # v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing)
110 # -version sync w/ chanmon
111 # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>:
112 # v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name
113 # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>:
114 # v2.0: Release as version 2.0
115 # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>:
116 # v1.9: Rewrite for v2.0
117 # Bring feature set in line with chanmon 2.0
118 # -code change: Made more subs to shrink the code down in places
119 # -fix: Stop highmon attempting to double load/hook
120 # -fix: Add version dependant check for away status
121 # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
122 # v1.7: -fixture: Let highmon be aware of nick_prefix/suffix
123 # and allow custom prefix/suffix for chanmon buffer
124 # (Defaults to <> if nothing set, and blank if there is)
125 # (Thanks to m4v for these)
126 # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
127 # v1.6: -feature: colored buffer names
128 # -change: version sync with chanmon
129 # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
130 # v1.2: -fix: disable buffer highlight
131 # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
132 # v.1.1.1 -change: Stop unsightly text block on '/help'
133 # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
134 # v1.1: In-client help added
135 # 2009-08-02, KenjiE20 <longbow@longbowslair.co.uk>:
136 # v1.0: Initial Public Release
138 # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
140 # This program is free software; you can redistribute it and/or modify
141 # it under the terms of the GNU General Public License as published by
142 # the Free Software Foundation; either version 3 of the License, or
143 # (at your option) any later version.
145 # This program is distributed in the hope that it will be useful,
146 # but WITHOUT ANY WARRANTY; without even the implied warranty of
147 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148 # GNU General Public License for more details.
150 # You should have received a copy of the GNU General Public License
151 # along with this program. If not, see <http://www.gnu.org/licenses/>.
155 @bar_lines_time = ();
156 # Replicate info earlier for in-client help
158 $highmonhelp = weechat
::color
("bold")."/highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all] | clearbar".weechat
::color
("-bold")."
159 Command wrapper for highmon commands
161 ".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
163 ".weechat
::color
("bold")."/highmon clearbar".weechat
::color
("-bold")." will clear the contents of highmon's bar output
165 ".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
167 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.alignment".weechat
::color
("-bold")."
168 The config setting \"alignment\" can be changed to;
169 \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\"
170 to change how the monitor appears
171 The 'channel' value will show: \"#weechat\"
172 The 'schannel' value will show: \"6\"
173 The 'nchannel' value will show: \"6:#weechat\"
175 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.short_names".weechat
::color
("-bold")."
176 Setting this to 'on' will trim the network name from highmon, ala buffers.pl
178 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.merge_private".weechat
::color
("-bold")."
179 Setting this to 'on' will merge private messages to highmon's display
181 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.color_buf".weechat
::color
("-bold")."
182 This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
183 This ".weechat
::color
("bold")."must".weechat
::color
("-bold")." be a valid color name, or weechat will likely do unexpected things :)
185 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.hotlist_show".weechat
::color
("-bold")."
186 Setting this to 'on' will let the highmon buffer appear in hotlists (status bar/buffer.pl)
188 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.away_only".weechat
::color
("-bold")."
189 Setting this to 'on' will only put messages in the highmon buffer when you set your status to away
191 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.logging".weechat
::color
("-bold")."
192 Toggles logging status for highmon buffer (default: off)
194 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.output".weechat
::color
("-bold")."
195 Changes where output method of highmon; takes either \"bar\" or \"buffer\" (default; buffer)
196 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_lines".weechat
::color
("-bold")."
197 Changes the amount of lines the output bar will hold.
198 (Only appears once output has been set to bar, defaults to 10)
199 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_scrolldown".weechat
::color
("-bold")."
200 Toggles the bar scrolling at the bottom when new highlights are received
201 (Only appears once output has been set to bar, defaults to off)
203 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_prefix".weechat
::color
("-bold")."
204 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_suffix".weechat
::color
("-bold")."
205 Sets the prefix and suffix chars in the highmon buffer
206 (Defaults to <> if nothing set, and blank if there is)
208 ".weechat
::color
("bold")."servername.#channel".weechat
::color
("-bold")."
209 servername is the internal name for the server (set when you use /server add)
210 #channel is the channel name, (where # is whatever channel type that channel happens to be)
212 ".weechat
::color
("bold")."Optional, set up tweaks;".weechat
::color
("-bold")." Hide the status and input lines on highmon
214 ".weechat
::color
("bold")."/set weechat.bar.status.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat
::color
("-bold")."
215 ".weechat
::color
("bold")."/set weechat.bar.input.conditions \"\${window.buffer.full_name} != perl.highmon\"".weechat
::color
("-bold");
219 weechat
::print("", "\t".weechat
::color
("bold")."Highmon Help".weechat
::color
("-bold")."\n\n");
220 weechat
::print("", "\t".$highmonhelp);
221 return weechat
::WEECHAT_RC_OK
;
225 sub highmon_bar_build
228 $max_lines = weechat
::config_get_plugin
("bar_lines");
229 $max_lines = $max_lines ? $max_lines : 10;
233 # Keep lines within max
234 while ($#bar_lines > $max_lines)
237 shift(@bar_lines_time);
239 # So long as we have some lines, build a string
243 $sep = " ".weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_suffix"))." ";
246 # Find max align needed
247 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
248 $align_num = $prefix_num if ($prefix_num > $align_num);
252 # Get align for this line
253 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
256 $str = $str.$bar_lines_time[$count]." ".(" " x
($align_num - $prefix_num)).$_."\n";
257 # Increment count for sync with time list
268 weechat
::bar_item_new
("highmon", "highmon_bar_build", "");
270 if (weechat
::info_get
("version_number", "") >= 0x02090000)
272 $highmon_bar = weechat
::bar_new
("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "default", "on", "highmon");
276 $highmon_bar = weechat
::bar_new
("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "highmon");
279 return weechat
::WEECHAT_RC_OK
;
282 sub highmon_bar_close
285 $highmon_bar = weechat
::bar_search
("highmon");
286 # If is does, close it
287 if ($highmon_bar ne "")
289 weechat
::bar_remove
($highmon_bar);
292 # Find if bar item exists
293 $highmon_bar_item = weechat
::bar_item_search
("highmon_bar");
294 # If is does, close it
295 if ($highmon_bar_item ne "")
297 weechat
::bar_remove
($highmon_bar_item);
301 return weechat
::WEECHAT_RC_OK
;
305 sub highmon_buffer_open
307 # Search for pre-existing buffer
308 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
311 if ($highmon_buffer eq "")
313 $highmon_buffer = weechat
::buffer_new
("highmon", "highmon_buffer_input", "", "highmon_buffer_close", "");
316 # Turn off notify, highlights
317 if ($highmon_buffer ne "")
319 if (weechat
::config_get_plugin
("hotlist_show") eq "off")
321 weechat
::buffer_set
($highmon_buffer, "notify", "0");
323 weechat
::buffer_set
($highmon_buffer, "highlight_words", "-");
324 weechat
::buffer_set
($highmon_buffer, "title", "Highlight Monitor");
326 if (weechat
::config_get_plugin
("logging") eq "off")
328 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
330 # send "logger_backlog" signal if logging is enabled to display backlog
331 if (weechat
::config_get_plugin
("logging") eq "on")
333 weechat
::hook_signal_send
("logger_backlog", weechat
::WEECHAT_HOOK_SIGNAL_POINTER
, $highmon_buffer)
336 return weechat
::WEECHAT_RC_OK
;
338 # Buffer input has no action
339 sub highmon_buffer_input
341 return weechat
::WEECHAT_RC_OK
;
344 sub highmon_buffer_close
346 $highmon_buffer = "";
347 # If user hasn't changed output style warn user
348 if (weechat
::config_get_plugin
("output") eq "buffer")
350 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"));
352 return weechat
::WEECHAT_RC_OK
;
355 # Highmon command wrapper
356 sub highmon_command_cb
367 @arg_array = split(/ /,$args);
368 # Take first as command
369 $cmd = shift(@arg_array);
370 # Rebuild string to pass to subs
373 $arg = join(" ", @arg_array);
378 if ($cmd eq "" || $cmd eq "help")
383 elsif ($cmd eq "monitor")
385 highmon_toggle
($data, $buffer, $arg);
388 elsif ($cmd eq "clean")
390 highmon_config_clean
($data, $buffer, $arg);
393 elsif ($cmd eq "clearbar")
395 if (weechat
::config_get_plugin
("output") eq "bar")
398 weechat
::bar_item_update
("highmon");
402 elsif ($cmd eq "fix")
404 if (weechat
::config_get_plugin
("output") eq "buffer" && $highmon_buffer eq "")
406 highmon_buffer_open
();
409 return weechat
::WEECHAT_RC_OK
;
412 # Clean up config entries
413 sub highmon_config_clean
419 # Don't do anything if bad option given
420 if ($args ne "default" && $args ne "orphan" && $args ne "all")
422 weechat
::print("", "\thighmon.pl: Unknown option");
423 return weechat
::WEECHAT_RC_OK
;
427 # Load an infolist of highmon options
428 $infolist = weechat
::infolist_get
("option", "", "*highmon*");
429 while (weechat
::infolist_next
($infolist))
431 $name = weechat
::infolist_string
($infolist, "option_name");
432 $name =~ s/perl\.highmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/;
433 if ($name =~ /^(.*)\.([#&\+!])(.*)$/)
437 if ($args eq "default" || $args eq "all")
439 # If value in config is "on"
440 if (weechat
::config_get_plugin
($name) eq "on")
442 # Unset and if successful flag as changed
443 $rc = weechat
::config_unset_plugin
($name);
444 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
451 if ($args eq "orphan" || $args eq "all")
453 # If we can't find the buffer for this entry
454 if (weechat
::buffer_search
("irc", $name) eq "")
456 # Unset and if successful flag as changed
457 $rc = weechat
::config_unset_plugin
($name);
458 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
464 # Add changed entry names to list
465 push (@chans, $name) if ($action);
468 weechat
::infolist_free
($infolist);
469 # If channels were cleaned from config
475 $str = "\thighmon.pl: Cleaned ".@chans." entry from the config:";
479 $str = "\thighmon.pl: Cleaned ".@chans." entries from the config:";
481 # Build a list of channels
486 # Print what happened
487 weechat
::print("",$str);
489 # Config seemed to be clean
492 weechat
::print("", "\thighmon.pl: No entries removed");
494 return weechat
::WEECHAT_RC_OK
;
497 # Check config elements
498 sub highmon_config_init
501 if (!(weechat
::config_is_set_plugin
("first_run")))
503 if (weechat
::config_get_plugin
("first_run") ne "true")
505 weechat
::print("", "\tThis appears to be the first time highmon has been run. For help and common set up hints see /highmon help");
506 weechat
::config_set_plugin
("first_run", "true");
510 if (!(weechat
::config_is_set_plugin
("alignment")))
512 weechat
::config_set_plugin
("alignment", "channel");
514 if (weechat
::config_get_plugin
("alignment") eq "")
516 weechat
::config_set_plugin
("alignment", "none");
520 if (!(weechat
::config_is_set_plugin
("short_names")))
522 weechat
::config_set_plugin
("short_names", "off");
525 # Coloured names default
526 if (!(weechat
::config_is_set_plugin
("color_buf")))
528 weechat
::config_set_plugin
("color_buf", "on");
531 # Hotlist show default
532 if (!(weechat
::config_is_set_plugin
("hotlist_show")))
534 weechat
::config_set_plugin
("hotlist_show", "off");
538 if (!(weechat
::config_is_set_plugin
("away_only")))
540 weechat
::config_set_plugin
("away_only", "off");
543 # highmon log default
544 if (!(weechat
::config_is_set_plugin
("logging")))
546 weechat
::config_set_plugin
("logging", "off");
550 if (!(weechat
::config_is_set_plugin
("output")))
552 weechat
::config_set_plugin
("output", "buffer");
555 # Private message merging
556 if (!(weechat
::config_is_set_plugin
("merge_private")))
558 weechat
::config_set_plugin
("merge_private", "off");
561 # Set bar config in case output was set to "bar" before even changing the setting
562 if (weechat
::config_get_plugin
("output") eq "bar")
564 # Output bar lines default
565 if (!(weechat
::config_is_set_plugin
("bar_lines")))
567 weechat
::config_set_plugin
("bar_lines", "10");
569 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
571 weechat
::config_set_plugin
("bar_scrolldown", "off");
575 # Check for exisiting prefix/suffix chars, and setup accordingly
576 $prefix = weechat
::config_get
("irc.look.nick_prefix");
577 $prefix = weechat
::config_string
($prefix);
578 $suffix = weechat
::config_get
("irc.look.nick_suffix");
579 $suffix = weechat
::config_string
($suffix);
581 if (!(weechat
::config_is_set_plugin
("nick_prefix")))
583 if ($prefix eq "" && $suffix eq "")
585 weechat
::config_set_plugin
("nick_prefix", "<");
589 weechat
::config_set_plugin
("nick_prefix", "");
593 if (!(weechat
::config_is_set_plugin
("nick_suffix")))
595 if ($prefix eq "" && $suffix eq "")
597 weechat
::config_set_plugin
("nick_suffix", ">");
601 weechat
::config_set_plugin
("nick_suffix", "");
607 sub highmon_config_cb
613 $name =~ s/^plugins\.var\.perl\.highmon\.//;
615 # Set logging on buffer
616 if ($name eq "logging")
618 # Search for pre-existing buffer
619 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
622 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
626 weechat
::buffer_set
($highmon_buffer, "localvar_del_no_log", "");
630 elsif ($name eq "output")
634 # Search for pre-existing buffer
635 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
637 if ($highmon_buffer ne "")
639 weechat
::buffer_close
($highmon_buffer)
642 # Output bar lines default
643 if (!(weechat
::config_is_set_plugin
("bar_lines")))
645 weechat
::config_set_plugin
("bar_lines", "10");
647 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
649 weechat
::config_set_plugin
("bar_scrolldown", "off");
651 # Make a bar if doesn't exist
654 elsif ($value eq "buffer")
656 # If a bar exists, close it
659 highmon_buffer_open
();
663 # Change if hotlist config changes
664 elsif ($name eq "hotlist_show")
666 # Search for pre-existing buffer
667 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
668 if ($value eq "off" && $highmon_buffer)
670 weechat
::buffer_set
($highmon_buffer, "notify", "0");
672 elsif ($value ne "off" && $highmon_buffer)
674 weechat
::buffer_set
($highmon_buffer, "notify", "3");
677 elsif ($name eq "weechat.look.prefix_suffix")
679 if (weechat
::config_get_plugin
("output") eq "bar")
682 weechat
::print("", "\thighmon: weechat.look.prefix_suffix changed, clearing highmon bar");
683 weechat
::bar_item_update
("highmon");
686 return weechat
::WEECHAT_RC_OK
;
689 # Set up weechat hooks / commands
692 weechat
::hook_print
("", "", "", 0, "highmon_new_message", "");
693 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", "");
695 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", "");
697 weechat
::hook_config
("plugins.var.perl.highmon.*", "highmon_config_cb", "");
698 weechat
::hook_config
("weechat.look.prefix_suffix", "highmon_config_cb", "");
701 # Main body, Callback for hook_print
702 sub highmon_new_message
708 my $window_displayed = "";
712 # $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
713 # weechat::print("", "\t".$string);
724 # Only work on highlighted messages or private message when enabled
725 if ($cb_high == "1" || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/))
727 # Pre bug #29618 (0.3.3) away detect
728 if (weechat
::info_get
("version_number", "") <= 0x00030200)
731 # Get infolist for this server
732 $infolist = weechat
::infolist_get
("irc_server", "", weechat
::buffer_get_string
($cb_bufferp, "localvar_server"));
733 while (weechat
::infolist_next
($infolist))
735 # Get away message is is_away is on
736 $away = weechat
::infolist_string
($infolist, "away_message") if (weechat
::infolist_integer
($infolist, "is_away"));
738 weechat
::infolist_free
($infolist);
740 # Post bug #29618 fix
743 $away = weechat
::buffer_get_string
($cb_bufferp, "localvar_away");
745 if (weechat
::config_get_plugin
("away_only") ne "on" || ($away ne ""))
747 # Check buffer name is an IRC channel
748 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
749 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
751 # Are we running on this channel
752 if (weechat
::config_get_plugin
($bufname) ne "off" && $cb_disp eq "1")
755 # Line isn't action or topic notify
756 if (!($cb_tags =~ /irc_action/) && !($cb_tags =~ /irc_topic/))
759 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
761 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
764 elsif ($cb_tags =~ /irc_topic/)
766 $nick = " ".$cb_prefix.weechat
::color
("reset");
771 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
772 $nick = weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset");
775 highmon_print
($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags);
778 # Or is private message
779 elsif (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/)
782 $uncolnick = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
784 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
786 highmon_print
($cb_msg, $cb_bufferp, $nick, $cb_date, $cb_tags);
790 return weechat
::WEECHAT_RC_OK
;
793 # Output formatter and printer takes (msg bufpointer nick)
797 my $cb_bufferp = $_[1] if ($_[1]);
798 my $nick = $_[2] if ($_[2]);
799 my $cb_date = $_[3] if ($_[3]);
800 my $cb_tags = $_[4] if ($_[4]);
802 #Normal channel message
803 if ($cb_bufferp && $nick)
806 $bufname = format_buffer_name
($cb_bufferp);
808 # If alignment is #channel | nick msg
809 if (weechat
::config_get_plugin
("alignment") eq "channel")
811 $nick =~ s/\s(.*)/$1/;
813 $outstr = $bufname."\t".$nick." ".$cb_msg;
815 # or if it is channel number | nick msg
816 elsif (weechat
::config_get_plugin
("alignment") eq "schannel")
818 $nick =~ s/\s(.*)/$1/;
819 # Use channel number instead
820 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
822 $outstr = $bufname."\t".$nick." ".$cb_msg;
824 # or if it is number:#channel | nick msg
825 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel")
827 $nick =~ s/\s(.*)/$1/;
828 # Place channel number in front of formatted name
829 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
831 $outstr = $bufname."\t".$nick." ".$cb_msg;
833 # or if it is #channel nick | msg
834 elsif (weechat
::config_get_plugin
("alignment") eq "channel,nick")
837 $outstr = $bufname.":".$nick."\t".$cb_msg;
839 # or if it is channel number nick | msg
840 elsif (weechat
::config_get_plugin
("alignment") eq "schannel,nick")
842 # Use channel number instead
843 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
845 $outstr = $bufname.":".$nick."\t".$cb_msg;
847 # or if it is number:#channel nick | msg
848 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel,nick")
850 # Place channel number in front of formatted name
851 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
853 $outstr = $bufname.":".$nick."\t".$cb_msg;
855 # or finally | #channel nick msg
859 $outstr = "\t".$bufname.":".$nick." ".$cb_msg;
862 # highmon channel toggle message
863 elsif ($cb_bufferp && !$nick)
866 $bufname = format_buffer_name
($cb_bufferp);
868 # If alignment is #channel * | *
869 if (weechat
::config_get_plugin
("alignment") =~ /channel/)
871 # If it's actually channel number * | *
872 if (weechat
::config_get_plugin
("alignment") =~ /schannel/)
874 # Use channel number instead
875 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
877 # Or if it's actually number:#channel * | *
878 if (weechat
::config_get_plugin
("alignment") =~ /nchannel/)
880 # Place channel number in front of formatted name
881 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
883 $outstr = $bufname."\t".$cb_msg;
885 # or if alignment is | *
888 $outstr = $bufname.": ".$cb_msg;
892 elsif (!$cb_bufferp && !$nick)
894 $outstr = "\t".$cb_msg;
897 # Send string to buffer
898 if (weechat
::config_get_plugin
("output") eq "buffer")
900 # Search for and confirm buffer
901 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
905 weechat
::print_date_tags
($highmon_buffer, $cb_date, $cb_tags, $outstr);
909 weechat
::print($highmon_buffer, $outstr);
912 elsif (weechat
::config_get_plugin
("output") eq "bar")
915 use POSIX
qw(strftime);
918 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime($cb_date));
922 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime);
925 if ($time =~ /\$\{(?:color:)?[\w,]+\}/) # Coloured string
927 while ($time =~ /\$\{(?:color:)?([\w,]+)\}/)
929 $color = weechat
::color
($1);
930 $time =~ s/\$\{(?:color:)?[\w,]+\}/$color/;
932 $time .= weechat
::color
("reset");
934 else # Default string
936 $colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_time_delimiters")));
937 $reset = weechat
::color
("reset");
938 $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g;
940 # Push updates to bar lists
941 push (@bar_lines_time, $time);
944 $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")." ";
945 $outstr =~ s/\t/$delim/;
947 push (@bar_lines, $outstr);
949 weechat
::bar_item_update
("highmon");
951 if (weechat
::config_get_plugin
("bar_scrolldown") eq "on")
953 weechat
::command
("", "/bar scroll highmon * ye")
958 # Start the output display
961 if (weechat
::config_get_plugin
("output") eq "buffer")
963 highmon_buffer_open
();
965 elsif (weechat
::config_get_plugin
("output") eq "bar")
971 # Takes two optional args (channel server), toggles monitoring on/off
978 # Check if we've been told what channel to act on
982 @arg_array = split(/ /,$args);
983 # Check if a server was given
987 $bufp = weechat
::buffer_search
("irc", $arg_array[1].".".$arg_array[0]);
992 # Loop through defined servers
993 $infolist = weechat
::infolist_get
("buffer", "", "");
994 while (weechat
::infolist_next
($infolist))
996 # Only interesting in IRC buffers
997 if (weechat
::infolist_string
($infolist, "plugin_name") eq "irc")
999 # Find buffers that maych
1000 $sname = weechat
::infolist_string
($infolist, "short_name");
1001 if ($sname eq $arg_array[0])
1004 $bufp = weechat
::infolist_pointer
($infolist, "pointer");
1008 weechat
::infolist_free
($infolist);
1009 # If the infolist found more than one channel, halt as we need to know which one
1010 if ($found_chans > 1)
1012 weechat
::print("", "Channel name is not unique, please define server");
1013 return weechat
::WEECHAT_RC_OK
;
1016 # Something didn't return right
1019 weechat
::print("", "Could not find buffer");
1020 return weechat
::WEECHAT_RC_OK
;
1025 # Get pointer from where we are
1026 $bufp = weechat
::current_buffer
();
1029 $bufname = weechat
::buffer_get_string
($bufp, 'name');
1030 # Test if buffer is an IRC channel
1031 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
1033 if (weechat
::config_get_plugin
($bufname) eq "off")
1035 # If currently off, set on
1036 weechat
::config_set_plugin
($bufname, "on");
1038 # Send to output formatter
1039 highmon_print
("Highlight Monitoring Enabled", $bufp);
1040 return weechat
::WEECHAT_RC_OK
;
1042 elsif (weechat
::config_get_plugin
($bufname) eq "on" || weechat
::config_get_plugin
($bufname) eq "")
1044 # If currently on, set off
1045 weechat
::config_set_plugin
($bufname, "off");
1047 # Send to output formatter
1048 highmon_print
("Highlight Monitoring Disabled", $bufp);
1049 return weechat
::WEECHAT_RC_OK
;
1054 # Takes a buffer pointer and returns a formatted name
1055 sub format_buffer_name
1057 $cb_bufferp = $_[0];
1058 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
1060 # Set colour from buffer name
1061 if (weechat
::config_get_plugin
("color_buf") eq "on")
1063 # Determine what colour to use
1064 $color = weechat
::info_get
("irc_nick_color", $bufname);
1068 @char_array = split(//,$bufname);
1069 foreach $char (@char_array)
1071 $color += ord($char);
1074 $color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
1075 $color = weechat
::config_get
($color);
1076 $color = weechat
::config_string
($color);
1077 $color = weechat
::color
($color);
1080 # Private message just show network
1081 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1083 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1085 # Format name to short or 'nicename'
1086 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1088 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1092 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1095 # Build a coloured string
1096 $bufname = $color.$bufname.weechat
::color
("reset");
1098 # User set colour name
1099 elsif (weechat
::config_get_plugin
("color_buf") ne "off")
1101 # Private message just show network
1102 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1104 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1106 # Format name to short or 'nicename'
1107 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1109 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1113 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1116 $color = weechat
::config_get_plugin
("color_buf");
1117 $bufname = weechat
::color
($color).$bufname.weechat
::color
("reset");
1119 # Stick with default colour
1122 # Private message just show network
1123 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1125 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1127 # Format name to short or 'nicename'
1128 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1130 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1134 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1141 # Check result of register, and attempt to behave in a sane manner
1142 if (!weechat
::register
("highmon", "KenjiE20", "2.7", "GPL3", "Highlight Monitor", "", ""))
1145 weechat
::print ("", "\tHighmon is already loaded");
1146 return weechat
::WEECHAT_RC_OK
;
1152 highmon_config_init
();