From 9f2a0346e07c97601d7806049f6e3031bb96581c Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Fri, 7 Feb 2020 12:24:21 -0800 Subject: [PATCH] Plugins: unregister event handlers on unload --- Plugins/ActionTrigger.pm | 6 ++++++ Plugins/AntiAway.pm | 6 ++++++ Plugins/AntiKickAutoRejoin.pm | 6 ++++++ Plugins/AntiNickSpam.pm | 6 +++++- Plugins/AntiRepeat.pm | 2 ++ Plugins/AntiTwitter.pm | 5 +++++ Plugins/AutoRejoin.pm | 6 ++++++ Plugins/Battleship.pm | 3 +++ Plugins/Connect4.pm | 3 +++ Plugins/Counter.pm | 1 + Plugins/Example.pm | 5 +---- Plugins/RelayUnreg.pm | 1 + Plugins/Spinach.pm | 3 +++ Plugins/TypoSub.pm | 4 +++- Plugins/UrlTitles.pm | 6 +++++- 15 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Plugins/ActionTrigger.pm b/Plugins/ActionTrigger.pm index 1b9e4d3c..60e2e353 100644 --- a/Plugins/ActionTrigger.pm +++ b/Plugins/ActionTrigger.pm @@ -72,6 +72,12 @@ sub unload { $self->dbi_end; $self->{pbot}->{commands}->unregister('actiontrigger'); $self->{pbot}->{capabilities}->remove('can-actiontrigger'); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.caction', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.join', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.part', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.quit', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick', __PACKAGE__); } sub create_database { diff --git a/Plugins/AntiAway.pm b/Plugins/AntiAway.pm index 2b9de86f..83d2d859 100644 --- a/Plugins/AntiAway.pm +++ b/Plugins/AntiAway.pm @@ -36,6 +36,12 @@ sub initialize { $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->on_action(@_) }); } +sub unload { + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.nick', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.caction', __PACKAGE__); +} + sub on_nickchange { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $newnick) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->args); diff --git a/Plugins/AntiKickAutoRejoin.pm b/Plugins/AntiKickAutoRejoin.pm index 13842e63..a79410d5 100644 --- a/Plugins/AntiKickAutoRejoin.pm +++ b/Plugins/AntiKickAutoRejoin.pm @@ -38,6 +38,12 @@ sub initialize { $self->{kicks} = {}; } +sub unload { + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.join', __PACKAGE__); +} + sub on_kick { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $target, $channel, $reason) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->to, $event->{event}->{args}[0], $event->{event}->{args}[1]); diff --git a/Plugins/AntiNickSpam.pm b/Plugins/AntiNickSpam.pm index 283e6316..1d61bbcf 100644 --- a/Plugins/AntiNickSpam.pm +++ b/Plugins/AntiNickSpam.pm @@ -35,7 +35,11 @@ sub initialize { $self->{nicks} = {}; } -sub unload {} +sub unload { + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.caction', __PACKAGE__); +} sub on_action { my ($self, $event_type, $event) = @_; diff --git a/Plugins/AntiRepeat.pm b/Plugins/AntiRepeat.pm index 9386a9e5..e35ca36e 100644 --- a/Plugins/AntiRepeat.pm +++ b/Plugins/AntiRepeat.pm @@ -45,6 +45,8 @@ sub initialize { sub unload { my $self = shift; $self->{pbot}->{timer}->unregister('antirepeat'); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.caction', __PACKAGE__); } sub on_public { diff --git a/Plugins/AntiTwitter.pm b/Plugins/AntiTwitter.pm index fe027592..ceeff269 100644 --- a/Plugins/AntiTwitter.pm +++ b/Plugins/AntiTwitter.pm @@ -38,6 +38,11 @@ sub initialize { $self->{offenses} = {}; } +sub unload { + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); +} + sub on_public { my ($self, $event_type, $event) = @_; my ($nick, $user, $host, $channel, $msg) = ($event->{event}->nick, $event->{event}->user, $event->{event}->host, $event->{event}->{to}[0], $event->{event}->args); diff --git a/Plugins/AutoRejoin.pm b/Plugins/AutoRejoin.pm index 2f29ba15..c79d363b 100644 --- a/Plugins/AutoRejoin.pm +++ b/Plugins/AutoRejoin.pm @@ -37,6 +37,12 @@ sub initialize { $self->{rejoins} = {}; } +sub unload { + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.part', __PACKAGE__); +} + sub rejoin_channel { my ($self, $channel) = @_; $self->{rejoins}->{$channel}->{rejoins} = 0 if not exists $self->{rejoins}->{$channel}; diff --git a/Plugins/Battleship.pm b/Plugins/Battleship.pm index 04139fc8..7e94717b 100644 --- a/Plugins/Battleship.pm +++ b/Plugins/Battleship.pm @@ -54,6 +54,9 @@ sub unload { my $self = shift; $self->{pbot}->{commands}->unregister('battleship'); $self->{pbot}->{timer}->unregister('battleship timer'); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.part', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.quit', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick', __PACKAGE__); } sub on_kick { diff --git a/Plugins/Connect4.pm b/Plugins/Connect4.pm index af99e3fe..cf1f0dca 100644 --- a/Plugins/Connect4.pm +++ b/Plugins/Connect4.pm @@ -48,6 +48,9 @@ sub unload { my $self = shift; $self->{pbot}->{commands}->unregister('connect4'); $self->{pbot}->{timer}->unregister('connect4 timer'); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.part', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.quit', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick', __PACKAGE__); } sub on_kick { diff --git a/Plugins/Counter.pm b/Plugins/Counter.pm index 1fe51ad0..ca2f9861 100644 --- a/Plugins/Counter.pm +++ b/Plugins/Counter.pm @@ -52,6 +52,7 @@ sub unload { $self->{pbot}->{commands}->unregister('counterlist'); $self->{pbot}->{commands}->unregister('countertrigger'); $self->{pbot}->{capabilities}->remove('can-countertrigger'); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); } sub create_database { diff --git a/Plugins/Example.pm b/Plugins/Example.pm index d35861ad..3431dd24 100644 --- a/Plugins/Example.pm +++ b/Plugins/Example.pm @@ -8,7 +8,6 @@ use warnings; use strict; use feature 'unicode_strings'; - use Carp (); sub new { @@ -28,9 +27,7 @@ sub initialize { sub unload { my $self = shift; # perform plugin clean-up here - # normally we'd unregister the 'irc.public' event handler; however, the - # event dispatcher will do this automatically for us when it sees there - # is no longer an existing sub. + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); } sub on_public { diff --git a/Plugins/RelayUnreg.pm b/Plugins/RelayUnreg.pm index 09ef5fdc..a2c0c9e9 100644 --- a/Plugins/RelayUnreg.pm +++ b/Plugins/RelayUnreg.pm @@ -30,6 +30,7 @@ sub initialize { sub unload { my $self = shift; $self->{pbot}->{timer}->unregister('RelayUnreg'); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); } sub on_public { diff --git a/Plugins/Spinach.pm b/Plugins/Spinach.pm index dcf92010..4c44df1b 100644 --- a/Plugins/Spinach.pm +++ b/Plugins/Spinach.pm @@ -86,6 +86,9 @@ sub unload { $self->{pbot}->{commands}->unregister('spinach'); $self->{pbot}->{timer}->unregister('spinach timer'); $self->{stats}->end if $self->{stats_running}; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.part', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.quit', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.kick', __PACKAGE__); } sub on_kick { diff --git a/Plugins/TypoSub.pm b/Plugins/TypoSub.pm index 077354a3..2d9c5d0c 100644 --- a/Plugins/TypoSub.pm +++ b/Plugins/TypoSub.pm @@ -38,7 +38,9 @@ sub initialize { } sub unload { - # nothing to do here + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.caction', __PACKAGE__); } sub on_public { diff --git a/Plugins/UrlTitles.pm b/Plugins/UrlTitles.pm index a857d2a5..232e8b89 100644 --- a/Plugins/UrlTitles.pm +++ b/Plugins/UrlTitles.pm @@ -36,7 +36,11 @@ sub initialize { $self->{pbot}->{event_dispatcher}->register_handler('irc.caction', sub { $self->show_url_titles(@_) }); } -sub unload {} +sub unload { + my ($self) = @_; + $self->{pbot}->{event_dispatcher}->remove_handler('irc.public', __PACKAGE__); + $self->{pbot}->{event_dispatcher}->remove_handler('irc.caction', __PACKAGE__); +} sub show_url_titles { my ($self, $event_type, $event) = @_;