aboutsummaryrefslogtreecommitdiff
path: root/saxrobot
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-03-10 10:04:03 +1300
committerDavid Phillips <david@sighup.nz>2017-03-10 10:17:02 +1300
commit07d4ed03896c453c7f95df4fe54b90716c6bc6e9 (patch)
tree04a7b5911baa18fdb1c1fbbe9480e35552a25a2c /saxrobot
parent870f05e2d4ddacdc58d3b515837dc2c2a17f83cc (diff)
downloadidalius-07d4ed03896c453c7f95df4fe54b90716c6bc6e9.tar.xz
Track our current nick correctly
Solves a bug where autorejoin would break if the bot had changed to a different nick from the one in its config file.
Diffstat (limited to 'saxrobot')
-rwxr-xr-xsaxrobot15
1 files changed, 13 insertions, 2 deletions
diff --git a/saxrobot b/saxrobot
index 3f6fdd9..8a59db6 100755
--- a/saxrobot
+++ b/saxrobot
@@ -10,6 +10,8 @@ use sb_config;
my %config = sb_config::parse_config('bot.conf');
+my $current_nick = $config{nick};
+
# New PoCo-IRC object
my $irc = POE::Component::IRC->spawn(
nick => $config{nick},
@@ -26,7 +28,7 @@ $irc->plugin_add('NickServID', POE::Component::IRC::Plugin::NickServID->new(
POE::Session->create(
package_states => [
- main => [ qw(_default _start irc_001 irc_kick irc_public irc_msg) ],
+ main => [ qw(_default _start irc_001 irc_kick irc_public irc_msg irc_nick) ],
],
heap => { irc => $irc },
);
@@ -51,9 +53,18 @@ sub irc_001 {
return;
}
+sub irc_nick {
+ my ($who, $new_nick) = @_[ARG0 .. ARG1];
+ my $oldnick = (split /!/, $who)[0];
+ if ($oldnick eq $current_nick) {
+ $current_nick = $new_nick;
+ }
+ return;
+}
+
sub irc_kick {
my ($kicker, $channel, $kickee, $reason) = @_[ARG0 .. ARG3];
- if ($kickee eq $config{nick}) {
+ if ($kickee eq $current_nick) {
print "I was kicked by $kicker ($reason). Rejoining now.\n";
$irc->yield(join => $channel);
}