Commit bad392ad authored by Al-Caveman's avatar Al-Caveman Committed by Sébastien Helleu

commorkers.pl 0.2: add options to ignore nicks

parent 6b18d73c
# Al-Caveman <toraboracaveman@gmail.com>
# Licensed under GPL3
# https://github.com/Al-Caveman/commorkers
use warnings;
use strict;
# register script
weechat::register("commorkers", "Al-Caveman", "0.1", "GPL3", "Suppose that you have joined C many channels, then this script notifies you in each buffer about the movement of lurkers around you across all the C-1 channels.", "", "");
weechat::register("commorkers", "Al-Caveman", "0.2", "GPL3", "Suppose that you have joined C many channels, then this script notifies you in each buffer about the movement of lurkers around you across all the C many channels.", "", "");
# option help
my $opt_ignore_nick = "ignore_nicks";
my $opt_ignore_all_triggered_notices = "ignore_all_triggered_notices";
my $opt_ignore_nick_triggered_notices = "ignore_nicks_triggered_notices";
unless (weechat::config_is_set_plugin($opt_ignore_nick)) {
weechat::config_set_plugin($opt_ignore_nick, "");
}
unless (weechat::config_is_set_plugin($opt_ignore_all_triggered_notices)) {
weechat::config_set_plugin($opt_ignore_all_triggered_notices, "off");
}
unless (weechat::config_is_set_plugin($opt_ignore_nick_triggered_notices)) {
weechat::config_set_plugin($opt_ignore_nick_triggered_notices, "");
}
# colors
my $c_channel = weechat::color("chat_channel");
......@@ -14,7 +29,7 @@ my $c_chat_join = weechat::color("chat_prefix_join");
my $c_chat_quit = weechat::color("chat_prefix_quit");
my $c_emph = weechat::color("chat_prefix_error");
my $prefix = "+++\t";
my $prefix = "$c_emph+++\t$c_emph";
my $notice = '';
my %notice_buffer;
sub common_lurkers {
......@@ -42,6 +57,22 @@ sub common_lurkers {
}
}
# get list of nicks to ignore their triggered notices
my %ignore_nicks_trig_notice;
if (weechat::config_is_set_plugin($opt_ignore_nick_triggered_notices)) {
my $option_str = weechat::config_get_plugin($opt_ignore_nick_triggered_notices);
$option_str =~ s/ //g;
$ignore_nicks_trig_notice{lc $_} = 1 for grep {$_ !~ m/^ *$/} split(/,/, $option_str);
}
# see if triggered notices, as a whole, are disabled
my $trig_notice_enabled = 1;
if (weechat::config_is_set_plugin($opt_ignore_all_triggered_notices)) {
my $option_str = weechat::config_get_plugin($opt_ignore_all_triggered_notices);
$option_str =~ s/ //g;
$trig_notice_enabled = 0 if $option_str =~ m/^on$/i;
}
# get current buffer
my $buffer_current = weechat::current_buffer();
my $buffer_current_name = weechat::buffer_get_string($buffer_current, "name");
......@@ -57,7 +88,7 @@ sub common_lurkers {
if ($signal_data) {
my @nick_buffers = sort grep {(defined $buffernicks{$_}{$signal_data}) && ($_ ne $buffer_current_name)} keys %buffernicks;
if (scalar @nick_buffers) {
my $notice_tmp = "$c_emph$prefix".weechat::color(weechat::nicklist_nick_get_string($buffer_current, weechat::nicklist_search_nick($buffer_current, "", $signal_data, "color")))."$signal_data$c_emph also lurks in: ".join(", ", map {$c_channel.$_.$c_emph} @nick_buffers);
my $notice_tmp = "$prefix".weechat::color(weechat::nicklist_nick_get_string($buffer_current, weechat::nicklist_search_nick($buffer_current, "", $signal_data, "color")))."$signal_data$c_emph also lurks in: ".join(", ", map {$c_channel.$_.$c_emph} @nick_buffers);
$commorkers_found = 1;
weechat::print($buffer_current, $notice_tmp);
}
......@@ -74,7 +105,7 @@ sub common_lurkers {
}
}
if (scalar @buffer_name_common_lurkers) {
my $notice_tmp = $c_emph.$prefix."common lurkers from $c_channel$buffer_name$c_chat$c_emph:\n".join(", ", map {weechat::color(weechat::nicklist_nick_get_string($buffer_current, weechat::nicklist_search_nick($buffer_current, "", $_), "color")).$_.$c_chat} @buffer_name_common_lurkers)."\n";
my $notice_tmp = $prefix."common lurkers from $c_channel$buffer_name$c_chat$c_emph:\n".join(", ", map {weechat::color(weechat::nicklist_nick_get_string($buffer_current, weechat::nicklist_search_nick($buffer_current, "", $_), "color")).$_.$c_chat} @buffer_name_common_lurkers)."\n";
$commorkers_found = 1;
weechat::print($buffer_current, $notice_tmp);
}
......@@ -83,20 +114,20 @@ sub common_lurkers {
# no common lurkers found at all?
if ($commorkers_found == 0) {
my $notice_tmp = $c_emph.$prefix."no common lurkage found";
my $notice_tmp = $prefix."no common lurkage found";
$commorkers_found = 1;
$notice .= $notice_tmp;
weechat::print($buffer_current, $notice_tmp);
}
} else {
my $notice_tmp = $c_emph.$prefix."must execute /commorkers in a channel";
my $notice_tmp = $prefix."must execute /commorkers in a channel";
weechat::print($buffer_current, $notice_tmp);
}
}
# handle a join/part event by printing all channels the joining nick is lurking
# in
if (($data eq 'j') || ($data eq 'p')) {
if ((($data eq 'j') || ($data eq 'p')) && $trig_notice_enabled) {
# get the buffer where the event occurred
my $buffer_event_name = "$weechat_signal_server.$weechat_signal_channel";
my $buffer_event = weechat::buffer_search("irc", $buffer_event_name);
......@@ -104,7 +135,7 @@ sub common_lurkers {
# find channels where the subject nick is lurking in
my @lurker_common_buffers;
for my $buffer_name (grep {$_ ne $buffer_event_name} sort keys %buffernicks) {
if (defined $buffernicks{$buffer_name}{$weechat_signal_nick}) {
if ((defined $buffernicks{$buffer_name}{$weechat_signal_nick}) && !(defined $ignore_nicks_trig_notice{$weechat_signal_nick})) {
push @lurker_common_buffers, $buffer_name;
}
}
......@@ -112,7 +143,7 @@ sub common_lurkers {
# print notice in the channel where the join/part occurred
if (scalar @lurker_common_buffers) {
my $notice_tmp = join(", ", sort map {$c_channel.$_.$c_emph} @lurker_common_buffers)."\n";
$notice .= $c_emph.$prefix."a lurker from: $notice_tmp";
$notice .= $prefix."a lurker from: $notice_tmp";
#weechat::print($buffer_event, $notice);
# also print an incremental notification to all buffers were said
......@@ -122,7 +153,7 @@ sub common_lurkers {
my $c_lurker_nick = weechat::color(weechat::nicklist_nick_get_string($buffer_nickexists, weechat::nicklist_search_nick($buffer_nickexists, "", $weechat_signal_nick), "color"));
my $event_phrase = $c_chat_join."extended$c_emph lurkage to";
$event_phrase = $c_chat_quit."ceased$c_emph lurkage from" if $data eq 'p';
weechat::print($buffer_nickexists, $c_emph.$prefix."$c_lurker_nick$weechat_signal_nick$c_emph has $event_phrase: $c_channel$weechat_signal_channel$c_chat");
weechat::print($buffer_nickexists, $prefix."$c_lurker_nick$weechat_signal_nick$c_emph has $event_phrase: $c_channel$weechat_signal_channel$c_chat");
}
}
......@@ -130,7 +161,7 @@ sub common_lurkers {
# handle a quit event by printing all channels the joining nick is lurking
# in
if ($data eq 'q') {
if (($data eq 'q') && $trig_notice_enabled) {
for my $buffer_event_name (sort grep {defined $buffernicks{$_}{$weechat_signal_nick}} keys %buffernicks) {
# get the buffer where the event occurred
my $buffer_event = weechat::buffer_search("irc", $buffer_event_name);
......@@ -138,14 +169,14 @@ sub common_lurkers {
# find channels where the subject nick is lurking in
my @lurker_common_buffers;
for my $buffer_name (grep {$_ ne $buffer_event_name} sort keys %buffernicks) {
if (defined $buffernicks{$buffer_name}{$weechat_signal_nick}) {
if ((defined $buffernicks{$buffer_name}{$weechat_signal_nick}) && !(defined $ignore_nicks_trig_notice{$weechat_signal_nick})) {
push @lurker_common_buffers, $buffer_name;
}
}
# print notice in the channel where the quit occurred
if (scalar @lurker_common_buffers) {
my $notice_tmp = $c_emph.$prefix."also lurked in: ".join(", ", sort map {$c_channel.$_.$c_emph} @lurker_common_buffers)."\n";
my $notice_tmp = $prefix."also lurked in: ".join(", ", sort map {$c_channel.$_.$c_emph} @lurker_common_buffers)."\n";
$notice_buffer{$buffer_event} = $notice_tmp;
#weechat::print($buffer_event, $notice_tmp);
}
......@@ -159,6 +190,14 @@ sub init_buffernicks {
# get args
my $buffernicks_ref = shift;
# what are the nicks to ignore?
my %ignore_nicks;
if (weechat::config_is_set_plugin($opt_ignore_nick)) {
my $option_str = weechat::config_get_plugin($opt_ignore_nick);
$option_str =~ s/ //g;
$ignore_nicks{lc $_} = 1 for grep {$_ !~ m/^ *$/} split(/,/, $option_str);
}
# populate it with new entries
my $list_buffer = weechat::infolist_get("buffer", "", "");
if ($list_buffer) {
......@@ -175,7 +214,9 @@ sub init_buffernicks {
if ($list_nicks) {
while (weechat::infolist_next($list_nicks)) {
my $nick_name = weechat::infolist_string($list_nicks, "name");
${$buffernicks_ref}{$buffer_name}{$nick_name} = $buffer if $nick_name ne $buffer_mynick;
if (($nick_name ne $buffer_mynick) && !(defined $ignore_nicks{lc $nick_name})) {
${$buffernicks_ref}{$buffer_name}{$nick_name} = $buffer;
}
}
}
weechat::infolist_free($list_nicks);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment