Skip to content

Instantly share code, notes, and snippets.

@wodim
Last active August 9, 2020 22:37
Show Gist options
  • Select an option

  • Save wodim/9738411 to your computer and use it in GitHub Desktop.

Select an option

Save wodim/9738411 to your computer and use it in GitHub Desktop.
Irssi script that shows a list of nicks affected by a ban once it's set or unset
use Irssi;
use strict;
use vars qw($VERSION %IRSSI);
$VERSION = "0.3";
%IRSSI = (
authors => "wodim",
contact => '[email protected]',
name => "ban-affects",
description => "Shows a list of nicks affected by a ban once it's set or unset",
license => "BSD",
url => "",
);
sub ban_new {
my ($channel, $ban) = @_;
# return if the channel is not synchronised yet
# (we know no user masks yet)
return unless $channel->{wholist};
my @affected_nicks;
foreach my $nick ($channel->nicks()) {
if ($channel->{server}->mask_match_address(
$ban->{ban}, $nick->{nick}, $nick->{host})) {
if ($channel->{server}->{nick} eq $nick->{nick}) {
push @affected_nicks, $nick->{nick} . " (YOU!)";
} else {
push @affected_nicks, $nick->{nick};
}
}
}
if (scalar @affected_nicks) {
$channel->printformat(MSGLEVEL_CLIENTNOTICE, "ban_affects",
$ban->{ban}, $ban->{setby}, join(", ", @affected_nicks));
}
}
sub ban_remove {
my ($channel, $ban) = @_;
# return if the channel is not synchronised yet
# (we know no user masks yet)
return unless $channel->{wholist};
my @affected_nicks;
foreach my $nick ($channel->nicks()) {
if ($channel->{server}->mask_match_address(
$ban->{ban}, $nick->{nick}, $nick->{host})) {
if ($channel->{server}->{nick} eq $nick->{nick}) {
push @affected_nicks, $nick->{nick} . " (YOU!)";
} else {
push @affected_nicks, $nick->{nick};
}
}
}
if (scalar @affected_nicks) {
$channel->printformat(MSGLEVEL_CLIENTNOTICE, "unban_affects",
$ban->{ban}, $ban->{setby}, join(", ", @affected_nicks));
}
}
Irssi::theme_register([
"ban_affects", 'Ban {ban $0} set by {nick $1} affects: {hilight $2}',
"unban_affects", 'Ban {ban $0} set by {nick $1} was affecting: {hilight $2}',
]);
Irssi::signal_add_last("ban new", "ban_new");
Irssi::signal_add_last("ban remove", "ban_remove");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment