aboutsummaryrefslogtreecommitdiff
path: root/idalius.pl
diff options
context:
space:
mode:
Diffstat (limited to 'idalius.pl')
-rwxr-xr-xidalius.pl33
1 files changed, 18 insertions, 15 deletions
diff --git a/idalius.pl b/idalius.pl
index 690d5a7..627d91f 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -8,6 +8,7 @@ use POE::Kernel;
use POE::Component::IRC;
use POE::Component::IRC::Plugin::NickServID;
use IdaliusConfig;
+use Plugin qw/load_plugin/;
use IRC::Utils qw(strip_color strip_formatting);
my $config_file = "bot.conf";
@@ -24,9 +25,7 @@ sub log_info {
eval {
for my $module (@{$config->{_}->{plugins}}) {
- log_info "Loading $module";
- (my $path = $module) =~ s,::,/,g;
- require $path . ".pm";
+ Plugin::load_plugin(\&log_info, $config->{_}, $module);
$module->configure(
\&register_command,
\&run_command,
@@ -39,7 +38,6 @@ eval {
die;
};
-
$| = 1;
my $current_nick = $config->{_}->{nick};
@@ -90,27 +88,32 @@ $poe_kernel->run();
sub module_is_enabled {
my $module = $_[0];
- return grep {$_ eq $module} @{$config->{_}->{plugins}};
+ return grep {$_ eq $module} @{$config->{_}->{active_plugins}};
}
# Register a command name to a certain sub
sub register_command {
- my ($command, $action) = @_;
+ my ($owner, $command, $action) = @_;
$command = lc $command;
- log_info "Registering command: $command";
- $commands{$command} = $action;
+ log_info "Registering command: $command (from $owner)";
+ $commands{$owner}{$command} = $action;
}
sub run_command {
my ($command_string, $who, $where, $ided) = @_;
my @arguments;
+ my $owner;
my $command_verbatim;
my $command;
- for my $c (keys %commands) {
- if (($command_verbatim) = $command_string =~ m/^(\Q$c\E( |$))/i) {
- $command = lc $c;
- last;
+ OUTER: for my $o (keys %commands) {
+ next unless module_is_enabled($o);
+ for my $c (keys %{$commands{$o}}) {
+ if (($command_verbatim) = $command_string =~ m/^(\Q$c\E( |$))/i) {
+ $command = lc $c;
+ $owner = $o;
+ last OUTER;
+ }
}
}
@@ -119,9 +122,9 @@ sub run_command {
my $rest = (split "\Q$command_verbatim", $command_string, 2)[1];
@arguments = split /\s+/, $rest if $rest;
- return ($commands{$command})->($irc, \&log_info, $who, $where, $ided, $rest, @arguments);
+ my $action = $commands{$owner}{$command};
+ return $action->($irc, \&log_info, $who, $where, $ided, $rest, @arguments);
}
-
sub custom_ping {
my ($irc, $heap) = @_[KERNEL, HEAP];
$irc->yield(userhost => $current_nick);
@@ -217,7 +220,7 @@ sub handle_common {
# handler names are defined as being prefixed with on_
$message_type = "on_$message_type";
my $ignore_suffix = "_yes_really_even_from_ignored_nicks";
- for my $module (@{$config->{_}->{plugins}}) {
+ for my $module (@{$config->{_}->{active_plugins}}) {
if (module_is_enabled($module)) {
if (!should_ignore($nick) and $module->can($message_type)) {
# Leave message type unchanged