1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
|
#
# chanmon.pl - Channel Monitoring for weechat 0.3.0
# Version 1.7.1
#
# Add 'Channel Monitor' buffer that you can position to show IRC channel
# messages in a single location without constantly switching buffers
# i.e. In a seperate window beneath the main channel buffer
#
# Usage:
# /monitor is used to toggle a channel monitoring on and off, this needs
# to be used in the channel buffer for the channel you wish to toggle
#
# /dynmon 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)
#
# /set plugins.var.perl.chanmon.alignment
# The config setting "alignment" can be changed to;
# "channel", "schannel", "channel,nick", "schannel,nick"
# to change how the monitor appears
# The 'schannel' value will only show the buffer number as opposed to
# 'server#channel'
#
# /set plugins.var.perl.chanmon.short_names
# Setting this to 'on' will trim the network name from chanmon, ala buffers.pl
#
# /set plugins.var.perl.chanmon.color_buf
# This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
# This *must* be a valid color name, or weechat will likely do unexpected things :)
#
# /set plugins.var.perl.chanmon.show_aways
# Toggles showing the Weechat away messages
#
# /set plugins.var.perl.chanmon.nick_prefix
# /set plugins.var.perl.chanmon.nick_suffix
# Sets the prefix and suffix chars in the chanmon buffer
# (Defaults to <> if nothing set, and blank if there is)
#
# servername.#channel
# servername is the internal name for the server (set when you use /server add)
# #channel is the channel name, (where # is whatever channel type that channel happens to be)
#
# Ideal set up:
# Split the layout 70/30 (or there abouts) horizontally and load
# Optionally, make the status and input lines only show on active windows
#
# /window splith 70 --> open the chanmon buffer
# /set weechat.bar.status.conditions "active"
# /set weechat.bar.input.conditions "active"
#
# History:
# 2010-02-10, m4v <lambdae2@gmail.com>:
# v1.7.1: -fix: chanmon was leaking infolists, changed how chanmon
# detects if the buffer is displayed or not.
# 2010-01-25, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.7: -fixture: Let chanmon be aware of nick_prefix/suffix
# and allow custom prefix/suffix for chanmon buffer
# (Defaults to <> if nothing set, and blank if there is)
# -fix: Make dynamic monitoring aware of multiple windows
# rather than just the active buffer
# (Thanks to m4v for these)
# 2009-09-07, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.6: -feature: colored buffer names
# -change: chanmon version sync
# 2009-09-05, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.5: -fix: disable buffer highlight
# 2009-09-02, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.4.1 -change: Stop unsightly text block on '/help'
# 2009-08-10, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.4: -feature: In-client help added
# -fix: Added missing help entries
# Fix remaining ugly vars
# 2009-07-09, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.3.3 -fix: highlight on the channel monitor when someone /me highlights
# 2009-07-04, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.3.2 -fix: use new away_info tag instead of ugly regexp for away detection
# -code: cleanup old raw callback arguement variables to nice neat named ones
# 2009-07-04, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.3.1 -feature(tte): Hide /away messages by default, change 'show_aways' to get them back
# 2009-07-01, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.3 -feature(tte): Mimic buffers.pl 'short_names'
# 2009-06-29, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.2.1 -fix: let the /monitor message respect the alignment setting
# 2009-06-19, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.2 -feature(tte): Customisable alignment
# Thanks to 'FreakGaurd' for the idea
# 2009-06-14, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.1.2 -fix: don't assume chanmon buffer needs creating
# fixes crashing with /upgrade
# 2009-06-13, KenjiE20 <longbow@longbowslair.co.uk>:
# v.1.1.1 -code: change from True/False to on/off for weechat consistency
# Settings WILL NEED to be changed manually from previous versions
# 2009-06-13, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.1: -feature: Dynamic Channel Monitoring,
# don't display messages from active channel buffer
# defaults to Disabled
# Thanks to 'sjohnson' for the idea
# -fix: don't set config entries for non-channels
# -fix: don't assume all channels are #
# 2009-06-12, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.0.1: -fix: glitch with tabs in IRC messages
# 2009-06-10, KenjiE20 <longbow@longbowslair.co.uk>:
# v1.0: Initial Public Release
#
# Copyright (c) 2009 by KenjiE20 <longbow@longbowslair.co.uk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
my $chanmon_buffer = "";
# Replicate info earlier for in-client help
$chanmonhelp = weechat::color("bold")."/set plugins.var.perl.chanmon.alignment".weechat::color("-bold")."
The config setting \"alignment\" can be changed to;
\"channel\", \"schannel\", \"channel,nick\", \"schannel,nick\"
to change how the monitor appears
The 'schannel' value will only show the buffer number as opposed to 'server#channel'
".weechat::color("bold")."/set plugins.var.perl.chanmon.short_names".weechat::color("-bold")."
Setting this to 'on' will trim the network name from chanmon, ala buffers.pl
".weechat::color("bold")."/set plugins.var.perl.chanmon.color_buf".weechat::color("-bold")."
This turns colored buffer names on or off, you can also set a single fixed color by using a weechat color name.
This ".weechat::color("bold")."must".weechat::color("-bold")." be a valid color name, or weechat will likely do unexpected things :)
".weechat::color("bold")."/set plugins.var.perl.chanmon.show_aways".weechat::color("-bold")."
Toggles showing the Weechat away messages
".weechat::color("bold")."/set plugins.var.perl.chanmon.nick_prefix".weechat::color("-bold")."
".weechat::color("bold")."/set plugins.var.perl.chanmon.nick_suffix".weechat::color("-bold")."
Sets the prefix and suffix chars in the chanmon buffer
(Defaults to <> if nothing set, and blank if there is)
".weechat::color("bold")."servername.#channel".weechat::color("-bold")."
servername is the internal name for the server (set when you use /server add)
#channel is the channel name, (where # is whatever channel type that channel happens to be)
".weechat::color("bold")."Ideal set up:".weechat::color("-bold")."
Split the layout 70/30 (or there abouts) horizontally and load
Optionally, make the status and input lines only show on active windows
".weechat::color("bold")."/window splith 70 --> open the chanmon buffer".weechat::color("-bold")."
".weechat::color("bold")."/set weechat.bar.status.conditions \"active\"".weechat::color("-bold")."
".weechat::color("bold")."/set weechat.bar.input.conditions \"active\"".weechat::color("-bold");
sub chanmon_new_message
{
my $net = "";
my $chan = "";
my $nick = "";
my $outstr = "";
my $window_displayed = "";
my $dyncheck = "0";
# DEBUG point
# $string = "\t"."0: ".$_[0]." 1: ".$_[1]." 2: ".$_[2]." 3: ".$_[3]." 4: ".$_[4]." 5: ".$_[5]." 6: ".$_[6]." 7: ".$_[7];
# weechat::print("", "\t".$string);
$cb_datap = $_[0];
$cb_bufferp = $_[1];
$cb_date = $_[2];
$cb_tags = $_[3];
$cb_disp = $_[4];
$cb_high = $_[5];
$cb_prefix = $_[6];
$cb_msg = $_[7];
if ($cb_tags =~ /irc_privmsg/ || $cb_tags =~ /irc_topic/)
{
$bufname = weechat::buffer_get_string($cb_bufferp, 'name');
if (weechat::config_get_plugin($bufname) eq "" && $bufname =~ /(.*)\.([#&\+!])(.*)/)
{
weechat::config_set_plugin($bufname, "on");
}
if (weechat::config_get_plugin($bufname) eq "on" && $cb_disp eq "1")
{
if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
{
if (weechat::config_get_plugin("dynamic") eq "on")
{
$window_displayed = weechat::buffer_get_integer($cb_bufferp, "num_displayed");
if ($window_displayed eq 0)
{
$dyncheck = "1";
}
}
$bufname = $1.$2.$3;
if (!($cb_prefix =~ / \*/) && !($cb_prefix =~ /--/))
{
if ($cb_high eq "1")
{
$uncolnick = weechat::string_remove_color($cb_prefix, "");
$nick = " ".weechat::config_get_plugin("nick_prefix").weechat::color("chat_highlight").$uncolnick.weechat::color("reset").weechat::config_get_plugin("nick_suffix");
}
else
{
$nick = " ".weechat::config_get_plugin("nick_prefix").$cb_prefix.weechat::color("reset").weechat::config_get_plugin("nick_suffix");
}
}
elsif ($cb_prefix =~ /--/)
{
$nick = " ".$cb_prefix.weechat::color("reset");
}
else
{
if ($cb_high eq "1")
{
$uncolnick = weechat::string_remove_color($cb_prefix, "");
$nick = weechat::color("chat_highlight").$uncolnick.weechat::color("reset");
}
else
{
$nick = $cb_prefix.weechat::color("reset");
}
}
$bufname = format_buffer($cb_bufferp, $bufname);
if (weechat::config_get_plugin("alignment") eq "channel")
{
$nick =~ s/\s(.*)/$1/;
$outstr = $bufname."\t".$nick." ".$cb_msg;
}
elsif (weechat::config_get_plugin("alignment") eq "schannel")
{
$nick =~ s/\s(.*)/$1/;
$bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
$outstr = $bufname."\t".$nick." ".$cb_msg;
}
elsif (weechat::config_get_plugin("alignment") eq "channel,nick")
{
$outstr = $bufname.":".$nick."\t".$cb_msg;
}
elsif (weechat::config_get_plugin("alignment") eq "schannel,nick")
{
$bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
$outstr = $bufname.":".$nick."\t".$cb_msg;
}
else
{
$outstr = "\t".$bufname.":".$nick." ".$cb_msg;
}
if (weechat::config_get_plugin("dynamic") eq "on")
{
if ($dyncheck)
{
weechat::print($chanmon_buffer, $outstr);
}
}
else
{
weechat::print($chanmon_buffer, $outstr);
}
}
}
}
# Special outgoing ACTION & away_info catcher
elsif ($cb_tags eq "" || $cb_tags =~ /away_info/ && weechat::config_get_plugin("show_aways") eq "on" )
{
$bufname = weechat::buffer_get_string($cb_bufferp, 'name');
if (weechat::config_get_plugin($bufname) eq "" && $bufname =~ /(.*)\.([#&\+!])(.*)/)
{
weechat::config_set_plugin($bufname, "on");
}
if (weechat::config_get_plugin($bufname) eq "on" && $cb_disp eq "1")
{
if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
{
if (weechat::config_get_plugin("dynamic") eq "on")
{
$window_displayed = weechat::buffer_get_integer($cb_bufferp, "num_displayed");
if ($window_displayed eq 0)
{
$dyncheck = "1";
}
}
$bufname = $1.$2.$3;
$net = $1;
$mynick = weechat::info_get("irc_nick", $net);
if ($cb_msg =~ $mynick)
{
$nick = weechat::color("white")." *".$nick.weechat::color("reset");
$bufname = format_buffer($cb_bufferp, $bufname);
if (weechat::config_get_plugin("alignment") eq "channel")
{
$nick =~ s/\s(.*)/$1/;
$outstr = $bufname."\t".$nick." ".$cb_msg;
}
elsif (weechat::config_get_plugin("alignment") eq "schannel")
{
$nick =~ s/\s(.*)/$1/;
$bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
$outstr = $bufname."\t".$nick." ".$cb_msg;
}
elsif (weechat::config_get_plugin("alignment") eq "channel,nick")
{
$outstr = $bufname.":".$nick."\t".$cb_msg;
}
elsif (weechat::config_get_plugin("alignment") eq "schannel,nick")
{
$bufname = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer($cb_bufferp, 'number').weechat::color("reset");
$outstr = $bufname.":".$nick."\t".$cb_msg;
}
else
{
$outstr = "\t".$bufname.":".$nick." ".$cb_msg;
}
if (weechat::config_get_plugin("dynamic") eq "on")
{
if ($dyncheck)
{
weechat::print($chanmon_buffer, $outstr);
}
}
else
{
weechat::print($chanmon_buffer, $outstr);
}
}
}
}
}
return weechat::WEECHAT_RC_OK;
}
sub chanmon_toggle
{
$bufname = weechat::buffer_get_string(weechat::current_buffer(), 'name');
if ($bufname =~ /(.*)\.([#&\+!])(.*)/)
{
$sbuf = weechat::color("chat_prefix_buffer").weechat::buffer_get_integer(weechat::current_buffer(), 'number').weechat::color("reset");
$str = "";
if (weechat::config_get_plugin($bufname) eq "off")
{
weechat::config_set_plugin($bufname, "on");
$nicename = $bufname;
$nicename =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
$nicename = format_buffer(weechat::current_buffer(), $nicename);
if (weechat::config_get_plugin("alignment") =~ /channel/)
{
if (weechat::config_get_plugin("alignment") =~ /schannel/)
{
$str = $sbuf."\tChannel Monitoring Enabled";
}
else
{
$str = $nicename."\tChannel Monitoring Enabled";
}
}
else
{
$str = $nicename.": Channel Monitoring Enabled";
}
weechat::print($chanmon_buffer, $str);
return weechat::WEECHAT_RC_OK;
}
elsif (weechat::config_get_plugin($bufname) eq "on" || weechat::config_get_plugin($bufname) eq "")
{
weechat::config_set_plugin($bufname, "off");
$nicename = $bufname;
$nicename =~ s/(.*)\.([#&\+!])(.*)/$1$2$3/;
$nicename = format_buffer(weechat::current_buffer(), $nicename);
if (weechat::config_get_plugin("alignment") =~ /channel/)
{
if (weechat::config_get_plugin("alignment") =~ /schannel/)
{
$str = $sbuf."\tChannel Monitoring Disabled";
}
else
{
$str = $nicename."\tChannel Monitoring Disabled";
}
}
else
{
$str = $nicename.": Channel Monitoring Disabled";
}
weechat::print($chanmon_buffer, $str);
return weechat::WEECHAT_RC_OK;
}
}
}
sub format_buffer
{
$cb_bufferp = $_[0];
$bufname = $_[1];
if (weechat::config_get_plugin("short_names") eq "on")
{
$bufname = weechat::buffer_get_string($cb_bufferp, 'short_name');
}
if (weechat::config_get_plugin("color_buf") eq "on")
{
$color = 0;
@char_array = split(//,weechat::buffer_get_string($cb_bufferp, 'name'));
foreach $char (@char_array)
{
$color += ord($char);
}
$color %= 10;
$color = sprintf "weechat.color.chat_nick_color%02d", $color+1;
$color = weechat::config_get($color);
$color = weechat::config_string($color);
$bufname = weechat::color($color).$bufname.weechat::color("reset");
}
elsif (weechat::config_get_plugin("color_buf") ne "off")
{
$color = weechat::config_get_plugin("color_buf");
$bufname = weechat::color($color).$bufname.weechat::color("reset");
}
return $bufname;
}
sub chanmon_dyn_toggle
{
$str = "";
if (weechat::config_get_plugin("dynamic") eq "off")
{
weechat::config_set_plugin("dynamic", "on");
$str = "Dynamic Channel Monitoring Enabled";
weechat::print($chanmon_buffer, $str);
return weechat::WEECHAT_RC_OK;
}
elsif (weechat::config_get_plugin("dynamic") eq "on")
{
weechat::config_set_plugin("dynamic", "off");
$str = "Dynamic Channel Monitoring Disabled";
weechat::print($chanmon_buffer, $str);
return weechat::WEECHAT_RC_OK;
}
}
sub chanmon_buffer_close
{
$chanmon_buffer = "";
return weechat::WEECHAT_RC_OK;
}
sub chanmon_buffer_setup
{
return weechat::WEECHAT_RC_OK;
}
sub chanmon_buffer_open
{
$chanmon_buffer = weechat::buffer_search("perl", "chanmon");
if ($chanmon_buffer eq "")
{
$chanmon_buffer = weechat::buffer_new("chanmon", "chanmon_buffer_setup", "", "", "chanmon_buffer_close", "");
}
if ($chanmon_buffer ne "")
{
weechat::buffer_set($chanmon_buffer, "notify", "0");
weechat::buffer_set($chanmon_buffer, "highlight_words", "-");
weechat::buffer_set($chanmon_buffer, "title", "Channel Monitor");
}
return weechat::WEECHAT_RC_OK;
}
sub chanmon_buffer_input
{
return weechat::WEECHAT_RC_OK;
}
sub print_help
{
weechat::print("", "\t".weechat::color("bold")."Chanmon Help".weechat::color("-bold")."\n\n");
weechat::print("", "\t".$chanmonhelp);
return weechat::WEECHAT_RC_OK;
}
weechat::register("chanmon", "KenjiE20", "1.7.1", "GPL3", "Channel Monitor", "", "");
weechat::hook_print("", "", "", 0, "chanmon_new_message", "");
weechat::hook_command("monitor", "Toggles monitoring for a channel (must be used in the channel buffer itself)", "", "", "", "chanmon_toggle", "");
weechat::hook_command("dynmon", "Toggles 'dynamic' monitoring (auto-disable monitoring for current channel)", "", "", "", "chanmon_dyn_toggle", "");
weechat::hook_command("chanmon", "Chanmon help", "", $chanmonhelp, "", "print_help", "");
weechat::hook_config("plugins.var.perl.chanmon.*", "", "");
if (!(weechat::config_is_set_plugin ("alignment")))
{
weechat::config_set_plugin("alignment", "channel");
}
if (weechat::config_get_plugin("alignment") eq "")
{
weechat::config_set_plugin("alignment", "none");
}
if (weechat::config_get_plugin("dynamic") eq "")
{
weechat::config_set_plugin("dynamic", "off");
}
if (!(weechat::config_is_set_plugin ("short_names")))
{
weechat::config_set_plugin("short_names", "off");
}
if (!(weechat::config_is_set_plugin ("color_buf")))
{
weechat::config_set_plugin("color_buf", "on");
}
if (!(weechat::config_is_set_plugin ("show_aways")))
{
weechat::config_set_plugin("show_aways", "off");
}
# Check for exisiting prefix/suffix chars, and setup accordingly
$prefix = weechat::config_get("irc.look.nick_prefix");
$prefix = weechat::config_string($prefix);
$suffix = weechat::config_get("irc.look.nick_suffix");
$suffix = weechat::config_string($suffix);
if (!(weechat::config_is_set_plugin("nick_prefix")))
{
if ($prefix eq "" && $suffix eq "")
{
weechat::config_set_plugin("nick_prefix", "<");
}
else
{
weechat::config_set_plugin("nick_prefix", "");
}
}
if (!(weechat::config_is_set_plugin("nick_suffix")))
{
if ($prefix eq "" && $suffix eq "")
{
weechat::config_set_plugin("nick_suffix", ">");
}
else
{
weechat::config_set_plugin("nick_suffix", "");
}
}
chanmon_buffer_open();
|