From 8c862af5a181a601e871cff8244d164da743a8f7 Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sat, 22 Jun 2019 23:04:09 +1200 Subject: Evict auto-joining of channels to module --- IdaliusConfig.pm | 2 +- Plugin/Autojoin.pm | 23 +++++++++++++++++++++++ Plugin/Log.pm | 3 ++- bot.conf.example | 6 ++++-- idalius.pl | 10 +++++----- 5 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 Plugin/Autojoin.pm diff --git a/IdaliusConfig.pm b/IdaliusConfig.pm index 642d408..3f919b6 100644 --- a/IdaliusConfig.pm +++ b/IdaliusConfig.pm @@ -48,7 +48,7 @@ sub check_config # Lists of mandatory config variables my @scalars = qw/nick username ircname server port usessl sslcert sslkey user group prefix_nick prefix log_debug/; - my @lists = qw/plugins channels ignore/; + my @lists = qw/plugins ignore/; foreach my $name (@scalars) { assert_scalar($config->{_}, "_", $name); diff --git a/Plugin/Autojoin.pm b/Plugin/Autojoin.pm new file mode 100644 index 0000000..0620ecd --- /dev/null +++ b/Plugin/Autojoin.pm @@ -0,0 +1,23 @@ +package Plugin::Autojoin; + +use strict; +use warnings; + +my $config; + +sub configure { + my $self = shift; + shift; # cmdref + shift; # run_command + $config = shift; + shift; # root config + + return $self; +} + +sub on_001 { + my ($self, $logger, $server, $message, $irc) = @_; + $irc->yield(join => $_) for @{$config->{channels}}; + return; +} +1; diff --git a/Plugin/Log.pm b/Plugin/Log.pm index 1d69e51..135cd85 100644 --- a/Plugin/Log.pm +++ b/Plugin/Log.pm @@ -14,6 +14,7 @@ my %t = ( nick => color("cyan"), info => color("yellow"), kick => color("red"), + host => color("magenta"), channel => color("blue"), message => color("reset"), misc => color("bright_black"), @@ -33,7 +34,7 @@ sub configure { # FIXME Not triggered yet sub on_001 { my ($self, $logger, $server, $message, $irc) = @_; - $logger->("$t{info}Connected to ${host}$server$t{info} --- \"$t{message}$message$t{info}\"$t{reset}"); + $logger->("$t{info}Connected to $t{host}$server$t{info} --- \"$t{message}$message$t{info}\"$t{reset}"); } sub on_message { diff --git a/bot.conf.example b/bot.conf.example index 143ad4c..4dba20b 100644 --- a/bot.conf.example +++ b/bot.conf.example @@ -1,4 +1,4 @@ -plugins = [ Plugin::Titillate, Plugin::Admin, Plugin::Ping ] +plugins = [ Plugin::Autojoin, Plugin::Titillate, Plugin::Admin, Plugin::Ping ] nick = somebot username = bot ircname = a bot @@ -7,7 +7,6 @@ port = 6667 usessl = 1 sslcert = foo.crt sslkey = foo.key -channels = [ #saxtalk, #bot] ignore = [trumpetbot, abusiveuser] password = pleffquiffle user = nobody @@ -16,6 +15,9 @@ prefix_nick = 1 prefix = % log_debug = 0 +[Plugin::Autojoin] +channels = [ #saxtalk, #bot ] + [Plugin::Admin] admins = [ snargle!~kleg@glarg.example.com ] must_id = 1 diff --git a/idalius.pl b/idalius.pl index fcddc13..fec0d24 100755 --- a/idalius.pl +++ b/idalius.pl @@ -312,13 +312,13 @@ sub _start { } sub irc_001 { - my ($irc, $sender) = @_[KERNEL, SENDER]; - my $heap = $sender->get_heap(); + my ($poek, $server, $message) = @_[KERNEL, ARG0, ARG1]; + my @empty = (); - log_info("Connected to server ", $heap->server_name()); + trigger_modules("001", undef, undef, \@empty, ($server, $message)); - $heap->yield(join => $_) for @{$config->{_}->{channels}}; - $irc->delay(custom_ping => $ping_delay); + # FIXME move to forward ping module + $poek->delay(custom_ping => $ping_delay); return; } -- cgit v1.1