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

View File

@ -60,6 +60,11 @@ sub on_disconnect {
$self->{pbot}->{logger}->log("Disconnected...\n");
$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
# TODO: maybe add a registry entry to control whether the bot auto-reconnects
$self->{pbot}->connect;