aboutsummaryrefslogtreecommitdiff
path: root/idalius.pl
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2018-04-10 15:06:10 +1200
committerDavid Phillips <david@sighup.nz>2018-04-10 15:06:29 +1200
commitbb1808b1ef92af9a14a073f2e14973ac132b7e7e (patch)
tree5cf3fb9174e07242ed258ae327d3506df1a5355c /idalius.pl
parent5aad7b27d5145d4f459ab36d3ffe4a576d3f4ea6 (diff)
downloadidalius-bb1808b1ef92af9a14a073f2e14973ac132b7e7e.tar.xz
Add command modules, map command
Diffstat (limited to 'idalius.pl')
-rwxr-xr-xidalius.pl37
1 files changed, 34 insertions, 3 deletions
diff --git a/idalius.pl b/idalius.pl
index 077e5ba..0e01e32 100755
--- a/idalius.pl
+++ b/idalius.pl
@@ -16,6 +16,8 @@ my %config = config_file::parse_config($config_file);
my %laststrike = ();
my $ping_delay = 300;
+my %commands = ();
+
$| = 1;
my $current_nick = $config{nick};
@@ -24,7 +26,7 @@ my $current_nick = $config{nick};
+$config{url_on};
+$config{url_len};
-my @plugin_list = plugins("dummy", \%config);
+my @plugin_list = plugins("dummy", \&register_command, \%config, \&run_command);
# New PoCo-IRC object
my $irc = POE::Component::IRC->spawn(
@@ -67,6 +69,26 @@ drop_priv();
$poe_kernel->run();
+
+# Register a command name to a certain sub
+sub register_command {
+ my ($command, $action) = @_;
+ print ("registering $command to $action\n");
+ $commands{$command} = $action;
+}
+
+sub run_command {
+ my ($command_string, $who, $where) = @_;
+ my @arguments;
+ my ($command, $rest) = split /\s+/, $command_string, 2;
+ @arguments = split /\s+/, $rest if $rest;
+ if ($commands{$command}) {
+ return ($commands{$command})->(\&log_info, $who, $where, $rest, @arguments);
+ } else {
+ return "No such command \"$command\"";
+ }
+}
+
sub custom_ping {
my ($irc, $heap) = @_[KERNEL, HEAP];
$irc->yield(userhost => $current_nick);
@@ -149,15 +171,24 @@ sub irc_public {
my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2];
my $nick = ( split /!/, $who )[0];
my $channel = $where->[0];
+ my $output;
log_info("[$channel] $who: $what");
# reject ignored nicks first
return if (grep {$_ eq $nick} @{$config{ignore}});
+ my $stripped_what = strip_color(strip_formatting($what));
+ if ($stripped_what =~ s/^$config{prefix}//) {
+ $output = run_command($stripped_what, $who, $where);
+ $irc->yield(privmsg => $where => $output) if $output;
+ }
+
for my $module (@plugin_list) {
- my $stripped_what = strip_color(strip_formatting($what));
- my $output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what, $irc);
+ $output = "";
+ if ($module->can("message")) {
+ $output = $module->message(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what, $irc);
+ }
strike_add $nick if $output;
$irc->yield(privmsg => $where => $output) if $output;
}