From bb1808b1ef92af9a14a073f2e14973ac132b7e7e Mon Sep 17 00:00:00 2001 From: David Phillips Date: Tue, 10 Apr 2018 15:06:10 +1200 Subject: Add command modules, map command --- idalius.pl | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'idalius.pl') 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", \®ister_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; } -- cgit v1.1