3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-12-23 19:22:40 +01:00

Fix auto-rejoin channels when reconnecting

This commit is contained in:
Pragmatic Software 2021-10-19 21:09:21 -07:00
parent 4809341e0f
commit 85fd8397c2
2 changed files with 14 additions and 0 deletions

View File

@ -20,6 +20,14 @@ sub initialize {
); );
$self->{storage}->load; $self->{storage}->load;
# reset joined_channels flag when disconnected
$self->{pbot}->{event_dispatcher}->register_handler(
'pbot.disconnect',
sub {
$self->{pbot}->{joined_channels} = 0;
}
);
} }
sub join { sub join {
@ -59,6 +67,7 @@ sub autojoin {
$self->{pbot}->{logger}->log("Joining channels: $channels\n"); $self->{pbot}->{logger}->log("Joining channels: $channels\n");
$self->join($channels); $self->join($channels);
$self->{pbot}->{joined_channels} = 1; $self->{pbot}->{joined_channels} = 1;
} }

View File

@ -60,6 +60,11 @@ sub on_disconnect {
$self->{pbot}->{logger}->log("Disconnected...\n"); $self->{pbot}->{logger}->log("Disconnected...\n");
$self->{pbot}->{connected} = 0; $self->{pbot}->{connected} = 0;
# send pbot.disconnect to notify PBot internals
$self->{pbot}->{event_dispatcher}->dispatch_event(
'pbot.disconnect', undef
);
# attempt to reconnect to server # attempt to reconnect to server
# TODO: maybe add a registry entry to control whether the bot auto-reconnects # TODO: maybe add a registry entry to control whether the bot auto-reconnects
$self->{pbot}->connect; $self->{pbot}->connect;