diff options
author | David Phillips <david@yeah.nah.nz> | 2018-10-02 17:03:00 +1300 |
---|---|---|
committer | David Phillips <david@yeah.nah.nz> | 2018-10-02 17:03:00 +1300 |
commit | 7aa9d419bc1d4a0f9e6cc369b06dd54c606df20b (patch) | |
tree | 89afcb09e4bd2074e5aae5a327c52dd81b525273 /idalius.pl | |
parent | 765205d27f19ff2b4484336b570937feaedd8643 (diff) | |
download | idalius-7aa9d419bc1d4a0f9e6cc369b06dd54c606df20b.tar.xz |
Add rejoin delay, reconfigure modules on reconnection
Diffstat (limited to 'idalius.pl')
-rwxr-xr-x | idalius.pl | 40 |
1 files changed, 28 insertions, 12 deletions
@@ -25,15 +25,7 @@ sub log_info { Plugin::set_load_callback(\&module_loaded_callback); -eval { - for my $module (@{$config->{_}->{plugins}}) { - Plugin::load_plugin(\&log_info, $config->{_}, $module); - } - 1; -} or do { - log_info "Error: failed to load module: $@"; - die; -}; +load_configure_all_plugins(); $| = 1; @@ -82,6 +74,18 @@ drop_priv(); $poe_kernel->run(); +sub load_configure_all_plugins { + eval { + for my $module (@{$config->{_}->{plugins}}) { + Plugin::load_plugin(\&log_info, $config->{_}, $module); + } + 1; + } or do { + log_info "Error: failed to load module: $@"; + die; + }; +} + sub module_loaded_callback { my ($module) = @_; @@ -283,20 +287,32 @@ sub irc_invite { $irc->yield(join => $where) if (grep {$_ eq $where} @{$config->{_}->{channels}}); } +sub reconnect { + my $reconnect_delay = 20; + + log_info("Reconnecting in $reconnect_delay seconds"); + sleep($reconnect_delay); + + $irc->yield(connect => { }); +} + sub irc_disconnected { _default(@_); # Dump the message + my $reconnect_delay = 20; + $config = IdaliusConfig::parse_config($config_file); - $irc->yield(connect => { }); + load_configure_all_plugins(); + reconnect(); } sub irc_error { _default(@_); # Dump the message - $irc->yield(connect => { }); + reconnect(); } sub irc_socketerr { _default(@_); # Dump the message - $irc->yield(connect => { }); + reconnect(); } sub _default { |