mirror of
https://github.com/pragma-/pbot.git
synced 2025-10-13 22:47:26 +02:00
Core/Interpreter: simplify ref_from
This commit is contained in:
parent
d5aa7f9e41
commit
8fdd51bc9a
@ -207,7 +207,8 @@ sub interpreter($self, $context) {
|
|||||||
if (gettimeofday - $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
|
if (gettimeofday - $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
|
||||||
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : '';
|
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : '';
|
||||||
|
|
||||||
unless ($self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}")) {
|
unless ($self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}")
|
||||||
|
|| $self->{pbot}->{users}->get_user_metadata($channel, "$context->{nick}!$context->{user}\@$context->{host}", 'is-whitelisted')) {
|
||||||
return "/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
|
return "/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
|
||||||
. duration($ratelimit - int(gettimeofday - $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'last_referenced_on'))) . "."
|
. duration($ratelimit - int(gettimeofday - $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'last_referenced_on'))) . "."
|
||||||
}
|
}
|
||||||
@ -298,12 +299,6 @@ sub handle_action($self, $context, $action) {
|
|||||||
|
|
||||||
my ($channel_name, $trigger_name) = ($context->{channel_name}, $context->{trigger_name});
|
my ($channel_name, $trigger_name) = ($context->{channel_name}, $context->{trigger_name});
|
||||||
|
|
||||||
my $ref_from = '';
|
|
||||||
|
|
||||||
unless ($context->{no_ref_from} or $context->{pipe} or $context->{subcmd}) {
|
|
||||||
$ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
my $interpolate = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'interpolate');
|
my $interpolate = $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'interpolate');
|
||||||
|
|
||||||
if (defined $interpolate and not $interpolate) {
|
if (defined $interpolate and not $interpolate) {
|
||||||
@ -383,7 +378,7 @@ sub handle_action($self, $context, $action) {
|
|||||||
|
|
||||||
if (defined $enabled and $enabled == 0) {
|
if (defined $enabled and $enabled == 0) {
|
||||||
$self->{pbot}->{logger}->log("$trigger_name disabled.\n");
|
$self->{pbot}->{logger}->log("$trigger_name disabled.\n");
|
||||||
return "${ref_from}$trigger_name is disabled.";
|
return "$trigger_name is disabled.";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check if it's an alias
|
# Check if it's an alias
|
||||||
@ -466,13 +461,7 @@ sub handle_action($self, $context, $action) {
|
|||||||
$context->{root_keyword} = $keyword unless defined $context->{root_keyword};
|
$context->{root_keyword} = $keyword unless defined $context->{root_keyword};
|
||||||
$context->{root_channel} = $channel;
|
$context->{root_channel} = $channel;
|
||||||
|
|
||||||
my $result = $self->{pbot}->{applets}->execute_applet($context);
|
return $self->{pbot}->{applets}->execute_applet($context);
|
||||||
|
|
||||||
if (defined $result && length $result) {
|
|
||||||
return $ref_from . $result;
|
|
||||||
} else {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
elsif ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'type') eq 'text') {
|
elsif ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'type') eq 'text') {
|
||||||
# Don't allow user-custom /msg factoids, unless invoked by admin
|
# Don't allow user-custom /msg factoids, unless invoked by admin
|
||||||
@ -483,21 +472,10 @@ sub handle_action($self, $context, $action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ref_from) {
|
if ($action =~ m/^\/(?:say|me|msg)/i) {
|
||||||
if ( $action =~ s/^\/say\s+/$ref_from/i
|
return $action;
|
||||||
|| $action =~ s/^\/me\s+(.*)/\/me $1 $ref_from/i
|
|
||||||
|| $action =~ s/^\/msg\s+([^ ]+)/\/msg $1 $ref_from/i
|
|
||||||
) {
|
|
||||||
return $action;
|
|
||||||
} else {
|
|
||||||
return $ref_from . "$trigger_name is $action";
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if ($action =~ m/^\/(?:say|me|msg)/i) {
|
return "/say $trigger_name is $action";
|
||||||
return $action;
|
|
||||||
} else {
|
|
||||||
return "/say $trigger_name is $action";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elsif ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'type') eq 'regex') {
|
elsif ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'type') eq 'regex') {
|
||||||
@ -536,13 +514,13 @@ sub handle_action($self, $context, $action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (length $result) {
|
if (length $result) {
|
||||||
return $ref_from . $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$self->{pbot}->{logger}->log("$context->{from}: $context->{nick}!$context->{user}\@$context->{host}): bad type for $channel.$keyword\n");
|
$self->{pbot}->{logger}->log("$context->{from}: $context->{nick}!$context->{user}\@$context->{host}): bad type for $channel.$keyword\n");
|
||||||
return "/me blinks. $ref_from";
|
return '/me blinks.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -449,7 +449,7 @@ sub interpret($self, $context) {
|
|||||||
# replace it with a placeholder
|
# replace it with a placeholder
|
||||||
$arguments =~ s/&\s*\{\Q$command\E\}/&{subcmd}/;
|
$arguments =~ s/&\s*\{\Q$command\E\}/&{subcmd}/;
|
||||||
|
|
||||||
# add it to the list of substituted commands
|
# add it to the command stack
|
||||||
push @{$context->{cmdstack}}, "$keyword $arguments";
|
push @{$context->{cmdstack}}, "$keyword $arguments";
|
||||||
|
|
||||||
# add output queue to stack
|
# add output queue to stack
|
||||||
@ -674,6 +674,11 @@ sub handle_result($self, $context, $result = $context->{result}) {
|
|||||||
$command =~ s/&\{subcmd\}/$result/;
|
$command =~ s/&\{subcmd\}/$result/;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if ($context->{result_prefix}) {
|
||||||
|
$result = "$context->{result_prefix} $result";
|
||||||
|
}
|
||||||
|
|
||||||
|
# append output to queue
|
||||||
push @{$context->{outq}->[$#{$context->{outq}}]}, $result;
|
push @{$context->{outq}->[$#{$context->{outq}}]}, $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -693,18 +698,18 @@ sub handle_result($self, $context, $result = $context->{result}) {
|
|||||||
|
|
||||||
# join output queue
|
# join output queue
|
||||||
if (exists $context->{outq}) {
|
if (exists $context->{outq}) {
|
||||||
|
my $botnick = $self->{pbot}->{conn}->nick;
|
||||||
|
|
||||||
while (my $outq = pop @{$context->{outq}}) {
|
while (my $outq = pop @{$context->{outq}}) {
|
||||||
$outq = join " ", @$outq;
|
$outq = join ' ', @$outq;
|
||||||
|
|
||||||
# reformat result to be more suitable for joining together
|
# reformat result to be more suitable for joining together
|
||||||
my $botnick = $self->{pbot}->{conn}->nick;
|
$result =~ s!^/say ! !i
|
||||||
$result =~ s!^/say !\n!i
|
|| $result =~ s!^/me ! * $botnick !i
|
||||||
|| $result =~ s!^/me !\n * $botnick !i
|
|| $result =~ s!^! !;
|
||||||
|| $result =~ s!^!\n!;
|
|
||||||
|
|
||||||
$result = "$outq$result";
|
$result = "$outq$result";
|
||||||
$result =~ s/^\n+//;
|
$result =~ s/^ +//;
|
||||||
}
|
}
|
||||||
delete $context->{outq};
|
delete $context->{outq};
|
||||||
}
|
}
|
||||||
@ -945,6 +950,11 @@ sub output_result($self, $context) {
|
|||||||
my $bot_account = $self->{pbot}->{messagehistory}->get_message_account($bot_nick, 'pbot3', 'pbot');
|
my $bot_account = $self->{pbot}->{messagehistory}->get_message_account($bot_nick, 'pbot3', 'pbot');
|
||||||
|
|
||||||
if ($type eq 'echo') {
|
if ($type eq 'echo') {
|
||||||
|
# prepend ref_from to output
|
||||||
|
if ($context->{ref_from}) {
|
||||||
|
$output = "[$context->{ref_from}] $output";
|
||||||
|
}
|
||||||
|
|
||||||
# prepend nickprefix to output
|
# prepend nickprefix to output
|
||||||
if ($context->{nickprefix} && (! $context->{nickprefix_disabled} || $context->{nickprefix_forced})) {
|
if ($context->{nickprefix} && (! $context->{nickprefix_disabled} || $context->{nickprefix_forced})) {
|
||||||
$output = "$context->{nickprefix}: $output";
|
$output = "$context->{nickprefix}: $output";
|
||||||
@ -965,6 +975,11 @@ sub output_result($self, $context) {
|
|||||||
$self->{pbot}->{conn}->privmsg($to, $output);
|
$self->{pbot}->{conn}->privmsg($to, $output);
|
||||||
}
|
}
|
||||||
elsif ($type eq 'action') {
|
elsif ($type eq 'action') {
|
||||||
|
# append ref_from to output
|
||||||
|
if ($context->{ref_from}) {
|
||||||
|
$output = "$output [$context->{ref_from}]";
|
||||||
|
}
|
||||||
|
|
||||||
# truncate if necessary, pasting original result to a web paste site
|
# truncate if necessary, pasting original result to a web paste site
|
||||||
$output = $self->truncate_result($context, $output, $context->{original_result});
|
$output = $self->truncate_result($context, $output, $context->{original_result});
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ use PBot::Imports;
|
|||||||
# These are set by the /misc/update_version script
|
# These are set by the /misc/update_version script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 4879,
|
BUILD_REVISION => 4880,
|
||||||
BUILD_DATE => "2025-07-29",
|
BUILD_DATE => "2025-07-30",
|
||||||
};
|
};
|
||||||
|
|
||||||
sub initialize {}
|
sub initialize {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user