diff options
| -rw-r--r-- | scripts/bitlbee_hide_password.pl | 64 | ||||
| -rw-r--r-- | scripts/chansort_configurable.pl | 144 | ||||
| -rw-r--r-- | scripts/msg2notice_regex.pl | 56 | ||||
| -rw-r--r-- | scripts/munge_own_nickname_to_username.pl | 79 | ||||
| -rw-r--r-- | scripts/slack_strip_auto_cc.pl | 35 | 
5 files changed, 378 insertions, 0 deletions
| diff --git a/scripts/bitlbee_hide_password.pl b/scripts/bitlbee_hide_password.pl new file mode 100644 index 0000000..feb86b2 --- /dev/null +++ b/scripts/bitlbee_hide_password.pl @@ -0,0 +1,64 @@ +use strict; +use warnings; +use Irssi; + +our $VERSION = '1.0'; +our %IRSSI = ( +    authors     => 'Ævar Arnfjörð Bjarmason', +    contact     => 'avarab@gmail.com', +    name        => 'bitlbee_hide_password.pl', +    description => 'Hide your REGISTER and IDENTIFY password lines in &bitlbee from screen & logs ', +    license     => 'Public Domain', +    url         => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/bitlbee_hide_password.pl', +); + +# HOWTO: +# +#   /load bitlbee_hide_password.pl +# +# When you're using Bitlbee and do either: +# +#    REGISTER <password> +# +# or: +# +#    IDENTIFY <password> +# +# Your password will be shown on screen, and more importantly logged +# in your logfiles. This extension intercepts these commands in your +# &bitlbee channel and hides it from screen & logs. +# +# Note: You can avoid the password going into the log without this +# plugin by doing: +# +#    IDENTIFY +#    /OPER +# +# But this script also makes sure that your REGISTER commands will be +# hidden, and of course "IDENTIFY <password>" commands if you ever +# forget to IDENTIFY with /OPER. + +sub msg_intercept_bitlbee_password_lines { +    my ($tdest, $data, $stripped) = @_; + +    # The $tdest object has various other things, like ->{target}, +    # ->{window} (object) etc. +    my $server = $tdest->{server}; + +    # Some events just have ->{window} and no ->{server}, we can +    # ignore those +    return unless $server; + +    # We only care about the &bitlbee control channel +    my $target = $tdest->{target}; +    return unless $target eq '&bitlbee'; + +    # We're matching against $stripped but replacing both because the +    # $data thing is escaped and much harder to match against. +    if ($stripped =~ /^<.?[^>]+> (?:register|identify) .+/si) { +        s/(identify|register) .+/$1 <password stripped by $IRSSI{name}>/i for $data, $stripped; +        Irssi::signal_continue($tdest, $data, $stripped); +    } +} + +Irssi::signal_add_first('print text', 'msg_intercept_bitlbee_password_lines'); diff --git a/scripts/chansort_configurable.pl b/scripts/chansort_configurable.pl new file mode 100644 index 0000000..639b822 --- /dev/null +++ b/scripts/chansort_configurable.pl @@ -0,0 +1,144 @@ +use strict; +use warnings; +use Irssi; +use File::Spec::Functions qw(catdir catfile); + +our $VERSION = '1.0'; +our %IRSSI = ( +    authors     => 'Ævar Arnfjörð Bjarmason', +    contact     => 'avarab@gmail.com', +    name        => 'chansort_configurable', +    description => "Sort channels & query windows in a configurable way, based on Peder Stray's chansort.pl", +    license     => 'GPL', +    url         => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/chansort_configurable.pl', +); + +# HOWTO: +# +#   /load chansort_configurable.pl +#   /set chansort_configurable_autosort ON +# +# This is a plugin that allows you to sort your windows in any +# arbitrary way using a callback you provide. I originally forked this +# from chansort.pl on https://scripts.irssi.org which is a similar +# plugin that just sorts the windows in a pre-determined order. +# +# By default this plugin will sort things in a pre-determined order, +# but you can create a +# ~/.irssi/scripts/chansort_configurable_callback.pl file with a +# subroutine that we'll call inside sort() (so the $a and $b sort +# variables are available). E.g. creating the file as: +# +#     use strict; +#     use warnings; +# +#     sub { +#         rand() <=> rand() +#     } +# +# Would sort your windows in a random order. This would be somewhat +# more useful: +# +#     use strict; +#     use warnings; +# +#     my $n = -9001; +#     my %hardcoded_positioning = ( +#         freenode => { +#             '#irssi'         => $n++, # 2 +#             '#freenode'      => $n++, # 3 +#         }, +#     ); +# +#     sub { +#         # Provide a default sorter with some sane defaults +#         exists($a->{chatnet}) <=> exists($b->{chatnet}) +#         || +#         # "CHANNEL" will sort before "QUERY" +#         $a->{type} cmp $b->{type} +#         || +#         # Cluster chatnets alphabetically +#         $a->{chatnet} cmp $b->{chatnet} +#         || +#         # Put & channels like &bitlbee before normal channels +#         ($b->{name} =~ /^&/) <=> ($a->{name} =~ /^&/) +#         || +#         # Allow for hardcoding the positioning of channels +#         # within a network +#         ($hardcoded_positioning{$a->{chatnet}}->{$a->{name}} || 0) <=> ($hardcoded_positioning{$b->{chatnet}}->{$b->{name}} || 0) +#         || +#         # Default to sorting alphabetically +#         $a->{name} cmp $b->{name} +#     }; +# +# The above sorter will sort channels before queries, and networks +# alphabetically, but will sort make the #irssi channel be the first +# channel on the freenode network. + +my $sort_callback_file = catfile(catdir(Irssi::get_irssi_dir(), 'scripts'), 'chansort_configurable_callback.pl'); +my $sort_callback = do $sort_callback_file; + +sub cmd_chansort_configurable { +    my @windows; + +    for my $window (Irssi::windows()) { +        my $active = $window->{active}; + +        push @windows => { +            # Extract these to the top-level for easy extraction +            refnum       => $window->{refnum}, +            (exists $active->{server} +             # This is for everything except the (status) window +             ? ( +                 name    => $active->{name}, +                 type    => $active->{type}, +                 chatnet => $active->{server}->{chatnet}, +             ) +             : ()), +            # The raw window object with all the details. +            window => $window, +        }; +    } + +    @windows = sort { +        ( +            $sort_callback +            ? ($sort_callback->()) +            : ( +                # Provide a default sorter with some sane defaults +                exists($a->{chatnet}) <=> exists($b->{chatnet}) +                || +                # "CHANNEL" will sort before "QUERY" +                $a->{type} cmp $b->{type} +                || +                # Cluster chatnets alphabetically +                $a->{chatnet} cmp $b->{chatnet} +                || +                # Put & channels like &bitlbee before normal channels +                ($b->{name} =~ /^&/) <=> ($a->{name} =~ /^&/) +                || +                # Default to sorting alphabetically +                $a->{name} cmp $b->{name} +            ) +        ) +    } @windows; + +    my $i = 0; +    for my $window (@windows) { +        $i++; +        $window->{window}->command("WINDOW MOVE $i"); +    } + +    return; +} + +sub sig_chansort_configurable_trigger { +    return unless Irssi::settings_get_bool('chansort_configurable_autosort'); +    cmd_chansort_configurable(); +} + +Irssi::command_bind('chansort_configurable', 'cmd_chansort_configurable'); +Irssi::settings_add_bool('chansort_configurable', 'chansort_configurable_autosort', 0); +Irssi::signal_add_last('window item name changed', 'sig_chansort_configurable_trigger'); +Irssi::signal_add_last('channel created', 'sig_chansort_configurable_trigger'); +Irssi::signal_add_last('query created', 'sig_chansort_configurable_trigger'); diff --git a/scripts/msg2notice_regex.pl b/scripts/msg2notice_regex.pl new file mode 100644 index 0000000..9ecedf6 --- /dev/null +++ b/scripts/msg2notice_regex.pl @@ -0,0 +1,56 @@ +use strict; +use warnings; +use Irssi; + +our $VERSION = '1.0'; +our %IRSSI = ( +    authors     => 'Fernando Vezzosi & Ævar Arnfjörð Bjarmason', +    contact     => 'irssi@repnz.net & avarab@gmail.com', +    name        => 'msg2notice_regex.pl', +    description => 'For a configured list of nicks or nicks matching a regex, convert all their messages to a notices', +    license     => 'Public Domain', +    url         => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/msg2notice_regex.pl & https://github.com/bucciarati/irssi-script-msg_to_notice', +); + +# HOWTO: +# +#   /load msg2notice_regex.pl +#   /set noticeable_nicks ~\[bot\]$,~mon-[0-9]+$,~^mon-.*-[0-9]+$,root,deploy,log,jenkins,nagmetoo +# +# The nicks that match will be turned into notices, useful for marking +# bots as such. Note that if the nicks start with ~ the rest is taken +# to be a regex. Due to limitations of our dummy parser you can't use +# {x,y} character classes or other regex constructs that require a +# comma, but usually that's something you can work around. + +sub privmsg_msg2notice_regex { +    use Data::Dumper; +    my ($server, $data, $nick, $nick_and_address) = @_; +    my ($target, $message) = split /:/, $data, 2; + +    # Irssi::print("server<$server> data<$data>[$target:$message] nick<$nick> mask<$nick_and_address>"); +    my $is_noticeable = 0; +    for my $noticeable_nick ( split /[\s,]+/, Irssi::settings_get_str('noticeable_nicks') ) { +        $noticeable_nick =~ s/\A \s+//x; +        $noticeable_nick =~ s/\s+ \z//x; +        my $is_regexp; $is_regexp = 1 if $noticeable_nick =~ s/^~//; + +        # Irssi::print("Checking <$nick> to <$noticeable_nick> via <" . ($is_regexp ? "rx" : "eq") . ">"); +        if ( $is_regexp and $nick =~ $noticeable_nick ) { +            # Irssi::print("Matched <$nick> to <$noticeable_nick> via <rx>"); +            $is_noticeable = 1; +            last; +        } elsif ( not $is_regexp and lc $noticeable_nick eq lc $nick ){ +            # Irssi::print("Matched <$nick> to <$noticeable_nick> via <eq>"); +            $is_noticeable = 1; +            last; +        } +    } +    return unless $is_noticeable; + +    Irssi::signal_emit('event notice', $server, $data, $nick, $nick_and_address); +    Irssi::signal_stop(); +} + +Irssi::settings_add_str('msg_to_notice', 'noticeable_nicks', '~\[bot\]$,root,deploy'); +Irssi::signal_add('event privmsg', 'privmsg_msg2notice_regex'); diff --git a/scripts/munge_own_nickname_to_username.pl b/scripts/munge_own_nickname_to_username.pl new file mode 100644 index 0000000..85e9328 --- /dev/null +++ b/scripts/munge_own_nickname_to_username.pl @@ -0,0 +1,79 @@ +use strict; +use warnings; +use Irssi; + +our $VERSION = '1.0'; +our %IRSSI = ( +    authors     => 'Ævar Arnfjörð Bjarmason', +    contact     => 'avarab@gmail.com', +    name        => 'munge_own_nickname_to_username.pl', +    description => 'Changes messages from myself to appear to come from my username, not my nickname', +    license     => 'Public Domain', +    url         => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/munge_own_nickname_to_username.pl', +); + +# HOWTO: +# +#   /load munge_own_nickname_to_username.pl +# +# This is for use on servers where your NICK is forced upon you, +# e.g. when connecting to some corporate maintained Bitlbee server +# that has LDAP-connected accounts. +# +# In that case your NICK may not be what you're used to. This +# intercepts "print text" events from irssi and rewrites them so that +# they appear to come from the "nick" configured in +# settings.core.user_name instead of whatever your nickname is on the +# server. +# +# The result is that you'll appear to yourself to have your "correct" +# nickname. The illusion goes pretty far, even down to your IRC logs, +# but of course everyone else will see you as your real nickname, or +# maybe your username (I use this for a IRC->Slack/Bitlee gateway). +# +# This should just automatically work, it'll detect what your nick is, +# what you're username is, and automatically substitute +# s/nick/username/ if applicable. +# +# Note that if your theme adjusts the msgnick rendering this may not +# work, because we try to match "< yournick>" in the line. We could +# potentially do better, please contact the author if you run into +# issues with this. + +sub msg_rename_myself_in_printed_text { +    my ($tdest, $data, $stripped) = @_; + +    # The $tdest object has various other things, like ->{target}, +    # ->{window} (object) etc. +    my $server = $tdest->{server}; + +    # Some events just have ->{window} and no ->{server}, we can +    # ignore those +    return unless $server; + +    # Unpack our configuration from $server. +    my $server_username = $server->{username}; +    my $server_nick     = $server->{nick}; + +    # We have nothing to do here, our nick is already the same as our +    # username. +    return if $server_username eq $server_nick; + +    # We're matching against $stripped but replacing both because the +    # $data thing is escaped and much harder to match against. +    # +    # We're just replacing nick mentions, so e.g. if you say "Hi I'm +    # bob here but my username is bobby" it won't turn into "Hi I'm +    # bobby here but my username is bobby". +    # +    # The illusion here isn't complete, e.g. if you do /NAMES your +    # nick will show up and not your username, but I consider that a +    # feature. +    if ($stripped =~ /^<.?\Q$server_nick\E> /s) { +        s/\Q$server_nick\E/$server_username/ for $data, $stripped; + +        Irssi::signal_continue($tdest, $data, $stripped); +    } +} + +Irssi::signal_add_first('print text', 'msg_rename_myself_in_printed_text'); diff --git a/scripts/slack_strip_auto_cc.pl b/scripts/slack_strip_auto_cc.pl new file mode 100644 index 0000000..b4fac4e --- /dev/null +++ b/scripts/slack_strip_auto_cc.pl @@ -0,0 +1,35 @@ +use strict; +use warnings; +use Irssi; + +our $VERSION = '1.0'; +our %IRSSI = ( +    authors     => 'Ævar Arnfjörð Bjarmason', +    contact     => 'avarab@gmail.com', +    name        => 'slack_strip_auto_cc.pl', +    description => 'Strips the annoying mentions of your nickname on Slack via [cc: <you>]', +    license     => 'Public Domain', +    url         => 'http://scripts.irssi.org & https://github.com/avar/dotfiles/blob/master/.irssi/scripts/slack_strip_auto_cc.pl', +); + +# HOWTO: +# +#   /load slack_strip_auto_cc.pl +# +# This should just automatically work, it'll detect if you're using +# the slack IRC gateway and auto-detect the nick it should be +# stripping as well. + +sub privmsg_slack_strip_auto_cc { +    my ($server, $data, $nick, $nick_and_address) = @_; +    my ($target, $message) = split /:/, $data, 2; + +    return unless $server->{address} =~ /irc\.slack\.com$/s; +    my $wanted_nick = $server->{wanted_nick}; +    return unless $message =~ s/ \[cc: \Q$wanted_nick\E\]$//s; + +    my $new_data = "$target:$message"; +    Irssi::signal_continue($server, $new_data, $nick, $nick_and_address); +} + +Irssi::signal_add('event privmsg', 'privmsg_slack_strip_auto_cc'); | 
