3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-08-03 11:17:23 +02:00

Core/Interpreter: simplify ref_from

This commit is contained in:
Pragmatic Software 2025-07-30 15:51:09 -07:00
parent d5aa7f9e41
commit 8fdd51bc9a
No known key found for this signature in database
GPG Key ID: CC916B6E3C84ECCE
3 changed files with 33 additions and 40 deletions

View File

@ -207,7 +207,8 @@ sub interpreter($self, $context) {
if (gettimeofday - $self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
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 "
. 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 $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');
if (defined $interpolate and not $interpolate) {
@ -383,7 +378,7 @@ sub handle_action($self, $context, $action) {
if (defined $enabled and $enabled == 0) {
$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
@ -466,13 +461,7 @@ sub handle_action($self, $context, $action) {
$context->{root_keyword} = $keyword unless defined $context->{root_keyword};
$context->{root_channel} = $channel;
my $result = $self->{pbot}->{applets}->execute_applet($context);
if (defined $result && length $result) {
return $ref_from . $result;
} else {
return $result;
}
return $self->{pbot}->{applets}->execute_applet($context);
}
elsif ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'type') eq 'text') {
# 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 =~ s/^\/say\s+/$ref_from/i
|| $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";
}
if ($action =~ m/^\/(?:say|me|msg)/i) {
return $action;
} else {
if ($action =~ m/^\/(?:say|me|msg)/i) {
return $action;
} else {
return "/say $trigger_name is $action";
}
return "/say $trigger_name is $action";
}
}
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) {
return $ref_from . $result;
return $result;
} else {
return '';
}
} else {
$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.';
}
}

View File

@ -449,7 +449,7 @@ sub interpret($self, $context) {
# replace it with a placeholder
$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";
# add output queue to stack
@ -674,6 +674,11 @@ sub handle_result($self, $context, $result = $context->{result}) {
$command =~ s/&\{subcmd\}/$result/;
}
} else {
if ($context->{result_prefix}) {
$result = "$context->{result_prefix} $result";
}
# append output to queue
push @{$context->{outq}->[$#{$context->{outq}}]}, $result;
}
@ -693,18 +698,18 @@ sub handle_result($self, $context, $result = $context->{result}) {
# join output queue
if (exists $context->{outq}) {
my $botnick = $self->{pbot}->{conn}->nick;
while (my $outq = pop @{$context->{outq}}) {
$outq = join " ", @$outq;
$outq = join ' ', @$outq;
# reformat result to be more suitable for joining together
my $botnick = $self->{pbot}->{conn}->nick;
$result =~ s!^/say !\n!i
|| $result =~ s!^/me !\n * $botnick !i
|| $result =~ s!^!\n!;
$result =~ s!^/say ! !i
|| $result =~ s!^/me ! * $botnick !i
|| $result =~ s!^! !;
$result = "$outq$result";
$result =~ s/^\n+//;
$result =~ s/^ +//;
}
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');
if ($type eq 'echo') {
# prepend ref_from to output
if ($context->{ref_from}) {
$output = "[$context->{ref_from}] $output";
}
# prepend nickprefix to output
if ($context->{nickprefix} && (! $context->{nickprefix_disabled} || $context->{nickprefix_forced})) {
$output = "$context->{nickprefix}: $output";
@ -965,6 +975,11 @@ sub output_result($self, $context) {
$self->{pbot}->{conn}->privmsg($to, $output);
}
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
$output = $self->truncate_result($context, $output, $context->{original_result});

View File

@ -25,8 +25,8 @@ use PBot::Imports;
# These are set by the /misc/update_version script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 4879,
BUILD_DATE => "2025-07-29",
BUILD_REVISION => 4880,
BUILD_DATE => "2025-07-30",
};
sub initialize {}