3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-27 06:19:25 +01:00

Refactor code-factoid execution a little bit

This commit is contained in:
Pragmatic Software 2017-08-27 04:18:31 -07:00
parent 73bc7cebe4
commit 75c6375339

View File

@ -710,23 +710,22 @@ sub interpreter {
$self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_on} = gettimeofday;
$self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin"; $self->{factoids}->hash->{$channel}->{$keyword}->{last_referenced_in} = $from || "stdin";
my $action = $self->{factoids}->hash->{$channel}->{$keyword}->{action}; my $action;
if (length $arguments and exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args}) {
$action = $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args};
} else {
$action = $self->{factoids}->hash->{$channel}->{$keyword}->{action};
}
if ($action =~ m/^\{\s*(.*)\s*\}$/) { if ($action =~ m/^\{\s*(.*)\s*\}$/) {
my $code = $1; my $code = $1;
$action = $self->execute_code_factoid($nick, $from, $channel, $root_keyword, $keyword, $arguments, $code, $tonick); $action = $self->execute_code_factoid($nick, $from, $channel, $root_keyword, $keyword, $arguments, $code, $tonick);
} }
return "" if not length $action;
if (length $arguments) { if (length $arguments) {
if(exists $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args}) {
$action = $self->{factoids}->hash->{$channel}->{$keyword}->{action_with_args};
}
if ($action =~ m/^\{\s*(.*)\s*\}$/) {
my $code = $1;
$action = $self->execute_code_factoid($nick, $from, $channel, $root_keyword, $keyword, $arguments, $code, $tonick);
}
if ($action =~ m/\$args/ or $action =~ m/\$arg\[/) { if ($action =~ m/\$args/ or $action =~ m/\$arg\[/) {
$action = $self->expand_action_arguments($action, $arguments, defined $tonick ? $tonick : $nick); $action = $self->expand_action_arguments($action, $arguments, defined $tonick ? $tonick : $nick);
$arguments = ""; $arguments = "";
@ -758,12 +757,8 @@ sub interpreter {
} }
} }
} else { } else {
# no arguments supplied # no arguments supplied, replace $args with $nick/$tonick, etc
if(defined $tonick) { $action = $self->expand_action_arguments($action, undef, $tonick ? $tonick : $nick);
$action = $self->expand_action_arguments($action, undef, $tonick);
} else {
$action = $self->expand_action_arguments($action, undef, $nick);
}
} }
# Check if it's an alias # Check if it's an alias
@ -803,8 +798,6 @@ sub interpreter {
return "/msg $nick $ref_from$keyword is currently disabled."; return "/msg $nick $ref_from$keyword is currently disabled.";
} }
return "" if not length $action;
$action =~ s/\$nick/$nick/g; $action =~ s/\$nick/$nick/g;
$action =~ s/\$channel/$from/g; $action =~ s/\$channel/$from/g;
$action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge; $action =~ s/\$randomnick/my $random = $self->{pbot}->{nicklist}->random_nick($from); $random ? $random : $nick/ge;