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-10-22, KenjiE20 <longbow@longbowslair.co.uk>:
70 # v2.3.3.2: -fix: Typo in fix command
71 # 2013-10-10, KenjiE20 <longbow@longbowslair.co.uk>:
72 # v2.3.3.1: -fix: Typo in closed buffer warning
73 # 2013-10-07, KenjiE20 <longbow@longbowslair.co.uk>:
74 # v2.3.3: -add: Warning and fixer for accidental buffer closes
75 # 2013-01-15, KenjiE20 <longbow@longbowslair.co.uk>:
76 # v2.3.2: -fix: Let bar output use the string set in weechat's config option
78 # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
79 # v2.3.1: -fix: Colour tags in bar timestamp string
80 # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>:
81 # v2.3: -feature: Added merge_private option to display private messages (default: off)
82 # -fix: Channel name colours now show correctly when set to on
83 # 2011-08-07, Sitaktif <romainchossart_at_gmail.com>:
84 # v2.2.1: -feature: Add "bar_scrolldown" option to have the bar display the latest hl at anytime
85 # -fix: Set up bar-specific config at startup if 'output' is already configured as 'bar'
86 # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>:
87 # v2.2: -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours
88 # 2010-12-13, idl0r & KenjiE20 <longbow@longbowslair.co.uk>:
89 # v2.1.3: -fix: perl errors caused by bar line counter
90 # -fix: Add command list to inbuilt help
91 # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>:
92 # v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing)
93 # -version sync w/ chanmon
94 # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>:
95 # v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name
96 # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>:
97 # v2.0: Release as version 2.0
98 # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>:
99 # v1.9: Rewrite for v2.0
100 # Bring feature set in line with chanmon 2.0
101 # -code change: Made more subs to shrink the code down in places
102 # -fix: Stop highmon attempting to double load/hook
103 # -fix: Add version dependant check for away status
104 # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
105 # v1.7: -fixture: Let highmon be aware of nick_prefix/suffix
106 # and allow custom prefix/suffix for chanmon buffer
107 # (Defaults to <> if nothing set, and blank if there is)
108 # (Thanks to m4v for these)
109 # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
110 # v1.6: -feature: colored buffer names
111 # -change: version sync with chanmon
112 # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
113 # v1.2: -fix: disable buffer highlight
114 # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
115 # v.1.1.1 -change: Stop unsightly text block on '/help'
116 # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
117 # v1.1: In-client help added
118 # 2009-08-02, KenjiE20 <longbow@longbowslair.co.uk>:
119 # v1.0: Initial Public Release
121 # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
123 # This program is free software; you can redistribute it and/or modify
124 # it under the terms of the GNU General Public License as published by
125 # the Free Software Foundation; either version 3 of the License, or
126 # (at your option) any later version.
128 # This program is distributed in the hope that it will be useful,
129 # but WITHOUT ANY WARRANTY; without even the implied warranty of
130 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
131 # GNU General Public License for more details.
133 # You should have received a copy of the GNU General Public License
134 # along with this program. If not, see <http://www.gnu.org/licenses/>.
138 @bar_lines_time = ();
139 # Replicate info earlier for in-client help
141 $highmonhelp = weechat
::color
("bold")."/highmon [help] | [monitor [channel [server]]] | [clean default|orphan|all]".weechat
::color
("-bold")."
142 Command wrapper for highmon commands
144 ".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
146 ".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
148 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.alignment".weechat
::color
("-bold")."
149 The config setting \"alignment\" can be changed to;
150 \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\"
151 to change how the monitor appears
152 The 'channel' value will show: \"#weechat\"
153 The 'schannel' value will show: \"6\"
154 The 'nchannel' value will show: \"6:#weechat\"
156 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.short_names".weechat
::color
("-bold")."
157 Setting this to 'on' will trim the network name from highmon, ala buffers.pl
159 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.merge_private".weechat
::color
("-bold")."
160 Setting this to 'on' will merge private messages to highmon's display
162 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.color_buf".weechat
::color
("-bold")."
163 This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
164 This ".weechat
::color
("bold")."must".weechat
::color
("-bold")." be a valid color name, or weechat will likely do unexpected things :)
166 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.hotlist_show".weechat
::color
("-bold")."
167 Setting this to 'on' will let the highmon buffer appear in hotlists (status bar/buffer.pl)
169 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.away_only".weechat
::color
("-bold")."
170 Setting this to 'on' will only put messages in the highmon buffer when you set your status to away
172 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.logging".weechat
::color
("-bold")."
173 Toggles logging status for highmon buffer (default: off)
175 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.output".weechat
::color
("-bold")."
176 Changes where output method of highmon; takes either \"bar\" or \"buffer\" (default; buffer)
177 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_lines".weechat
::color
("-bold")."
178 Changes the amount of lines the output bar will hold.
179 (Only appears once output has been set to bar, defaults to 10)
180 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.bar_scrolldown".weechat
::color
("-bold")."
181 Toggles the bar scrolling at the bottom when new highlights are received
182 (Only appears once output has been set to bar, defaults to off)
184 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_prefix".weechat
::color
("-bold")."
185 ".weechat
::color
("bold")."/set plugins.var.perl.highmon.nick_suffix".weechat
::color
("-bold")."
186 Sets the prefix and suffix chars in the highmon buffer
187 (Defaults to <> if nothing set, and blank if there is)
189 ".weechat
::color
("bold")."servername.#channel".weechat
::color
("-bold")."
190 servername is the internal name for the server (set when you use /server add)
191 #channel is the channel name, (where # is whatever channel type that channel happens to be)";
195 weechat
::print("", "\t".weechat
::color
("bold")."Highmon Help".weechat
::color
("-bold")."\n\n");
196 weechat
::print("", "\t".$highmonhelp);
197 return weechat
::WEECHAT_RC_OK
;
201 sub highmon_bar_build
204 $max_lines = weechat
::config_get_plugin
("bar_lines");
205 $max_lines = $max_lines ? $max_lines : 10;
209 # Keep lines within max
210 while ($#bar_lines > $max_lines)
213 shift(@bar_lines_time);
215 # So long as we have some lines, build a string
219 $sep = " ".weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_suffix"))." ";
222 # Find max align needed
223 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
224 $align_num = $prefix_num if ($prefix_num > $align_num);
228 # Get align for this line
229 $prefix_num = (index(weechat
::string_remove_color
($_, ""), $sep));
232 $str = $str.$bar_lines_time[$count]." ".(" " x
($align_num - $prefix_num)).$_."\n";
233 # Increment count for sync with time list
244 weechat
::bar_item_new
("highmon", "highmon_bar_build", "");
246 $highmon_bar = weechat
::bar_new
("highmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "highmon");
248 return weechat
::WEECHAT_RC_OK
;
251 sub highmon_bar_close
254 $highmon_bar = weechat
::bar_search
("highmon");
255 # If is does, close it
256 if ($highmon_bar ne "")
258 weechat
::bar_remove
($highmon_bar);
261 # Find if bar item exists
262 $highmon_bar_item = weechat
::bar_item_search
("highmon_bar");
263 # If is does, close it
264 if ($highmon_bar_item ne "")
266 weechat
::bar_remove
($highmon_bar_item);
270 return weechat
::WEECHAT_RC_OK
;
274 sub highmon_buffer_open
276 # Search for pre-existing buffer
277 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
280 if ($highmon_buffer eq "")
282 $highmon_buffer = weechat
::buffer_new
("highmon", "highmon_buffer_input", "", "highmon_buffer_close", "");
285 # Turn off notify, highlights
286 if ($highmon_buffer ne "")
288 if (weechat
::config_get_plugin
("hotlist_show" eq "off"))
290 weechat
::buffer_set
($highmon_buffer, "notify", "0");
292 weechat
::buffer_set
($highmon_buffer, "highlight_words", "-");
293 weechat
::buffer_set
($highmon_buffer, "title", "Highlight Monitor");
295 if (weechat
::config_get_plugin
("logging") eq "off")
297 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
300 return weechat
::WEECHAT_RC_OK
;
302 # Buffer input has no action
303 sub highmon_buffer_input
305 return weechat
::WEECHAT_RC_OK
;
308 sub highmon_buffer_close
310 $highmon_buffer = "";
311 # If user hasn't changed output style warn user
312 if (weechat
::config_get_plugin
("output") eq "buffer")
314 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"));
316 return weechat
::WEECHAT_RC_OK
;
319 # Highmon command wrapper
320 sub highmon_command_cb
331 @arg_array = split(/ /,$args);
332 # Take first as command
333 $cmd = shift(@arg_array);
334 # Rebuild string to pass to subs
337 $arg = join(" ", @arg_array);
342 if ($cmd eq "" || $cmd eq "help")
347 elsif ($cmd eq "monitor")
349 highmon_toggle
($data, $buffer, $arg);
352 elsif ($cmd eq "clean")
354 highmon_config_clean
($data, $buffer, $arg);
357 elsif ($cmd eq "fix")
359 if (weechat
::config_get_plugin
("output") eq "buffer" && $highmon_buffer eq "")
361 highmon_buffer_open
();
364 return weechat
::WEECHAT_RC_OK
;
367 # Clean up config entries
368 sub highmon_config_clean
374 # Don't do anything if bad option given
375 if ($args ne "default" && $args ne "orphan" && $args ne "all")
377 weechat
::print("", "\thighmon.pl: Unknown option");
378 return weechat
::WEECHAT_RC_OK
;
382 # Load an infolist of highmon options
383 $infolist = weechat
::infolist_get
("option", "", "*highmon*");
384 while (weechat
::infolist_next
($infolist))
386 $name = weechat
::infolist_string
($infolist, "option_name");
387 $name =~ s/perl\.highmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/;
388 if ($name =~ /^(.*)\.([#&\+!])(.*)$/)
392 if ($args eq "default" || $args eq "all")
394 # If value in config is "on"
395 if (weechat
::config_get_plugin
($name) eq "on")
397 # Unset and if successful flag as changed
398 $rc = weechat
::config_unset_plugin
($name);
399 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
406 if ($args eq "orphan" || $args eq "all")
408 # If we can't find the buffer for this entry
409 if (weechat
::buffer_search
("irc", $name) eq "")
411 # Unset and if successful flag as changed
412 $rc = weechat
::config_unset_plugin
($name);
413 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
419 # Add changed entry names to list
420 push (@chans, $name) if ($action);
423 weechat
::infolist_free
($infolist);
424 # If channels were cleaned from config
430 $str = "\thighmon.pl: Cleaned ".@chans." entry from the config:";
434 $str = "\thighmon.pl: Cleaned ".@chans." entries from the config:";
436 # Build a list of channels
441 # Print what happened
442 weechat
::print("",$str);
444 # Config seemed to be clean
447 weechat
::print("", "\thighmon.pl: No entries removed");
449 return weechat
::WEECHAT_RC_OK
;
452 # Check config elements
453 sub highmon_config_init
456 if (!(weechat
::config_is_set_plugin
("alignment")))
458 weechat
::config_set_plugin
("alignment", "channel");
460 if (weechat
::config_get_plugin
("alignment") eq "")
462 weechat
::config_set_plugin
("alignment", "none");
466 if (!(weechat
::config_is_set_plugin
("short_names")))
468 weechat
::config_set_plugin
("short_names", "off");
471 # Coloured names default
472 if (!(weechat
::config_is_set_plugin
("color_buf")))
474 weechat
::config_set_plugin
("color_buf", "on");
477 # Hotlist show default
478 if (!(weechat
::config_is_set_plugin
("hotlist_show")))
480 weechat
::config_set_plugin
("hotlist_show", "off");
484 if (!(weechat
::config_is_set_plugin
("away_only")))
486 weechat
::config_set_plugin
("away_only", "off");
489 # highmon log default
490 if (!(weechat
::config_is_set_plugin
("logging")))
492 weechat
::config_set_plugin
("logging", "off");
496 if (!(weechat
::config_is_set_plugin
("output")))
498 weechat
::config_set_plugin
("output", "buffer");
501 # Private message merging
502 if (!(weechat
::config_is_set_plugin
("merge_private")))
504 weechat
::config_set_plugin
("merge_private", "off");
507 # Set bar config in case output was set to "bar" before even changing the setting
508 if (weechat
::config_get_plugin
("output") eq "bar")
510 # Output bar lines default
511 if (!(weechat
::config_is_set_plugin
("bar_lines")))
513 weechat
::config_set_plugin
("bar_lines", "10");
515 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
517 weechat
::config_set_plugin
("bar_scrolldown", "off");
521 # Check for exisiting prefix/suffix chars, and setup accordingly
522 $prefix = weechat
::config_get
("irc.look.nick_prefix");
523 $prefix = weechat
::config_string
($prefix);
524 $suffix = weechat
::config_get
("irc.look.nick_suffix");
525 $suffix = weechat
::config_string
($suffix);
527 if (!(weechat
::config_is_set_plugin
("nick_prefix")))
529 if ($prefix eq "" && $suffix eq "")
531 weechat
::config_set_plugin
("nick_prefix", "<");
535 weechat
::config_set_plugin
("nick_prefix", "");
539 if (!(weechat
::config_is_set_plugin
("nick_suffix")))
541 if ($prefix eq "" && $suffix eq "")
543 weechat
::config_set_plugin
("nick_suffix", ">");
547 weechat
::config_set_plugin
("nick_suffix", "");
553 sub highmon_config_cb
559 $name =~ s/^plugins\.var\.perl\.highmon\.//;
561 # Set logging on buffer
562 if ($name eq "logging")
564 # Search for pre-existing buffer
565 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
568 weechat
::buffer_set
($highmon_buffer, "localvar_set_no_log", "1");
572 weechat
::buffer_set
($highmon_buffer, "localvar_del_no_log", "");
576 elsif ($name eq "output")
580 # Search for pre-existing buffer
581 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
583 if ($highmon_buffer ne "")
585 weechat
::buffer_close
($highmon_buffer)
588 # Output bar lines default
589 if (!(weechat
::config_is_set_plugin
("bar_lines")))
591 weechat
::config_set_plugin
("bar_lines", "10");
593 if (!(weechat
::config_is_set_plugin
("bar_scrolldown")))
595 weechat
::config_set_plugin
("bar_scrolldown", "off");
597 # Make a bar if doesn't exist
600 elsif ($value eq "buffer")
602 # If a bar exists, close it
605 highmon_buffer_open
();
609 # Change if hotlist config changes
610 elsif ($name eq "hotlist_show")
612 # Search for pre-existing buffer
613 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
614 if ($value eq "off" && $highmon_buffer)
616 weechat
::buffer_set
($highmon_buffer, "notify", "0");
618 elsif ($value ne "off" && $highmon_buffer)
620 weechat
::buffer_set
($highmon_buffer, "notify", "3");
623 elsif ($name eq "weechat.look.prefix_suffix")
625 if (weechat
::config_get_plugin
("output") eq "bar")
628 weechat
::print("", "\thighmon: weechat.look.prefix_suffix changed, clearing highmon bar");
629 weechat
::bar_item_update
("highmon");
632 return weechat
::WEECHAT_RC_OK
;
635 # Set up weechat hooks / commands
638 weechat
::hook_print
("", "", "", 0, "highmon_new_message", "");
639 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", "");
641 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", "");
643 weechat
::hook_config
("plugins.var.perl.highmon.*", "highmon_config_cb", "");
644 weechat
::hook_config
("weechat.look.prefix_suffix", "highmon_config_cb", "");
647 # Main body, Callback for hook_print
648 sub highmon_new_message
654 my $window_displayed = "";
658 # $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
659 # weechat::print("", "\t".$string);
670 # Only work on highlighted messages or private message when enabled
671 if ($cb_high == "1" || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/))
673 # Pre bug #29618 (0.3.3) away detect
674 if (weechat
::info_get
("version_number", "") <= 197120)
677 # Get infolist for this server
678 $infolist = weechat
::infolist_get
("irc_server", "", weechat
::buffer_get_string
($cb_bufferp, "localvar_server"));
679 while (weechat
::infolist_next
($infolist))
681 # Get away message is is_away is on
682 $away = weechat
::infolist_string
($infolist, "away_message") if (weechat
::infolist_integer
($infolist, "is_away"));
684 weechat
::infolist_free
($infolist);
686 # Post bug #29618 fix
689 $away = weechat
::buffer_get_string
($cb_bufferp, "localvar_away");
691 if (weechat
::config_get_plugin
("away_only") ne "on" || ($away ne ""))
693 # Check buffer name is an IRC channel
694 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
695 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
697 # Are we running on this channel
698 if (weechat
::config_get_plugin
($bufname) ne "off" && $cb_disp eq "1")
701 # Line isn't action or topic notify
702 if (!($cb_tags =~ /irc_action/) && !($cb_tags =~ /irc_topic/))
705 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
707 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
710 elsif ($cb_tags =~ /irc_topic/)
712 $nick = " ".$cb_prefix.weechat
::color
("reset");
717 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
718 $nick = weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset");
721 highmon_print
($cb_msg, $cb_bufferp, $nick);
724 # Or is private message
725 elsif (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/)
728 $uncolnick = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
730 $nick = " ".weechat
::config_get_plugin
("nick_prefix").weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
732 highmon_print
($cb_msg, $cb_bufferp, $nick);
736 return weechat
::WEECHAT_RC_OK
;
739 # Output formatter and printer takes (msg bufpointer nick)
743 my $cb_bufferp = $_[1] if ($_[1]);
744 my $nick = $_[2] if ($_[2]);
746 #Normal channel message
747 if ($cb_bufferp && $nick)
750 $bufname = format_buffer_name
($cb_bufferp);
752 # If alignment is #channel | nick msg
753 if (weechat
::config_get_plugin
("alignment") eq "channel")
755 $nick =~ s/\s(.*)/$1/;
757 $outstr = $bufname."\t".$nick." ".$cb_msg;
759 # or if it is channel number | nick msg
760 elsif (weechat
::config_get_plugin
("alignment") eq "schannel")
762 $nick =~ s/\s(.*)/$1/;
763 # Use channel number instead
764 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
766 $outstr = $bufname."\t".$nick." ".$cb_msg;
768 # or if it is number:#channel | nick msg
769 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel")
771 $nick =~ s/\s(.*)/$1/;
772 # Place channel number in front of formatted name
773 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
775 $outstr = $bufname."\t".$nick." ".$cb_msg;
777 # or if it is #channel nick | msg
778 elsif (weechat
::config_get_plugin
("alignment") eq "channel,nick")
781 $outstr = $bufname.":".$nick."\t".$cb_msg;
783 # or if it is channel number nick | msg
784 elsif (weechat
::config_get_plugin
("alignment") eq "schannel,nick")
786 # Use channel number instead
787 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
789 $outstr = $bufname.":".$nick."\t".$cb_msg;
791 # or if it is number:#channel nick | msg
792 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel,nick")
794 # Place channel number in front of formatted name
795 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
797 $outstr = $bufname.":".$nick."\t".$cb_msg;
799 # or finally | #channel nick msg
803 $outstr = "\t".$bufname.":".$nick." ".$cb_msg;
806 # highmon channel toggle message
807 elsif ($cb_bufferp && !$nick)
810 $bufname = format_buffer_name
($cb_bufferp);
812 # If alignment is #channel * | *
813 if (weechat
::config_get_plugin
("alignment") =~ /channel/)
815 # If it's actually channel number * | *
816 if (weechat
::config_get_plugin
("alignment") =~ /schannel/)
818 # Use channel number instead
819 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
821 # Or if it's actually number:#channel * | *
822 if (weechat
::config_get_plugin
("alignment") =~ /nchannel/)
824 # Place channel number in front of formatted name
825 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
827 $outstr = $bufname."\t".$cb_msg;
829 # or if alignment is | *
832 $outstr = $bufname.": ".$cb_msg;
836 elsif (!$cb_bufferp && !$nick)
838 $outstr = "\t".$cb_msg;
841 # Send string to buffer
842 if (weechat
::config_get_plugin
("output") eq "buffer")
844 # Search for and confirm buffer
845 $highmon_buffer = weechat
::buffer_search
("perl", "highmon");
847 weechat
::print($highmon_buffer, $outstr);
849 elsif (weechat
::config_get_plugin
("output") eq "bar")
852 use POSIX
qw(strftime);
853 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime);
855 if ($time =~ /\$\{\w+\}/) # Coloured string
857 while ($time =~ /\$\{(\w+)\}/)
859 $color = weechat
::color
($1);
860 $time =~ s/\$\{\w+\}/$color/;
863 else # Default string
865 $colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_time_delimiters")));
866 $reset = weechat
::color
("reset");
867 $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g;
869 # Push updates to bar lists
870 push (@bar_lines_time, $time);
873 $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")." ";
874 $outstr =~ s/\t/$delim/;
876 push (@bar_lines, $outstr);
878 weechat
::bar_item_update
("highmon");
880 if (weechat
::config_get_plugin
("bar_scrolldown") eq "on")
882 weechat
::command
("", "/bar scroll highmon * ye")
887 # Start the output display
890 if (weechat
::config_get_plugin
("output") eq "buffer")
892 highmon_buffer_open
();
894 elsif (weechat
::config_get_plugin
("output") eq "bar")
900 # Takes two optional args (channel server), toggles monitoring on/off
907 # Check if we've been told what channel to act on
911 @arg_array = split(/ /,$args);
912 # Check if a server was given
916 $bufp = weechat
::buffer_search
("irc", $arg_array[1].".".$arg_array[0]);
921 # Loop through defined servers
922 $infolist = weechat
::infolist_get
("buffer", "", "");
923 while (weechat
::infolist_next
($infolist))
925 # Only interesting in IRC buffers
926 if (weechat
::infolist_string
($infolist, "plugin_name") eq "irc")
928 # Find buffers that maych
929 $sname = weechat
::infolist_string
($infolist, "short_name");
930 if ($sname eq $arg_array[0])
933 $bufp = weechat
::infolist_pointer
($infolist, "pointer");
937 weechat
::infolist_free
($infolist);
938 # If the infolist found more than one channel, halt as we need to know which one
939 if ($found_chans > 1)
941 weechat
::print("", "Channel name is not unique, please define server");
942 return weechat
::WEECHAT_RC_OK
;
945 # Something didn't return right
948 weechat
::print("", "Could not find buffer");
949 return weechat
::WEECHAT_RC_OK
;
954 # Get pointer from where we are
955 $bufp = weechat
::current_buffer
();
958 $bufname = weechat
::buffer_get_string
($bufp, 'name');
959 # Test if buffer is an IRC channel
960 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
962 if (weechat
::config_get_plugin
($bufname) eq "off")
964 # If currently off, set on
965 weechat
::config_set_plugin
($bufname, "on");
967 # Send to output formatter
968 highmon_print
("Highlight Monitoring Enabled", $bufp);
969 return weechat
::WEECHAT_RC_OK
;
971 elsif (weechat
::config_get_plugin
($bufname) eq "on" || weechat
::config_get_plugin
($bufname) eq "")
973 # If currently on, set off
974 weechat
::config_set_plugin
($bufname, "off");
976 # Send to output formatter
977 highmon_print
("Highlight Monitoring Disabled", $bufp);
978 return weechat
::WEECHAT_RC_OK
;
983 # Takes a buffer pointer and returns a formatted name
984 sub format_buffer_name
987 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
989 # Set colour from buffer name
990 if (weechat
::config_get_plugin
("color_buf") eq "on")
992 # Determine what colour to use
993 $color = weechat
::info_get
("irc_nick_color", $bufname);
997 @char_array = split(//,$bufname);
998 foreach $char (@char_array)
1000 $color += ord($char);
1003 $color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
1004 $color = weechat
::config_get
($color);
1005 $color = weechat
::config_string
($color);
1006 $color = weechat
::color
($color);
1009 # Private message just show network
1010 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1012 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1014 # Format name to short or 'nicename'
1015 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1017 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1021 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1024 # Build a coloured string
1025 $bufname = $color.$bufname.weechat
::color
("reset");
1027 # User set colour name
1028 elsif (weechat
::config_get_plugin
("color_buf") ne "off")
1030 # Private message just show network
1031 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1033 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1035 # Format name to short or 'nicename'
1036 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1038 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1042 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1045 $color = weechat
::config_get_plugin
("color_buf");
1046 $bufname = weechat
::color
($color).$bufname.weechat
::color
("reset");
1048 # Stick with default colour
1051 # Private message just show network
1052 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1054 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1056 # Format name to short or 'nicename'
1057 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1059 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1063 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1070 # Check result of register, and attempt to behave in a sane manner
1071 if (!weechat
::register
("highmon", "KenjiE20", "2.3.3.2", "GPL3", "Highlight Monitor", "", ""))
1074 weechat
::print ("", "\tHighmon is already loaded");
1075 return weechat
::WEECHAT_RC_OK
;
1081 highmon_config_init
();