aboutsummaryrefslogtreecommitdiff
path: root/idalius.pl
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-09-03 16:14:22 +1200
committerDavid Phillips <david@sighup.nz>2018-09-03 16:14:22 +1200
commit65694d185582c9a6558ea8bfee99e56a5721540b (patch)
tree9d6d3da4dd8eb15daff1c645b02cd84d123548e8 /idalius.pl
parent14c1d55b97d61de7eb48acd4a5b745e2ba5e977a (diff)
downloadidalius-65694d185582c9a6558ea8bfee99e56a5721540b.tar.xz
Configurable modules
Diffstat (limited to 'idalius.pl')
-rwxr-xr-xidalius.pl40
1 files changed, 27 insertions, 13 deletions
diff --git a/idalius.pl b/idalius.pl
index 8db549f..d1cd12e 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -9,15 +9,32 @@ use POE::Component::IRC;
use POE::Component::IRC::Plugin::NickServID;
use config_file;
use IRC::Utils qw(strip_color strip_formatting);
-use Module::Pluggable search_path => "Plugin", instantiate => 'configure';
my $config_file = "bot.conf";
my %config = config_file::parse_config($config_file);
my %laststrike = ();
my $ping_delay = 300;
-
my %commands = ();
+sub log_info {
+ # FIXME direct to a log file instead of stdout
+ my $stamp = strftime("%Y-%m-%d %H:%M:%S %z", localtime);
+ print "$stamp | @_\n";
+}
+
+eval {
+ for my $module (@{$config{plugins}}) {
+ log_info "Loading $module";
+ (my $path = $module) =~ s,::,/,g;
+ require $path . ".pm";
+ $module->configure(\&register_command, \%config, \&run_command);
+ }
+ 1;
+} or do {
+ log_info "Error: failed to load module: $@";
+};
+
+
$| = 1;
my $current_nick = $config{nick};
@@ -26,8 +43,6 @@ my $current_nick = $config{nick};
+$config{url_on};
+$config{url_len};
-my @plugin_list = plugins("dummy", \&register_command, \%config, \&run_command);
-
# New PoCo-IRC object
my $irc = POE::Component::IRC->spawn(
UseSSL => $config{usessl},
@@ -71,10 +86,10 @@ drop_priv();
$poe_kernel->run();
-sub log_info {
- # FIXME direct to a log file instead of stdout
- my $stamp = strftime("%Y-%m-%d %H:%M:%S %z", localtime);
- print "$stamp | @_\n";
+sub module_is_enabled {
+ my $module = $_[0];
+
+ return grep {$_ eq $module} @{$config{plugins}};
}
# Register a command name to a certain sub
@@ -198,13 +213,12 @@ sub irc_public {
strike_add($nick, $channel) if $output;
}
- for my $module (@plugin_list) {
- $output = "";
- if ($module->can("message")) {
+ for my $module (@{$config{plugins}}) {
+ if (module_is_enabled($module) && $module->can("message")) {
$output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what, $irc);
+ $irc->yield(privmsg => $where => $output) if $output;
+ strike_add($nick, $channel) if $output;
}
- $irc->yield(privmsg => $where => $output) if $output;
- strike_add($nick, $channel) if $output;
}
return;