diff options
author | David Phillips <david@sighup.nz> | 2018-09-10 19:37:46 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2018-09-10 19:37:46 +1200 |
commit | 1c5caa91047e8291fd7cb01f1b45decc993f49d9 (patch) | |
tree | 34d0e88a721e8e7927a682aa02ffeed61ea42e78 | |
parent | ade3c69f9e307f27d789d4a3f5009230a56d554b (diff) | |
download | idalius-1c5caa91047e8291fd7cb01f1b45decc993f49d9.tar.xz |
Separate handling of message and action
-rwxr-xr-x | idalius.pl | 49 |
1 files changed, 34 insertions, 15 deletions
@@ -153,6 +153,10 @@ sub strike_add { } } +sub should_ignore { + return grep @{$config{ignore}}; +} + sub _start { my $heap = $_[HEAP]; my $irc = $heap->{irc}; @@ -191,32 +195,27 @@ sub irc_kick { return; } -sub irc_ctcp_action { - irc_public(@_); -} - -sub irc_public { - my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2]; - my $nick = ( split /!/, $who )[0]; +sub handle_common { + my ($message_type, $who, $where, $what) = @_; + 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}}); + # Return early if should ignore + return if should_ignore($nick); my $stripped_what = strip_color(strip_formatting($what)); + my $no_prefix_what = $stripped_what; if ($config{prefix_nick} && $stripped_what =~ s/^\Q$current_nick\E[:,]\s+//g || - $stripped_what =~ s/^$config{prefix}//) { - $output = run_command($stripped_what, $who, $where); + $no_prefix_what =~ s/^$config{prefix}//) { + $output = run_command($no_prefix_what, $who, $where); $irc->yield(privmsg => $where => $output) if $output; strike_add($nick, $channel) if $output; } 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); + if (module_is_enabled($module) && $module->can($message_type)) { + $output = $module->$message_type(\&log_info, $irc->nick_name, $who, $where, $what, $stripped_what, $irc); $irc->yield(privmsg => $where => $output) if $output; strike_add($nick, $channel) if $output; } @@ -225,6 +224,26 @@ sub irc_public { return; } +sub irc_ctcp_action { + my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2]; + my $nick = ( split /!/, $who )[0]; + my $channel = $where->[0]; + + log_info("[$channel] [action] $who $what"); + + return handle_common("action", $who, $where, $what); +} + +sub irc_public { + my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2]; + my $nick = ( split /!/, $who )[0]; + my $channel = $where->[0]; + + log_info("[$channel] $who: $what"); + + return handle_common("message", $who, $where, $what); +} + sub irc_msg { my ($who, $to, $what, $ided) = @_[ARG0 .. ARG3]; my $nick = (split /!/, $who)[0]; |