diff --git a/lib/PBot/Core/Channels.pm b/lib/PBot/Core/Channels.pm index 2891a06d..da5dc849 100644 --- a/lib/PBot/Core/Channels.pm +++ b/lib/PBot/Core/Channels.pm @@ -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; } diff --git a/lib/PBot/Core/Handlers/Server.pm b/lib/PBot/Core/Handlers/Server.pm index acacba5f..7353fb87 100644 --- a/lib/PBot/Core/Handlers/Server.pm +++ b/lib/PBot/Core/Handlers/Server.pm @@ -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;