diff options
author | David Phillips <david@sighup.nz> | 2017-03-10 10:04:03 +1300 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2017-03-10 10:17:02 +1300 |
commit | 07d4ed03896c453c7f95df4fe54b90716c6bc6e9 (patch) | |
tree | 04a7b5911baa18fdb1c1fbbe9480e35552a25a2c /saxrobot | |
parent | 870f05e2d4ddacdc58d3b515837dc2c2a17f83cc (diff) | |
download | idalius-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-x | saxrobot | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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); } |