From 3bfbeb5a429d29ab0a9cec7bb3d4f7b4a94df34b Mon Sep 17 00:00:00 2001 From: wowaname Date: Sun, 27 Nov 2016 13:12:40 +0000 Subject: [PATCH] antifuck.pl: add option to ignore/whitelist servers --- scripts/antifuck.pl | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/antifuck.pl b/scripts/antifuck.pl index 415099c..910a4a6 100644 --- a/scripts/antifuck.pl +++ b/scripts/antifuck.pl @@ -17,6 +17,8 @@ my %OPTIONS = ( 'You can always do this manually with /antifuck part', '0'], delay => ['Delay in milliseconds to wait before autoparting', '5000'], forward => ['Whether to allow channel forwards (+f on freenode)', '1'], + ignore => ['Servers to ignore (e.g. for non-ZNC bouncers), '. + 'separated by commas', ''], ); my (%channels, %part, %partbuf, $fuckbuf, $timeout_cb); @@ -40,6 +42,7 @@ HELP weechat::hook_signal('buffer_closed', 'buffer_closed', ''); weechat::hook_signal('*,irc_out1_join', 'client_join', ''); weechat::hook_signal('*,irc_out1_part', 'client_part', ''); + weechat::hook_signal('*,irc_raw_in_001', 'irc_001', ''); weechat::hook_modifier('irc_in_366', 'irc_366', ''); weechat::hook_modifier('irc_in_part', 'irc_part', ''); @@ -58,7 +61,6 @@ HELP lc weechat::buffer_get_string($buf, 'localvar_server')}{ lc weechat::buffer_get_string($buf, 'localvar_channel')} = 1; } - weechat::infolist_free($iptr); } @@ -69,6 +71,14 @@ sub mynick return lc weechat::buffer_get_string($buf, 'localvar_nick') eq lc $nick; } +sub ignored +{ + my $server = shift; + my $ignore_conf = lc weechat::config_get_plugin('ignore'); + + return $ignore_conf =~ /(^|,)$server($|,)/; +} + sub servchan { my $buf = shift; @@ -131,6 +141,7 @@ sub buffer_opened { my ($server, $channel) = servchan($buffer); return weechat::WEECHAT_RC_OK if exists $channels{$server}{$channel}; + return weechat::WEECHAT_RC_OK if ignored($server); $fuckbuf = weechat::buffer_new( 'antifuck', @@ -176,6 +187,22 @@ sub client_part return weechat::WEECHAT_RC_OK; } +sub irc_001 +{ + my (undef, $server, $message) = (shift, + shift =~ /(.+),irc_raw_in_001/, shift); + + $server = lc $server; + return weechat::WEECHAT_RC_OK unless $message =~ / :- Welcome to ZNC -$/; + + my $ignore_conf = lc weechat::config_get_plugin('ignore'); + return weechat::WEECHAT_RC_OK if $ignore_conf =~ /(^|,)$server($|,)/; + + weechat::config_set_plugin('ignore', "$ignore_conf,$server"); + + return weechat::WEECHAT_RC_OK; +} + sub irc_366 { my ($server, $message) = ($_[2], $_[3]); @@ -185,6 +212,7 @@ sub irc_366 return $message unless mynick($buffer, $nick); return $message if exists $channels{$server}{$channel}; + return $message if ignored($server); weechat::print($buffer, weechat::prefix('network'). 'Forcejoined, not syncing modes'); @@ -249,6 +277,7 @@ sub irc_part return $message unless mynick($buffer, $nick); return $message unless exists $channels{$lserver}{$lchannel}; + return $message if ignored($lserver); weechat::print($buffer, weechat::prefix('quit'). weechat::color('irc.color.message_quit').