]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Add account-notify.pl
authorJanik Kleinhoff <redacted>
Sun, 5 Nov 2017 00:04:25 +0000 (00:04 +0000)
committerJanik Kleinhoff <redacted>
Thu, 30 Nov 2017 19:28:21 +0000 (19:28 +0000)
The script simply displays a message when people identify to an account
(or log out of one) on servers supporting the account-notify CAP.

scripts/account-notify.pl [new file with mode: 0644]

diff --git a/scripts/account-notify.pl b/scripts/account-notify.pl
new file mode 100644 (file)
index 0000000..41808b7
--- /dev/null
@@ -0,0 +1,67 @@
+# vim: ft=perl
+use strict;
+use warnings;
+
+use Irssi qw(theme_register signal_add servers);
+
+our $VERSION = '1.01';
+our %IRSSI = (
+    authors     => 'ilbelkyr',
+    contact     => 'ilbelkyr on freenode, ilbelkyr@shalture.org',
+    name        => 'account-notify',
+    description => 'Display account identification status changes using CAP account-notify',
+    license     => 'CC0 1.0 <https://creativecommons.org/publicdomain/zero/1.0/legalcode>',
+    changed     => 'Sun Nov 04 00:42:42 CET 2017',
+);
+
+theme_register([
+        account_identified   => '{channick_hilight $0} has identified as {hilight $2}',
+        account_unidentified => '{channick $0} has unidentified',
+    ]);
+
+sub on_account {
+    my ( $server, $account, $nick, $userhost ) = @_;
+
+    $account =~ s/^://;
+
+    # Print the notification to all shared channels, and the nick's query if any
+    for my $c ( $server->channels ) {
+        print_account( $c, $account, $nick, $userhost ) if $c->nick_find($nick);
+    }
+    my $q = $server->query_find($nick);
+    print_account( $q, $account, $nick, $userhost ) if defined $q;
+}
+
+sub print_account {
+    my ( $witem, $account, $nick, $userhost ) = @_;
+
+    if ( $account ne '*' ) {
+        $witem->printformat( MSGLEVEL_NICKS, 'account_identified', $nick, $userhost, $account );
+    }
+    else {
+        $witem->printformat( MSGLEVEL_NICKS, 'account_unidentified', $nick, $userhost );
+    }
+}
+
+sub on_connected {
+    my ($server) = @_;
+
+    if ( $server->{chat_type} eq 'IRC' ) {
+        $server->irc_server_cap_toggle( 'account-notify', 1 );
+    }
+}
+
+signal_add({
+        'event account'   => \&on_account,
+        'event connected' => \&on_connected,
+    });
+
+# When we are loaded, try to enable account-notify on all servers.
+# ...But complain if this irssi is too old
+if ( !Irssi::Irc::Server->can('irc_server_cap_toggle') ) {
+    die 'This script requires a more recent Irssi exposing the client capability API to Perl';
+}
+
+for my $server ( servers() ) {
+    on_connected($server);
+}
git clone https://git.99rst.org/PROJECT