2 # chanmon.pl - Channel Monitoring for weechat 0.3.0
5 # Add 'Channel Monitor' buffer/bar that you can position to show IRC channel
6 # messages in a single location without constantly switching buffers
7 # i.e. In a seperate window beneath the main channel buffer
10 # /chanmon [help] | [monitor [channel [server]]] | [dynmon] | [clean default|orphan|all]
11 # Command wrapper for chanmon commands
13 # /chmonitor [channel] [server] is used to toggle a channel monitoring on and off, this
14 # can be used in the channel buffer for the channel you wish to toggle, or be given
15 # with arguments e.g. /monitor #weechat freenode
17 # /dynmon is used to toggle 'Dynamic Channel Monitoring' on and off, this
18 # will automagically stop monitoring the current active buffer, without
19 # affecting regular settings (Default is off)
21 # /chanclean default|orphan|all will clean the config section of default 'on' entries,
22 # channels you are no longer joined, or both
24 # /set plugins.var.perl.chanmon.alignment
25 # The config setting "alignment" can be changed to;
26 # "channel", "schannel", "nchannel", "channel,nick", "schannel,nick", "nchannel,nick"
27 # to change how the monitor appears
28 # The 'channel' value will show: "#weechat"
29 # The 'schannel' value will show: "6"
30 # The 'nchannel' value will show: "6:#weechat"
32 # /set plugins.var.perl.chanmon.short_names
33 # Setting this to 'on' will trim the network name from chanmon, ala buffers.pl
35 # /set plugins.var.perl.chanmon.merge_private
36 # Setting this to 'on' will merge private messages to chanmon's display
38 # /set plugins.var.perl.chanmon.color_buf
39 # This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
40 # This *must* be a valid color name, or weechat will likely do unexpected things :)
42 # /set plugins.var.perl.chanmon.show_aways
43 # Toggles showing the Weechat away messages
45 # /set plugins.var.perl.chanmon.logging
46 # Toggles logging status for chanmon buffer (default: off)
48 # /set plugins.var.perl.chanmon.output
49 # Changes where output method of chanmon; takes either "bar" or "buffer" (default; buffer)
50 # /set plugins.var.perl.chanmon.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)
54 # /set plugins.var.perl.chanmon.nick_prefix
55 # /set plugins.var.perl.chanmon.nick_suffix
56 # Sets the prefix and suffix chars in the chanmon buffer
57 # (Defaults to <> if nothing set, and blank if there is)
60 # servername is the internal name for the server (set when you use /server add)
61 # #channel is the channel name, (where # is whatever channel type that channel happens to be)
64 # Split the layout 70/30 (or there abouts) horizontally and load
65 # Optionally, make the status and input lines only show on active windows
67 # /window splith 70 --> open the chanmon buffer
68 # /set weechat.bar.status.conditions "active"
69 # /set weechat.bar.input.conditions "active"
72 # 2012-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
73 # v2.3.1: -fix: Colour tags in bar timestamp string, bar error fixes from highmon
74 # 2012-02-28, KenjiE20 <longbow@longbowslair.co.uk>:
75 # v2.3: -feature: Added merge_private option to display private messages (default: off)
76 # 2010-12-22, KenjiE20 <longbow@longbowslair.co.uk>:
77 # v2.2: -change: Use API instead of config to find channel colours, ready for 0.3.4 and 256 colours
78 # 2010-12-05, KenjiE20 <longbow@longbowslair.co.uk>:
79 # v2.1.3: -change: /monitor is now /chmonitor to avoid command conflicts (thanks m4v)
80 # (/chanmon monitor remains the same)
81 # -fix: Add command list to inbuilt help
82 # 2010-09-30, KenjiE20 <longbow@longbowslair.co.uk>:
83 # v2.1.2: -fix: logging config was not correctly toggling back on (thanks to sleo for noticing)
84 # 2010-09-20, m4v <lambdae2@gmail.com>:
85 # v2.1.1: -fix: chanmon wasn't detecting buffers displayed on more than one window
86 # 2010-08-27, KenjiE20 <longbow@longbowslair.co.uk>:
87 # v2.1: -feature: Add 'nchannel' option to alignment to display buffer and name
88 # 2010-04-25, KenjiE20 <longbow@longbowslair.co.uk>:
89 # v2.0: Release as version 2.0
90 # 2010-04-24, KenjiE20 <longbow@longbowslair.co.uk>:
91 # -fix: No longer using hard-coded detection for ACTION and
92 # TOPIC messages. Use config settings for ACTION printing
93 # 2010-04-15, KenjiE20 <longbow@longbowslair.co.uk>:
94 # v1.9: Rewrite for v2.0
95 # -feature: /monitor takes arguments
96 # -feature: Added /chanclean for config cleanup
97 # -feature: Buffer logging option (default: off)
98 # -feature: Selectable output (Bar/Buffer (default))
99 # -feature: /chanmon is now a command wrapper for all commands
100 # /help chanmon gives command help
101 # /chanmon help gives config help
102 # -code change: Made more subs to shrink the code down in places
103 # -fix: Stop chanmon attempting to double load/hook
104 # 2010-02-10, m4v <lambdae2@gmail.com>:
105 # v1.7.1: -fix: chanmon was leaking infolists, changed how chanmon
106 # detects if the buffer is displayed or not.
107 # 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
108 # v1.7: -fixture: Let chanmon be aware of nick_prefix/suffix
109 # and allow custom prefix/suffix for chanmon buffer
110 # (Defaults to <> if nothing set, and blank if there is)
111 # -fix: Make dynamic monitoring aware of multiple windows
112 # rather than just the active buffer
113 # (Thanks to m4v for these)
114 # 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
115 # v1.6: -feature: colored buffer names
116 # -change: chanmon version sync
117 # 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
118 # v1.5: -fix: disable buffer highlight
119 # 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
120 # v.1.4.1 -change: Stop unsightly text block on '/help'
121 # 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
122 # v1.4: -feature: In-client help added
123 # -fix: Added missing help entries
124 # Fix remaining ugly vars
125 # 2009-07-09, KenjiE20 <longbow@longbowslair.co.uk>:
126 # v.1.3.3 -fix: highlight on the channel monitor when someone /me highlights
127 # 2009-07-04, KenjiE20 <longbow@longbowslair.co.uk>:
128 # v.1.3.2 -fix: use new away_info tag instead of ugly regexp for away detection
129 # -code: cleanup old raw callback arguement variables to nice neat named ones
130 # 2009-07-04, KenjiE20 <longbow@longbowslair.co.uk>:
131 # v.1.3.1 -feature(tte): Hide /away messages by default, change 'show_aways' to get them back
132 # 2009-07-01, KenjiE20 <longbow@longbowslair.co.uk>:
133 # v.1.3 -feature(tte): Mimic buffers.pl 'short_names'
134 # 2009-06-29, KenjiE20 <longbow@longbowslair.co.uk>:
135 # v.1.2.1 -fix: let the /monitor message respect the alignment setting
136 # 2009-06-19, KenjiE20 <longbow@longbowslair.co.uk>:
137 # v.1.2 -feature(tte): Customisable alignment
138 # Thanks to 'FreakGaurd' for the idea
139 # 2009-06-14, KenjiE20 <longbow@longbowslair.co.uk>:
140 # v.1.1.2 -fix: don't assume chanmon buffer needs creating
141 # fixes crashing with /upgrade
142 # 2009-06-13, KenjiE20 <longbow@longbowslair.co.uk>:
143 # v.1.1.1 -code: change from True/False to on/off for weechat consistency
144 # Settings WILL NEED to be changed manually from previous versions
145 # 2009-06-13, KenjiE20 <longbow@longbowslair.co.uk>:
146 # v1.1: -feature: Dynamic Channel Monitoring,
147 # don't display messages from active channel buffer
148 # defaults to Disabled
149 # Thanks to 'sjohnson' for the idea
150 # -fix: don't set config entries for non-channels
151 # -fix: don't assume all channels are #
152 # 2009-06-12, KenjiE20 <longbow@longbowslair.co.uk>:
153 # v1.0.1: -fix: glitch with tabs in IRC messages
154 # 2009-06-10, KenjiE20 <longbow@longbowslair.co.uk>:
155 # v1.0: Initial Public Release
157 # Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
159 # This program is free software; you can redistribute it and/or modify
160 # it under the terms of the GNU General Public License as published by
161 # the Free Software Foundation; either version 3 of the License, or
162 # (at your option) any later version.
164 # This program is distributed in the hope that it will be useful,
165 # but WITHOUT ANY WARRANTY; without even the implied warranty of
166 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
167 # GNU General Public License for more details.
169 # You should have received a copy of the GNU General Public License
170 # along with this program. If not, see <http://www.gnu.org/licenses/>.
174 @bar_lines_time = ();
175 # Replicate info earlier for in-client help
176 $chanmonhelp = weechat
::color
("bold")."/chanmon [help] | [monitor [channel [server]]] | [dynmon] | [clean default|orphan|all]".weechat
::color
("-bold")."
177 Command wrapper for chanmon commands
179 ".weechat
::color
("bold")."/chmonitor [channel] [server]".weechat
::color
("-bold")." is used to toggle a channel monitoring on and off, this
180 can be used in the channel buffer for the channel you wish to toggle, or be given with arguments e.g. /monitor #weechat freenode
182 ".weechat
::color
("bold")."/dynmon".weechat
::color
("-bold")." is used to toggle 'Dynamic Channel Monitoring' on and off, this will automagically stop monitoring the current active buffer, without affecting regular settings (Default is off)
184 ".weechat
::color
("bold")."/chanclean".weechat
::color
("-bold")." default|orphan|all will clean the config section of default 'on' entries, channels you are no longer joined, or both
186 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.alignment".weechat
::color
("-bold")."
187 The config setting \"alignment\" can be changed to;
188 \"channel\", \"schannel\", \"nchannel\", \"channel,nick\", \"schannel,nick\", \"nchannel,nick\"
189 to change how the monitor appears
190 The 'channel' value will show: \"#weechat\"
191 The 'schannel' value will show: \"6\"
192 The 'nchannel' value will show: \"6:#weechat\"
194 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.short_names".weechat
::color
("-bold")."
195 Setting this to 'on' will trim the network name from chanmon, ala buffers.pl
197 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.merge_private".weechat
::color
("-bold")."
198 Setting this to 'on' will merge private messages to chanmon's display
200 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.color_buf".weechat
::color
("-bold")."
201 This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
202 This ".weechat
::color
("bold")."must".weechat
::color
("-bold")." be a valid color name, or weechat will likely do unexpected things :)
204 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.show_aways".weechat
::color
("-bold")."
205 Toggles showing the Weechat away messages
207 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.logging".weechat
::color
("-bold")."
208 Toggles logging status for chanmon buffer (default: off)
210 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.output".weechat
::color
("-bold")."
211 Changes where output method of chanmon; takes either \"bar\" or \"buffer\" (default; buffer)
212 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.bar_lines".weechat
::color
("-bold")."
213 Changes the amount of lines the output bar will hold.
214 (Only appears once output has been set to bar, defaults to 10)
216 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.nick_prefix".weechat
::color
("-bold")."
217 ".weechat
::color
("bold")."/set plugins.var.perl.chanmon.nick_suffix".weechat
::color
("-bold")."
218 Sets the prefix and suffix chars in the chanmon buffer
219 (Defaults to <> if nothing set, and blank if there is)
221 ".weechat
::color
("bold")."servername.#channel".weechat
::color
("-bold")."
222 servername is the internal name for the server (set when you use /server add)
223 #channel is the channel name, (where # is whatever channel type that channel happens to be)
225 ".weechat
::color
("bold")."Ideal set up:".weechat
::color
("-bold")."
226 Split the layout 70/30 (or there abouts) horizontally and load
227 Optionally, make the status and input lines only show on active windows
229 ".weechat
::color
("bold")."/window splith 70 --> open the chanmon buffer".weechat
::color
("-bold")."
230 ".weechat
::color
("bold")."/set weechat.bar.status.conditions \"active\"".weechat
::color
("-bold")."
231 ".weechat
::color
("bold")."/set weechat.bar.input.conditions \"active\"".weechat
::color
("-bold");
235 weechat
::print("", "\t".weechat
::color
("bold")."Chanmon Help".weechat
::color
("-bold")."\n\n");
236 weechat
::print("", "\t".$chanmonhelp);
237 return weechat
::WEECHAT_RC_OK
;
241 sub chanmon_bar_build
244 $max_lines = weechat
::config_get_plugin
("bar_lines");
245 $max_lines = $max_lines ? $max_lines : 10;
249 # Keep lines within max
250 while ($#bar_lines > $max_lines)
253 shift(@bar_lines_time);
255 # So long as we have some lines, build a string
261 # Find max align needed
262 $prefix_num = (index(weechat
::string_remove_color
($_, ""), " | "));
263 $align_num = $prefix_num if ($prefix_num > $align_num);
267 # Get align for this line
268 $prefix_num = (index(weechat
::string_remove_color
($_, ""), " | "));
271 $str = $str.$bar_lines_time[$count]." ".(" " x
($align_num - $prefix_num)).$_."\n";
272 # Increment count for sync with time list
283 weechat
::bar_item_new
("chanmon", "chanmon_bar_build", "");
285 $chanmon_bar = weechat
::bar_new
("chanmon", "off", 100, "root", "", "bottom", "vertical", "vertical", 0, 0, "default", "cyan", "default", "on", "chanmon");
287 return weechat
::WEECHAT_RC_OK
;
290 sub chanmon_bar_close
293 $chanmon_bar = weechat
::bar_search
("chanmon");
294 # If is does, close it
295 if ($chanmon_bar ne "")
297 weechat
::bar_remove
($chanmon_bar);
300 # Find if bar item exists
301 $chanmon_bar_item = weechat
::bar_item_search
("chanmon_bar");
302 # If is does, close it
303 if ($chanmon_bar_item ne "")
305 weechat
::bar_remove
($chanmon_bar_item);
309 return weechat
::WEECHAT_RC_OK
;
313 sub chanmon_buffer_open
315 # Search for pre-existing buffer
316 $chanmon_buffer = weechat
::buffer_search
("perl", "chanmon");
319 if ($chanmon_buffer eq "")
321 $chanmon_buffer = weechat
::buffer_new
("chanmon", "chanmon_buffer_input", "", "chanmon_buffer_close", "");
324 # Turn off notify, highlights
325 if ($chanmon_buffer ne "")
327 weechat
::buffer_set
($chanmon_buffer, "notify", "0");
328 weechat
::buffer_set
($chanmon_buffer, "highlight_words", "-");
329 weechat
::buffer_set
($chanmon_buffer, "title", "Channel Monitor");
331 if (weechat
::config_get_plugin
("logging") eq "off")
333 weechat
::buffer_set
($chanmon_buffer, "localvar_set_no_log", "1");
336 return weechat
::WEECHAT_RC_OK
;
338 # Buffer input has no action
339 sub chanmon_buffer_input
341 return weechat
::WEECHAT_RC_OK
;
344 sub chanmon_buffer_close
346 $chanmon_buffer = "";
347 return weechat
::WEECHAT_RC_OK
;
350 # Chanmon command wrapper
351 sub chanmon_command_cb
362 @arg_array = split(/ /,$args);
363 # Take first as command
364 $cmd = shift(@arg_array);
365 # Rebuild string to pass to subs
368 $arg = join(" ", @arg_array);
373 if ($cmd eq "" || $cmd eq "help")
378 elsif ($cmd eq "monitor")
380 chanmon_toggle
($data, $buffer, $arg);
383 elsif ($cmd eq "dynmon")
385 chanmon_dyn_toggle
();
388 elsif ($cmd eq "clean")
390 chanmon_config_clean
($data, $buffer, $arg);
392 return weechat
::WEECHAT_RC_OK
;
395 # Clean up config entries
396 sub chanmon_config_clean
402 # Don't do anything if bad option given
403 if ($args ne "default" && $args ne "orphan" && $args ne "all")
405 weechat
::print("", "\tchanmon.pl: Unknown option");
406 return weechat
::WEECHAT_RC_OK
;
410 # Load an infolist of chanmon options
411 $infolist = weechat
::infolist_get
("option", "", "*chanmon*");
412 while (weechat
::infolist_next
($infolist))
414 $name = weechat
::infolist_string
($infolist, "option_name");
415 $name =~ s/perl\.chanmon\.(\w*)\.([#&\+!])(.*)/$1.$2$3/;
416 if ($name =~ /^(.*)\.([#&\+!])(.*)$/)
420 if ($args eq "default" || $args eq "all")
422 # If value in config is "on"
423 if (weechat
::config_get_plugin
($name) eq "on")
425 # Unset and if successful flag as changed
426 $rc = weechat
::config_unset_plugin
($name);
427 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
434 if ($args eq "orphan" || $args eq "all")
436 # If we can't find the buffer for this entry
437 if (weechat
::buffer_search
("irc", $name) eq "")
439 # Unset and if successful flag as changed
440 $rc = weechat
::config_unset_plugin
($name);
441 if ($rc eq weechat
::WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED
)
447 # Add changed entry names to list
448 push (@chans, $name) if ($action);
451 weechat
::infolist_free
($infolist);
452 # If channels were cleaned from config
458 $str = "\tchanmon.pl: Cleaned ".@chans." entry from the config:";
462 $str = "\tchanmon.pl: Cleaned ".@chans." entries from the config:";
464 # Build a list of channels
469 # Print what happened
470 weechat
::print("",$str);
472 # Config seemed to be clean
475 weechat
::print("", "\tchanmon.pl: No entries removed");
477 return weechat
::WEECHAT_RC_OK
;
480 # Check config elements
481 sub chanmon_config_init
484 if (!(weechat
::config_is_set_plugin
("alignment")))
486 weechat
::config_set_plugin
("alignment", "channel");
488 if (weechat
::config_get_plugin
("alignment") eq "")
490 weechat
::config_set_plugin
("alignment", "none");
494 if (!(weechat
::config_is_set_plugin
("dynamic")))
496 weechat
::config_set_plugin
("dynamic", "off");
500 if (!(weechat
::config_is_set_plugin
("short_names")))
502 weechat
::config_set_plugin
("short_names", "off");
505 # Coloured names default
506 if (!(weechat
::config_is_set_plugin
("color_buf")))
508 weechat
::config_set_plugin
("color_buf", "on");
511 # Away message default
512 if (!(weechat
::config_is_set_plugin
("show_aways")))
514 weechat
::config_set_plugin
("show_aways", "off");
517 # chanmon log default
518 if (!(weechat
::config_is_set_plugin
("logging")))
520 weechat
::config_set_plugin
("logging", "off");
524 if (!(weechat
::config_is_set_plugin
("output")))
526 weechat
::config_set_plugin
("output", "buffer");
529 # Private message merging
530 if (!(weechat
::config_is_set_plugin
("merge_private")))
532 weechat
::config_set_plugin
("merge_private", "off");
535 # Check for exisiting prefix/suffix chars, and setup accordingly
536 $prefix = weechat
::config_get
("irc.look.nick_prefix");
537 $prefix = weechat
::config_string
($prefix);
538 $suffix = weechat
::config_get
("irc.look.nick_suffix");
539 $suffix = weechat
::config_string
($suffix);
541 if (!(weechat
::config_is_set_plugin
("nick_prefix")))
543 if ($prefix eq "" && $suffix eq "")
545 weechat
::config_set_plugin
("nick_prefix", "<");
549 weechat
::config_set_plugin
("nick_prefix", "");
553 if (!(weechat
::config_is_set_plugin
("nick_suffix")))
555 if ($prefix eq "" && $suffix eq "")
557 weechat
::config_set_plugin
("nick_suffix", ">");
561 weechat
::config_set_plugin
("nick_suffix", "");
567 sub chanmon_config_cb
573 $name =~ s/^plugins\.var\.perl\.chanmon\.//;
575 # Set logging on buffer
576 if ($name eq "logging")
578 # Search for pre-existing buffer
579 $chanmon_buffer = weechat
::buffer_search
("perl", "chanmon");
582 weechat
::buffer_set
($chanmon_buffer, "localvar_set_no_log", "1");
586 weechat
::buffer_set
($chanmon_buffer, "localvar_del_no_log", "");
590 elsif ($name eq "output")
594 # Search for pre-existing buffer
595 $chanmon_buffer = weechat
::buffer_search
("perl", "chanmon");
597 if ($chanmon_buffer ne "")
599 weechat
::buffer_close
($chanmon_buffer)
602 # Output bar lines default
603 if (!(weechat
::config_is_set_plugin
("bar_lines")))
605 weechat
::config_set_plugin
("bar_lines", "10");
607 # Make a bar if doesn't exist
610 elsif ($value eq "buffer")
612 # If a bar exists, close it
615 chanmon_buffer_open
();
619 return weechat
::WEECHAT_RC_OK
;
622 # Toggle dynamic monitoring on/off
623 sub chanmon_dyn_toggle
625 if (weechat
::config_get_plugin
("dynamic") eq "off")
627 weechat
::config_set_plugin
("dynamic", "on");
628 chanmon_print
("Dynamic Channel Monitoring Enabled");
629 return weechat
::WEECHAT_RC_OK
;
631 elsif (weechat
::config_get_plugin
("dynamic") eq "on")
633 weechat
::config_set_plugin
("dynamic", "off");
634 chanmon_print
("Dynamic Channel Monitoring Disabled");
635 return weechat
::WEECHAT_RC_OK
;
639 # Set up weechat hooks / commands
642 weechat
::hook_print
("", "", "", 0, "chanmon_new_message", "");
643 weechat
::hook_command
("chmonitor", "Toggles monitoring for a channel", "[channel [server]]", " channel: What channel to toggle monitoring for\n server: Internal server name, if channel is on more than one server", "%(irc_channels) %(irc_servers)", "chanmon_toggle", "");
644 weechat
::hook_command
("dynmon", "Toggles 'dynamic' monitoring (auto-disable monitoring for current channel)", "", "", "", "chanmon_dyn_toggle", "");
645 weechat
::hook_command
("chanclean", "Chanmon 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", "chanmon_config_clean", "");
647 weechat
::hook_command
("chanmon", "Chanmon help", "[help] | [monitor [channel [server]]] | [dynmon] | [clean default|orphan|all]", " help: Print help for chanmon\n monitor: Toggles monitoring for a channel (/chmonitor)\n dynmon: Toggles 'dynamic' monitoring (auto-disable monitoring for current channel) (/dynmon)\n clean: Chanmon config clean up (/chanclean)", "help || monitor %(irc_channels) %(irc_servers) || dynmon || clean default|orphan|all", "chanmon_command_cb", "");
649 weechat
::hook_config
("plugins.var.perl.chanmon.*", "chanmon_config_cb", "");
652 # Main body, Callback for hook_print
653 sub chanmon_new_message
659 my $window_displayed = "";
663 # $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
664 # weechat::print("", "\t".$string);
675 # Only work on messages and topic notices
676 if ($cb_tags =~ /irc_privmsg/ || $cb_tags =~ /irc_topic/)
678 # Check buffer name is an IRC channel or private message when enabled
679 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
680 if ($bufname =~ /(.*)\.([#&\+!])(.*)/ || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/))
682 # Are we running on this channel
683 if (weechat
::config_get_plugin
($bufname) ne "off" && $cb_disp eq "1")
685 # Are we running dynamically
686 if (weechat
::config_get_plugin
("dynamic") eq "on")
688 # Check if this buffer is shown in a window somewhere
689 $window_displayed = weechat
::buffer_get_integer
($cb_bufferp, "num_displayed");
690 if ($window_displayed ne 0)
693 return weechat
::WEECHAT_RC_OK
;
698 # Line isn't action or topic notify
699 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");
713 $nick = " ".weechat
::config_get_plugin
("nick_prefix").$cb_prefix.weechat
::color
("reset").weechat
::config_get_plugin
("nick_suffix");
717 elsif ($cb_tags =~ /irc_topic/)
720 $nick = " ".$cb_prefix.weechat
::color
("reset");
728 $uncolnick = weechat
::string_remove_color
($cb_prefix, "");
729 $nick = weechat
::color
("chat_highlight").$uncolnick.weechat
::color
("reset");
734 $nick = $cb_prefix.weechat
::color
("reset");
738 chanmon_print
($cb_msg, $cb_bufferp, $nick);
742 # Special outgoing ACTION & away_info catcher
743 elsif ($cb_tags eq "" || $cb_tags =~ /away_info/ && weechat
::config_get_plugin
("show_aways") eq "on" )
745 # Check buffer name is an IRC channel or private message when enabled
746 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
747 if ($bufname =~ /(.*)\.([#&\+!])(.*)/ || (weechat
::config_get_plugin
("merge_private") eq "on" && $cb_tags =~ /notify_private/))
749 # Are we running dynamically
750 if (weechat
::config_get_plugin
("dynamic") eq "on")
752 # Check if this buffer is shown in a window somewhere
753 $window_displayed = weechat
::buffer_get_integer
($cb_bufferp, "num_displayed");
754 if ($window_displayed eq 1)
757 return weechat
::WEECHAT_RC_OK
;
762 $mynick = weechat
::info_get
("irc_nick", $net);
763 if ($cb_msg =~ $mynick)
765 $action_colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_prefix_action")));
766 $action_prefix = weechat
::config_string
(weechat
::config_get
("weechat.look.prefix_action"));
767 $nick_self_colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_nick_self")));
768 $nick = $action_colour.$action_prefix.$nick_self_colour.$nick.weechat
::color
("reset");
770 chanmon_print
($cb_msg, $cb_bufferp, $nick);
774 return weechat
::WEECHAT_RC_OK
;
777 # Output formatter and printer takes (msg bufpointer nick)
781 my $cb_bufferp = $_[1] if ($_[1]);
782 my $nick = $_[2] if ($_[2]);
784 #Normal channel message
785 if ($cb_bufferp && $nick)
788 $bufname = format_buffer_name
($cb_bufferp);
790 # If alignment is #channel | nick msg
791 if (weechat
::config_get_plugin
("alignment") eq "channel")
793 $nick =~ s/\s(.*)/$1/;
795 $outstr = $bufname."\t".$nick." ".$cb_msg;
797 # or if it is channel number | nick msg
798 elsif (weechat
::config_get_plugin
("alignment") eq "schannel")
800 $nick =~ s/\s(.*)/$1/;
801 # Use channel number instead
802 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
804 $outstr = $bufname."\t".$nick." ".$cb_msg;
806 # or if it is number:#channel | nick msg
807 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel")
809 $nick =~ s/\s(.*)/$1/;
810 # Place channel number in front of formatted name
811 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
813 $outstr = $bufname."\t".$nick." ".$cb_msg;
815 # or if it is #channel nick | msg
816 elsif (weechat
::config_get_plugin
("alignment") eq "channel,nick")
819 $outstr = $bufname.":".$nick."\t".$cb_msg;
821 # or if it is channel number nick | msg
822 elsif (weechat
::config_get_plugin
("alignment") eq "schannel,nick")
824 # Use channel number instead
825 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
827 $outstr = $bufname.":".$nick."\t".$cb_msg;
829 # or if it is number:#channel nick | msg
830 elsif (weechat
::config_get_plugin
("alignment") eq "nchannel,nick")
832 # Place channel number in front of formatted name
833 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
835 $outstr = $bufname.":".$nick."\t".$cb_msg;
837 # or finally | #channel nick msg
841 $outstr = "\t".$bufname.":".$nick." ".$cb_msg;
844 # chanmon channel toggle message
845 elsif ($cb_bufferp && !$nick)
848 $bufname = format_buffer_name
($cb_bufferp);
850 # If alignment is #channel * | *
851 if (weechat
::config_get_plugin
("alignment") =~ /channel/)
853 # If it's actually channel number * | *
854 if (weechat
::config_get_plugin
("alignment") =~ /schannel/)
856 # Use channel number instead
857 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').weechat
::color
("reset");
859 # Or if it's actually number:#channel * | *
860 if (weechat
::config_get_plugin
("alignment") =~ /nchannel/)
862 # Place channel number in front of formatted name
863 $bufname = weechat
::color
("chat_prefix_buffer").weechat
::buffer_get_integer
($cb_bufferp, 'number').":".weechat
::color
("reset").$bufname;
865 $outstr = $bufname."\t".$cb_msg;
867 # or if alignment is | *
870 $outstr = $bufname.": ".$cb_msg;
874 elsif (!$cb_bufferp && !$nick)
876 $outstr = "\t".$cb_msg;
879 # Send string to buffer
880 if (weechat
::config_get_plugin
("output") eq "buffer")
882 # Search for and confirm buffer
883 $chanmon_buffer = weechat
::buffer_search
("perl", "chanmon");
885 weechat
::print($chanmon_buffer, $outstr);
887 elsif (weechat
::config_get_plugin
("output") eq "bar")
890 use POSIX
qw(strftime);
891 $time = strftime
(weechat
::config_string
(weechat
::config_get
("weechat.look.buffer_time_format")), localtime);
893 if ($time =~ /\$\{\w+\}/) # Coloured string
895 while ($time =~ /\$\{(\w+)\}/)
897 $color = weechat
::color
($1);
898 $time =~ s/\$\{\w+\}/$color/;
901 else # Default string
903 $colour = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_time_delimiters")));
904 $reset = weechat
::color
("reset");
905 $time =~ s/(\d*)(.)(\d*)/$1$colour$2$reset$3/g;
907 # Push updates to bar lists
908 push (@bar_lines_time, $time);
911 $delim = weechat
::color
(weechat
::config_string
(weechat
::config_get
("weechat.color.chat_delimiters")))." | ".weechat
::color
("reset");
912 $outstr =~ s/\t/$delim/;
914 push (@bar_lines, $outstr);
916 weechat
::bar_item_update
("chanmon");
920 # Start the output display
923 if (weechat
::config_get_plugin
("output") eq "buffer")
925 chanmon_buffer_open
();
927 elsif (weechat
::config_get_plugin
("output") eq "bar")
933 # Takes two optional args (channel server), toggles monitoring on/off
940 # Check if we've been told what channel to act on
944 @arg_array = split(/ /,$args);
945 # Check if a server was given
949 $bufp = weechat
::buffer_search
("irc", $arg_array[1].".".$arg_array[0]);
954 # Loop through defined servers
955 $infolist = weechat
::infolist_get
("buffer", "", "");
956 while (weechat
::infolist_next
($infolist))
958 # Only interesting in IRC buffers
959 if (weechat
::infolist_string
($infolist, "plugin_name") eq "irc")
961 # Find buffers that maych
962 $sname = weechat
::infolist_string
($infolist, "short_name");
963 if ($sname eq $arg_array[0])
966 $bufp = weechat
::infolist_pointer
($infolist, "pointer");
970 weechat
::infolist_free
($infolist);
971 # If the infolist found more than one channel, halt as we need to know which one
972 if ($found_chans > 1)
974 weechat
::print("", "Channel name is not unique, please define server");
975 return weechat
::WEECHAT_RC_OK
;
978 # Something didn't return right
981 weechat
::print("", "Could not find buffer");
982 return weechat
::WEECHAT_RC_OK
;
987 # Get pointer from where we are
988 $bufp = weechat
::current_buffer
();
991 $bufname = weechat
::buffer_get_string
($bufp, 'name');
992 # Test if buffer is an IRC channel
993 if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
995 if (weechat
::config_get_plugin
($bufname) eq "off")
997 # If currently off, set on
998 weechat
::config_set_plugin
($bufname, "on");
1000 # Send to output formatter
1001 chanmon_print
("Channel Monitoring Enabled", $bufp);
1002 return weechat
::WEECHAT_RC_OK
;
1004 elsif (weechat
::config_get_plugin
($bufname) eq "on" || weechat
::config_get_plugin
($bufname) eq "")
1006 # If currently on, set off
1007 weechat
::config_set_plugin
($bufname, "off");
1009 # Send to output formatter
1010 chanmon_print
("Channel Monitoring Disabled", $bufp);
1011 return weechat
::WEECHAT_RC_OK
;
1016 # Takes a buffer pointer and returns a formatted name
1017 sub format_buffer_name
1019 $cb_bufferp = $_[0];
1020 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'name');
1022 # Set colour from buffer name
1023 if (weechat
::config_get_plugin
("color_buf") eq "on")
1025 # Determine what colour to use
1026 $color = weechat
::info_get
("irc_nick_color", $bufname);
1030 @char_array = split(//,$bufname);
1031 foreach $char (@char_array)
1033 $color += ord($char);
1036 $color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
1037 $color = weechat
::config_get
($color);
1038 $color = weechat
::config_string
($color);
1039 $color = weechat
::color
($color);
1042 # Private message just show network
1043 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1045 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1047 # Format name to short or 'nicename'
1048 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1050 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1054 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1057 # Build a coloured string
1058 $bufname = $color.$bufname.weechat
::color
("reset");
1060 # User set colour name
1061 elsif (weechat
::config_get_plugin
("color_buf") ne "off")
1063 # Private message just show network
1064 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1066 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1068 # Format name to short or 'nicename'
1069 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1071 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1075 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1078 $color = weechat
::config_get_plugin
("color_buf");
1079 $bufname = weechat
::color
($color).$bufname.weechat
::color
("reset");
1081 # Stick with default colour
1084 # Private message just show network
1085 if (weechat
::config_get_plugin
("merge_private") eq "on" && weechat
::buffer_get_string
($cb_bufferp, "localvar_type") eq "private")
1087 $bufname = weechat
::buffer_get_string
($cb_bufferp, "localvar_server");
1089 # Format name to short or 'nicename'
1090 elsif (weechat
::config_get_plugin
("short_names") eq "on")
1092 $bufname = weechat
::buffer_get_string
($cb_bufferp, 'short_name');
1096 $bufname =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
1103 # Check result of register, and attempt to behave in a sane manner
1104 if (!weechat
::register
("chanmon", "KenjiE20", "2.3.1", "GPL3", "Channel Monitor", "", ""))
1107 weechat
::print ("", "\tChanmon is already loaded");
1108 return weechat
::WEECHAT_RC_OK
;
1114 chanmon_config_init
();