aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--slacktopic.pl82
1 files changed, 47 insertions, 35 deletions
diff --git a/slacktopic.pl b/slacktopic.pl
index e8a787b..9fe70b1 100644
--- a/slacktopic.pl
+++ b/slacktopic.pl
@@ -34,11 +34,12 @@
# harm done, but no topic updates either.
# Notes:
-# - This script would possibly work for other FreeNode channels that track
-# a ChangeLog and update the /topic when there's a change. You'd want
-# to at least change $update_channel and $update_cmd. If you're not on
-# FreeNode, more surgery will be required (if there's a way to change
-# the /topic by talking to a 'services' bot, it should be possible).
+# - This script would possibly work for other FreeNode or Libera channels
+# that track a ChangeLog and update the /topic when there's
+# a change. You'd want to at least change @update_channels and
+# $update_cmd. If you're not on FreeNode/Libera, more surgery will be
+# required (if there's a way to change the /topic by talking to a
+# 'services' bot, it should be possible).
# - Please don't try to talk me into using LWP and one of the Date::
# modules in place of executing curl and date. Slackware doesn't ship
# them, plus they're huge and I don't want to keep them loaded in
@@ -63,15 +64,15 @@ use Irssi qw/
window_find_name
/;
-our $VERSION = "0.1";
+our $VERSION = "0.2";
our %IRSSI = (
authors => 'B. Watson',
- contact => 'yalhcru@gmail.com or Urchlay on FreeNode ##slackware',
+ contact => 'yalhcru@gmail.com or Urchlay on libera.chat ##slackware',
name => 'slacktopic',
description => 'Updates ##slackware /topic whenever there\'s a ' .
'security update in the Slackware ChangeLog.',
license => 'WTFPL',
- url => 'http://urchlay.naptime.net/repos/misc-scripts/',
+ url => 'https://slackware.uk/~urchlay/repos/misc-scripts',
);
### Configurables.
@@ -122,14 +123,18 @@ our $update_cmd = "rm -f $cmd_outfile ; " .
if($FAKE) { $update_cmd = "echo '$FAKE' > $cmd_outfile"; }
-# What channel's /topic are we updating?
-our $update_channel = "##slackware";
+# What channel(s) /topic are we updating?
+our @update_channels = (
+ "##slackware", "#slackware.uk"
+ );
-# What server is $update_channel supposed to be on? This is paranoid
+# What server are @update_channels supposed to be on? This is paranoid
# maybe, AFAIK no other network uses the ## like freenode does, so
# the channel name ##slackware should be enough to identify it. But,
# ehhh, a little paranoia goes a long way...
-our $server_regex = qr/\.freenode\.(org|net)$/;
+# 20210602 bkw: now there's libera.chat, which can be thought of as a
+# fork of freenode.
+our $server_regex = qr/\.libera\.chat$/;
# Seconds between update checks. Every check executes $update_script, which
# talks to ftp.slackware.com, so be polite here.
@@ -199,32 +204,37 @@ sub init {
}
}
-# Return a Channel (always true) if we're joined to the correct channel,
-# otherwise return undef (false).
-sub get_channel {
- my $chan = channel_find($update_channel);
- if(!$chan) {
- errmsg("not joined to $update_channel");
- return;
- }
+# Return a list of the @update_channels we're actually joined to, or
+# undef (false) if none.
+sub get_channels {
+ my @result;
+ for(@update_channels) {
+ my $chan = channel_find($_);
+ if(!$chan) {
+ errmsg("not joined to $_");
+ next;
+ }
- my $server = $chan->{server}->{address};
- if($server !~ $server_regex) {
- errmsg("channel $update_channel server is wrong: " .
- $chan->{server}->{address});
- return;
+ my $server = $chan->{server}->{address};
+ if($server !~ $server_regex) {
+ errmsg("channel $_ server is wrong: " .
+ $chan->{server}->{address});
+ next;
+ }
+
+ push @result, $chan;
}
- return $chan;
+ return @result;
}
# First update might need to be delayed. Usually we're being autoloaded at
# irssi startup, and we might get called before autojoining the channel,
# and/or before being logged in to services. Hard-coded 10 sec here. If
-# FreeNode or your ISP is being slow, the first update still might
+# the IRC server or your ISP is being slow, the first update still might
# fail. Oh well.
sub initial_update {
- if(get_channel()) {
+ if(get_channels()) {
start_update();
} else {
timeout_add_once(10 * 1000, "start_update", 0);
@@ -240,11 +250,11 @@ sub start_update {
if($force_date !~ /^\d\d\d\d-\d\d-\d\d$/) {
errmsg("Invalid date '$force_date'");
} else {
- set_topic_date(get_channel(), $force_date, 1);
+ set_topic_date($_, $force_date, 1) for get_channels();
}
} else {
# Don't do anything if we're not joined to the channel already.
- exec_update() if get_channel();
+ exec_update() if get_channels();
}
}
@@ -268,9 +278,9 @@ sub finish_update {
# ChanServ would let us change the topic even if we weren't in
# the channel, but let's not do that. For one thing, it's a PITA
# to retrieve the old topic, if we're not in the channel.
- # No debugmsg here, get_channel() already did it.
- my $chan = get_channel();
- return unless $chan;
+ # No debugmsg here, get_channels() already did it.
+ my @chans = get_channels();
+ return unless @chans;
# Get the date of the last update.
my $new_date;
@@ -288,7 +298,9 @@ sub finish_update {
return;
}
- set_topic_date($chan, $new_date, 0);
+ for(@chans) {
+ set_topic_date($_, $new_date, 0);
+ }
}
sub set_topic_date {
@@ -316,7 +328,7 @@ sub set_topic_date {
# Ask ChanServ to change the topic for us. We don't need +o in
# the channel, so long as we're logged in to services and have +t.
logmsg("ChangeLog updated [$new_date], asking ChanServ to update topic");
- $chan->{server}->send_raw("ChanServ topic $update_channel $t");
+ $chan->{server}->send_raw("ChanServ topic " . $chan->{name} . " $t");
}
# Called if the child process times out ($cmd_timeout + 2 sec).