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]
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 monitor [channel] [server] is used to toggle a highlight monitoring on and off, this
15 # can be used in the channel buffer for the channel you wish to toggle, or be given
16 # with arguments e.g. /highmon monitor #weechat freenode
18 # /set plugins.var.perl.highmon.alignment
19 # The config setting "alignment" can be changed to;
20 # "channel", "schannel", "nchannel", "channel,nick", "schannel,nick", "nchannel,nick"
21 # to change how the monitor appears
22 # The 'channel' value will show: "#weechat"
23 # The 'schannel' value will show: "6"
24 # The 'nchannel' value will show: "6:#weechat"
26 # /set plugins.var.perl.highmon.short_names
27 # Setting this to 'on' will trim the network name from highmon, ala buffers.pl
29 # /set plugins.var.perl.highmon.merge_private
30 # Setting this to 'on' will merge private messages to highmon's display
32 # /set plugins.var.perl.highmon.color_buf
33 # This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
34 # This *must* be a valid color name, or weechat will likely do unexpected things :)
36 # /set plugins.var.perl.highmon.hotlist_show
37 # Setting this to 'on' will let the highmon buffer appear in hotlists
38 # (status bar/buffer.pl)
40 # /set plugins.var.perl.highmon.away_only
41 # Setting this to 'on' will only put messages in the highmon buffer when
42 # you set your status to away
44 # /set plugins.var.perl.highmon.logging
45 # Toggles logging status for highmon buffer (default: off)
47 # /set plugins.var.perl.highmon.output
48 # Changes where output method of highmon; takes either "bar" or "buffer" (default; buffer)
49 # /set plugins.var.perl.highmon.bar_lines
50 # Changes the amount of lines the output bar will hold.
51 # (Only appears once output has been set to bar, defaults to 10)
52 # /set plugins.var.perl.highmon.bar_scrolldown
53 # Toggles the bar scrolling at the bottom when new highlights are received
54 # (Only appears once output has been set to bar, defaults to off)
56 # /set plugins.var.perl.highmon.nick_prefix
57 # /set plugins.var.perl.highmon.nick_suffix
58 # Sets the prefix and suffix chars in the highmon buffer
59 # (Defaults to <> if nothing set, and blank if there is)
62 # servername is the internal name for the server (set when you use /server add)
63 # #channel is the channel name, (where # is whatever channel type that channel happens to be)
66 # Bugs and feature requests at: https://github.com/KenjiE20/highmon
69 # 2013-12-04, KenjiE20 <longbow@longbowslair.co.uk>:
70 # v2.4: -add: Support for eval style colour codes in time format used for bar output
71 # 2013-10-22, KenjiE20 <longbow@longbowslair.co.uk>:
72 # v2.3.3.2: -fix: Typo in fix command
73 # 2013-10-10, KenjiE20 <longbow@longbowslair.co.uk>:
74 # v2.3.3.1: -fix: Typo in closed buffer warning
75 # 2013-10-07, KenjiE20 <longbow@longbowslair.co.uk>:
76 # v2.3.3: -add: Warning and fixer for accidental buffer closes
77 # 2013-01-15, KenjiE20 <longbow@longbowslair.co.uk>:
78 # v2.3.2: -fix: Let bar output use the string set in weechat's config option
80 # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
81 # v2.3.1: -fix: Colour tags in bar timestamp string
82 # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>:
83 # v2.3: -feature: Added merge_private option to display private messages (default: off)
84 # -fix: Channel name colours now show correctly when set to on
85 # 2011-08-07, Sitaktif <romainchossart_at_gmail.com>:
86 # v2.2.1: -feature: Add "bar_scrolldown" option to have the bar display the latest hl at anytime
87 # -fix: Set up bar-specific config at startup if 'output' is already configured as 'bar'
88 # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>:
89 # v2.2: -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours
90 # 2010-12-13, idl0r & KenjiE20 <longbow@longbowslair.co.uk>:
91 # v2.1.3: -fix: perl errors caused by bar line counter
92 # -fix: Add command list to inbuilt help
93 # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>:
94 # v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing)
95 # -version sync w/ chanmon
96 # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>:
97 # v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name
98 # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>:
99 # v2.0: Release as version 2.0
100 # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>:
101 # v1.9: Rewrite for v2.0
102 # Bring feature set in line with chanmon 2.0
103 # -code change: Made more subs to shrink the code down in places
104 # -fix: Stop highmon attempting to double load/hook
105 # -fix: Add version dependant check for away status
106 # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
107 # v1.7: -fixture: Let highmon be aware of nick_prefix/suffix
108 # and allow custom prefix/suffix for chanmon buffer
109 # (Defaults to <> if nothing set, and blank if there is)
110 # (Thanks to m4v for these)
111 # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
112 # v1.6: -feature: colored buffer names
113 # -change: version sync with chanmon
114 # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
115 # v1.2: -fix: disable buffer highlight
116 # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
117 # v.1.1.1 -change: Stop unsightly text block on '/help'
118 # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
119 # v1.1: In-client help added
120 # 2009-08-02, KenjiE20 <longbow@longbowslair.co.uk>:
121 # v1.0: Initial Public Release
123 # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
125 # This program is free software; you can redistribute it and/or modify
126 # it under the terms of the GNU General Public License as published by
127 # the Free Software Foundation; either version 3 of the License, or
128 # (at your option) any later version.
130 # This program is distributed in the hope that it will be useful,
131 # but WITHOUT ANY WARRANTY; without even the implied warranty of
132 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
133 # GNU General Public License for more details.
135 # You should have received a copy of the GNU General Public License
136 # along with this program. If not, see <http://www.gnu.org/licenses/>.
140 @bar_lines_time = ();
141 # Replicate info earlier for in-client help
143 $highmonhelp = weechat
::color
("bold")."/highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all]".weechat
::color
("-bold")."
144 Command wrapper for highmon commands
146 ".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
148 ".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
150 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.alignment".weechat
::color
("-bold")."
151 The config setting \"alignment\" can be changed to;
152 \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\"
153 to change how the monitor appears
154 The 'channel' value will show: \"#weechat\"
155 The 'schannel' value will show: \"6\"
156 The 'nchannel' value will show: \"6:#weechat\"
158 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.short_names".weechat
::color
("-bold")."
159 Setting this to 'on' will trim the network name from highmon, ala buffers.pl
161 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.merge_private".weechat
::color
("-bold")."
162 Setting this to 'on' will merge private messages to highmon's display
164 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.color_buf".weechat
::color
("-bold")."
165 This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
166 This ".weechat
::color
("bold")."must".weechat
::color
("-bold")." be a valid color name, or weechat will likely do unexpected things :)
168 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.hotlist_show".weechat
::color
("-bold")."
169 Setting this to 'on' will let the highmon buffer appear in hotlists (status bar/buffer.pl)
171 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.away_only".weechat
::color
("-bold")."
172 Setting this to 'on' will only put messages in the highmon buffer when you set your status to away
174 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.logging".weechat
::color
("-bold")."
175 Toggles logging status for highmon buffer (default: off)
177 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.output".weechat
::color
("-bold")."
178 Changes where output method of highmon; takes either \"bar\" or \"buffer\" (default; buffer)
179 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_lines".weechat
::color
("-bold")."
180 Changes the amount of lines the output bar will hold.
181 (Only appears once output has been set to bar, defaults to 10)
182 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_scrolldown".weechat
::color
("-bold")."
183 Toggles the bar scrolling at the bottom when new highlights are received
184 (Only appears once output has been set to bar, defaults to off)
186 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_prefix".weechat
::color
("-bold")."
187 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_suffix".weechat
::color
("-bold")."
188 Sets the prefix and suffix chars in the highmon buffer
189 (Defaults to <> if nothing set, and blank if there is)
191 ".weechat
::color
("bold")."servername.#channel".weechat
::color
("-bold")."
192 servername is the internal name for the server (set when you use /server add)
193 #channel is the channel name, (where # is whatever channel type that channel happens to be)";
197 weechat
::print("", "\t".weechat
::color
("bold")."Highmon Help".weechat
::color
("-bold")."\n\n");
198 weechat
::print("", "\t".$highmonhelp);
199 return weechat
::WEECHAT_RC_OK
;
203 sub highmon_bar_build
206 $max_lines = weechat
::config_get_plugin
("bar_lines");
207 $max_lines = $max_lines ? $max_lines : 10;
211 # Keep lines within max
212 while ($#bar_lines > $max_lines)
215 shift(@bar_lines_time);
217 # So long as we have some lines, build a string
221 $sep = " ".weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_suffix"))." ";
224 # Find max align needed
225 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
226 $align_num = $prefix_num if ($prefix_num > $align_num);
230 # Get align for this line
231 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
234 $str = $str.$bar_lines_time[$count]." ".(" " x
($align_num - $prefix_num)).$_."\n";
235 # Increment count for sync with time list
246 weechat
::bar_item_new
("highmon", "highmon_bar_build", "");
248 $highmon_bar = weechat
::bar_new
("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "highmon");
250 return weechat
::WEECHAT_RC_OK
;
253 sub highmon_bar_close
256 $highmon_bar = weechat
::bar_search
("highmon");
257 # If is does, close it
258 if ($highmon_bar ne "")
260 weechat
::bar_remove
($highmon_bar);
263 # Find if bar item exists
264 $highmon_bar_item = weechat
::bar_item_search
("highmon_bar");
265 # If is does, close it
266 if ($highmon_bar_item ne "")
268 weechat
::bar_remove
($highmon_bar_item);
272 return weechat
::WEECHAT_RC_OK
;
276 sub highmon_buffer_open
278 # Search for pre-existing buffer
279 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
282 if ($highmon_buffer eq "")
284 $highmon_buffer = weechat
::buffer_new
("highmon", "highmon_buffer_input", "", "highmon_buffer_close", "");
287 # Turn off notify, highlights
288 if ($highmon_buffer ne "")
290 if (weechat
::config_get_plugin
("hotlist_show" eq "off"))
292 weechat
::buffer_set
($highmon_buffer, "notify", "0");
294 weechat
::buffer_set
($highmon_buffer, "highlight_words", "-");
295 weechat
::buffer_set
($highmon_buffer, "title", "Highlight Monitor");
297 if (weechat
::config_get_plugin
("logging") eq "off")
299 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
302 return weechat
::WEECHAT_RC_OK
;
304 # Buffer input has no action
305 sub highmon_buffer_input
307 return weechat
::WEECHAT_RC_OK
;
310 sub highmon_buffer_close
312 $highmon_buffer = "";
313 # If user hasn't changed output style warn user
314 if (weechat
::config_get_plugin
("output") eq "buffer")
316 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"));
318 return weechat
::WEECHAT_RC_OK
;
321 # Highmon command wrapper
322 sub highmon_command_cb
333 @arg_array = split(/ /,$args);
334 # Take first as command
335 $cmd = shift(@arg_array);
336 # Rebuild string to pass to subs
339 $arg = join(" ", @arg_array);
344 if ($cmd eq "" || $cmd eq "help")
349 elsif ($cmd eq "monitor")
351 highmon_toggle
($data, $buffer, $arg);
354 elsif ($cmd eq "clean")
356 highmon_config_clean
($data, $buffer, $arg);
359 elsif ($cmd eq "fix")
361 if (weechat
::config_get_plugin
("output") eq "buffer" && $highmon_buffer eq "")
363 highmon_buffer_open
();
366 return weechat
::WEECHAT_RC_OK
;
369 # Clean up config entries
370 sub highmon_config_clean
376 # Don't do anything if bad option given
377 if ($args ne "default" && $args ne "orphan" && $args ne "all")
379 weechat
::print("", "\thighmon.pl: Unknown option");
380 return weechat
::WEECHAT_RC_OK
;
384 # Load an infolist of highmon options
385 $infolist = weechat
::infolist_get
("option", "", "*highmon*");
386 while (weechat
::infolist_next
($infolist))
388 $name = weechat
::infolist_string
($infolist, "option_name");
389 $name =~ s/perl\.highmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/;
390 if ($name =~ /^(.*)\.([#&\+!])(.*)$/)
394 if ($args eq "default" || $args eq "all")
396 # If value in config is "on"
397 if (weechat
::config_get_plugin
($name) eq "on")
399 # Unset and if successful flag as changed
400 $rc = weechat
::config_unset_plugin
($name);
401 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
408 if ($args eq "orphan" || $args eq "all")
410 # If we can't find the buffer for this entry
411 if (weechat
::buffer_search
("irc", $name) eq "")
413 # Unset and if successful flag as changed
414 $rc = weechat
::config_unset_plugin
($name);
415 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
421 # Add changed entry names to list
422 push (@chans, $name) if ($action);
425 weechat
::infolist_free
($infolist);
426 # If channels were cleaned from config
432 $str = "\thighmon.pl: Cleaned ".@chans." entry from the config:";
436 $str = "\thighmon.pl: Cleaned ".@chans." entries from the config:";
438 # Build a list of channels
443 # Print what happened
444 weechat
::print("",$str);
446 # Config seemed to be clean
449 weechat
::print("", "\thighmon.pl: No entries removed");
451 return weechat
::WEECHAT_RC_OK
;
454 # Check config elements
455 sub highmon_config_init
458 if (!(weechat
::config_is_set_plugin
("alignment")))
460 weechat
::config_set_plugin
("alignment", "channel");
462 if (weechat
::config_get_plugin
("alignment") eq "")
464 weechat
::config_set_plugin
("alignment", "none");
468 if (!(weechat
::config_is_set_plugin
("short_names")))
470 weechat
::config_set_plugin
("short_names", "off");
473 # Coloured names default
474 if (!(weechat
::config_is_set_plugin
("color_buf")))
476 weechat
::config_set_plugin
("color_buf", "on");
479 # Hotlist show default
480 if (!(weechat
::config_is_set_plugin
("hotlist_show")))
482 weechat
::config_set_plugin
("hotlist_show", "off");
486 if (!(weechat
::config_is_set_plugin
("away_only")))
488 weechat
::config_set_plugin
("away_only", "off");
491 # highmon log default
492 if (!(weechat
::config_is_set_plugin
("logging")))
494 weechat
::config_set_plugin
("logging", "off");
498 if (!(weechat
::config_is_set_plugin
("output")))
500 weechat
::config_set_plugin
("output", "buffer");
503 # Private message merging
504 if (!(weechat
::config_is_set_plugin
("merge_private")))
506 weechat
::config_set_plugin
("merge_private", "off");
509 # Set bar config in case output was set to "bar" before even changing the setting
510 if (weechat
::config_get_plugin
("output") eq "bar")
512 # Output bar lines default
513 if (!(weechat
::config_is_set_plugin
("bar_lines")))
515 weechat
::config_set_plugin
("bar_lines", "10");
517 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
519 weechat
::config_set_plugin
("bar_scrolldown", "off");
523 # Check for exisiting prefix/suffix chars, and setup accordingly
524 $prefix = weechat
::config_get
("irc.look.nick_prefix");
525 $prefix = weechat
::config_string
($prefix);
526 $suffix = weechat
::config_get
("irc.look.nick_suffix");
527 $suffix = weechat
::config_string
($suffix);
529 if (!(weechat
::config_is_set_plugin
("nick_prefix")))
531 if ($prefix eq "" && $suffix eq "")
533 weechat
::config_set_plugin
("nick_prefix", "<");
537 weechat
::config_set_plugin
("nick_prefix", "");
541 if (!(weechat
::config_is_set_plugin
("nick_suffix")))
543 if ($prefix eq "" && $suffix eq "")
545 weechat
::config_set_plugin
("nick_suffix", ">");
549 weechat
::config_set_plugin
("nick_suffix", "");
555 sub highmon_config_cb
561 $name =~ s/^plugins\.var\.perl\.highmon\.//;
563 # Set logging on buffer
564 if ($name eq "logging")
566 # Search for pre-existing buffer
567 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
570 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
574 weechat
::buffer_set
($highmon_buffer, "localvar_del_no_log", "");
578 elsif ($name eq "output")
582 # Search for pre-existing buffer
583 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
585 if ($highmon_buffer ne "")
587 weechat
::buffer_close
($highmon_buffer)
590 # Output bar lines default
591 if (!(weechat
::config_is_set_plugin
("bar_lines")))
593 weechat
::config_set_plugin
("bar_lines", "10");
595 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
597 weechat
::config_set_plugin
("bar_scrolldown", "off");
599 # Make a bar if doesn't exist
602 elsif ($value eq "buffer")
604 # If a bar exists, close it
607 highmon_buffer_open
();
611 # Change if hotlist config changes
612 elsif ($name eq "hotlist_show")
614 # Search for pre-existing buffer
615 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
616 if ($value eq "off" && $highmon_buffer)
618 weechat
::buffer_set
($highmon_buffer, "notify", "0");
620 elsif ($value ne "off" && $highmon_buffer)
622 weechat
::buffer_set
($highmon_buffer, "notify", "3");
625 elsif ($name eq "weechat.look.prefix_suffix")
627 if (weechat
::config_get_plugin
("output") eq "bar")
630 weechat
::print("", "\thighmon: weechat.look.prefix_suffix changed, clearing highmon bar");
631 weechat
::bar_item_update
("highmon");
634 return weechat
::WEECHAT_RC_OK
;
637 # Set up weechat hooks / commands
640 weechat
::hook_print
("", "", "", 0, "highmon_new_message", "");
641 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", "");
643 weechat
::hook_command
("highmon", "Highmon help", "[help] | [monitor [channel [server]]] | [clean default|orphan|all]", " help: Print help on config options for highmon\n monitor: Toggles monitoring for a channel\n clean: Highmon config clean up (/highclean)", "help || monitor %(irc_channels) %(irc_servers) || clean default|orphan|all", "highmon_command_cb", "");
645 weechat
::hook_config
("plugins.var.perl.highmon.*", "highmon_config_cb", "");
646 weechat
::hook_config
("weechat.look.prefix_suffix", "highmon_config_cb", "");
649 # Main body, Callback for hook_print
650 sub highmon_new_message
656 my $window_displayed = "";
660 # $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
661 # weechat::print("", "\t".$string);
672 # Only work on highlighted messages or private message when enabled
673 if ($cb_high == "1" || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/))
675 # Pre bug #29618 (0.3.3) away detect
676 if (weechat
::info_get
("version_number", "") <= 197120)
679 # Get infolist for this server
680 $infolist = weechat
::infolist_get
("irc_server", "", weechat
::buffer_get_string
($cb_bufferp, "localvar_server"));
681 while (weechat
::infolist_next
($infolist))
683 # Get away message is is_away is on
684 $away = weechat
::infolist_string
($infolist, "away_message") if (weechat
::infolist_integer
($infolist, "is_away"));
686 weechat
::infolist_free
($infolist);
688 # Post bug #29618 fix
691 $away = weechat
::buffer_get_string
($cb_bufferp, "localvar_away");
693 if (weechat
::config_get_plugin
("away_only") ne "on" || ($away ne ""))
695 # Check buffer name is an IRC channel
696 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
697 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
699 # Are we running on this channel
700 if (weechat
::config_get_plugin
($bufname) ne "off" && $cb_disp eq "1")
703 # Line isn't action or topic notify
704 if (!($cb_tags =~ /irc_action/) && !($cb_tags =~ /irc_topic/))
707 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
709 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
712 elsif ($cb_tags =~ /irc_topic/)
714 $nick = " ".$cb_prefix.weechat
::color
("reset");
719 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
720 $nick = weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset");
723 highmon_print
($cb_msg, $cb_bufferp, $nick);
726 # Or is private message
727 elsif (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/)
730 $uncolnick = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
732 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
734 highmon_print
($cb_msg, $cb_bufferp, $nick);
738 return weechat
::WEECHAT_RC_OK
;
741 # Output formatter and printer takes (msg bufpointer nick)
745 my $cb_bufferp = $_[1] if ($_[1]);
746 my $nick = $_[2] if ($_[2]);
748 #Normal channel message
749 if ($cb_bufferp && $nick)
752 $bufname = format_buffer_name
($cb_bufferp);
754 # If alignment is #channel | nick msg
755 if (weechat
::config_get_plugin
("alignment") eq "channel")
757 $nick =~ s/\s(.*)/$1/;
759 $outstr = $bufname."\t".$nick." ".$cb_msg;
761 # or if it is channel number | nick msg
762 elsif (weechat
::config_get_plugin
("alignment") eq "schannel")
764 $nick =~ s/\s(.*)/$1/;
765 # Use channel number instead
766 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
768 $outstr = $bufname."\t".$nick." ".$cb_msg;
770 # or if it is number:#channel | nick msg
771 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel")
773 $nick =~ s/\s(.*)/$1/;
774 # Place channel number in front of formatted name
775 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
777 $outstr = $bufname."\t".$nick." ".$cb_msg;
779 # or if it is #channel nick | msg
780 elsif (weechat
::config_get_plugin
("alignment") eq "channel,nick")
783 $outstr = $bufname.":".$nick."\t".$cb_msg;
785 # or if it is channel number nick | msg
786 elsif (weechat
::config_get_plugin
("alignment") eq "schannel,nick")
788 # Use channel number instead
789 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
791 $outstr = $bufname.":".$nick."\t".$cb_msg;
793 # or if it is number:#channel nick | msg
794 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel,nick")
796 # Place channel number in front of formatted name
797 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
799 $outstr = $bufname.":".$nick."\t".$cb_msg;
801 # or finally | #channel nick msg
805 $outstr = "\t".$bufname.":".$nick." ".$cb_msg;
808 # highmon channel toggle message
809 elsif ($cb_bufferp && !$nick)
812 $bufname = format_buffer_name
($cb_bufferp);
814 # If alignment is #channel * | *
815 if (weechat
::config_get_plugin
("alignment") =~ /channel/)
817 # If it's actually channel number * | *
818 if (weechat
::config_get_plugin
("alignment") =~ /schannel/)
820 # Use channel number instead
821 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
823 # Or if it's actually number:#channel * | *
824 if (weechat
::config_get_plugin
("alignment") =~ /nchannel/)
826 # Place channel number in front of formatted name
827 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
829 $outstr = $bufname."\t".$cb_msg;
831 # or if alignment is | *
834 $outstr = $bufname.": ".$cb_msg;
838 elsif (!$cb_bufferp && !$nick)
840 $outstr = "\t".$cb_msg;
843 # Send string to buffer
844 if (weechat
::config_get_plugin
("output") eq "buffer")
846 # Search for and confirm buffer
847 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
849 weechat
::print($highmon_buffer, $outstr);
851 elsif (weechat
::config_get_plugin
("output") eq "bar")
854 use POSIX
qw(strftime);
855 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime);
857 if ($time =~ /\$\{(?:color:)?[\w,]+\}/) # Coloured string
859 while ($time =~ /\$\{(?:color:)?([\w,]+)\}/)
861 $color = weechat
::color
($1);
862 $time =~ s/\$\{(?:color:)?[\w,]+\}/$color/;
864 $time .= weechat
::color
("reset");
866 else # Default string
868 $colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_time_delimiters")));
869 $reset = weechat
::color
("reset");
870 $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g;
872 # Push updates to bar lists
873 push (@bar_lines_time, $time);
876 $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")." ";
877 $outstr =~ s/\t/$delim/;
879 push (@bar_lines, $outstr);
881 weechat
::bar_item_update
("highmon");
883 if (weechat
::config_get_plugin
("bar_scrolldown") eq "on")
885 weechat
::command
("", "/bar scroll highmon * ye")
890 # Start the output display
893 if (weechat
::config_get_plugin
("output") eq "buffer")
895 highmon_buffer_open
();
897 elsif (weechat
::config_get_plugin
("output") eq "bar")
903 # Takes two optional args (channel server), toggles monitoring on/off
910 # Check if we've been told what channel to act on
914 @arg_array = split(/ /,$args);
915 # Check if a server was given
919 $bufp = weechat
::buffer_search
("irc", $arg_array[1].".".$arg_array[0]);
924 # Loop through defined servers
925 $infolist = weechat
::infolist_get
("buffer", "", "");
926 while (weechat
::infolist_next
($infolist))
928 # Only interesting in IRC buffers
929 if (weechat
::infolist_string
($infolist, "plugin_name") eq "irc")
931 # Find buffers that maych
932 $sname = weechat
::infolist_string
($infolist, "short_name");
933 if ($sname eq $arg_array[0])
936 $bufp = weechat
::infolist_pointer
($infolist, "pointer");
940 weechat
::infolist_free
($infolist);
941 # If the infolist found more than one channel, halt as we need to know which one
942 if ($found_chans > 1)
944 weechat
::print("", "Channel name is not unique, please define server");
945 return weechat
::WEECHAT_RC_OK
;
948 # Something didn't return right
951 weechat
::print("", "Could not find buffer");
952 return weechat
::WEECHAT_RC_OK
;
957 # Get pointer from where we are
958 $bufp = weechat
::current_buffer
();
961 $bufname = weechat
::buffer_get_string
($bufp, 'name');
962 # Test if buffer is an IRC channel
963 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
965 if (weechat
::config_get_plugin
($bufname) eq "off")
967 # If currently off, set on
968 weechat
::config_set_plugin
($bufname, "on");
970 # Send to output formatter
971 highmon_print
("Highlight Monitoring Enabled", $bufp);
972 return weechat
::WEECHAT_RC_OK
;
974 elsif (weechat
::config_get_plugin
($bufname) eq "on" || weechat
::config_get_plugin
($bufname) eq "")
976 # If currently on, set off
977 weechat
::config_set_plugin
($bufname, "off");
979 # Send to output formatter
980 highmon_print
("Highlight Monitoring Disabled", $bufp);
981 return weechat
::WEECHAT_RC_OK
;
986 # Takes a buffer pointer and returns a formatted name
987 sub format_buffer_name
990 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
992 # Set colour from buffer name
993 if (weechat
::config_get_plugin
("color_buf") eq "on")
995 # Determine what colour to use
996 $color = weechat
::info_get
("irc_nick_color", $bufname);
1000 @char_array = split(//,$bufname);
1001 foreach $char (@char_array)
1003 $color += ord($char);
1006 $color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
1007 $color = weechat
::config_get
($color);
1008 $color = weechat
::config_string
($color);
1009 $color = weechat
::color
($color);
1012 # Private message just show network
1013 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1015 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1017 # Format name to short or 'nicename'
1018 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1020 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1024 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1027 # Build a coloured string
1028 $bufname = $color.$bufname.weechat
::color
("reset");
1030 # User set colour name
1031 elsif (weechat
::config_get_plugin
("color_buf") ne "off")
1033 # Private message just show network
1034 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1036 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1038 # Format name to short or 'nicename'
1039 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1041 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1045 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1048 $color = weechat
::config_get_plugin
("color_buf");
1049 $bufname = weechat
::color
($color).$bufname.weechat
::color
("reset");
1051 # Stick with default colour
1054 # Private message just show network
1055 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1057 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1059 # Format name to short or 'nicename'
1060 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1062 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1066 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1073 # Check result of register, and attempt to behave in a sane manner
1074 if (!weechat
::register
("highmon", "KenjiE20", "2.4", "GPL3", "Highlight Monitor", "", ""))
1077 weechat
::print ("", "\tHighmon is already loaded");
1078 return weechat
::WEECHAT_RC_OK
;
1084 highmon_config_init
();