mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-22 18:14:48 +01:00
Remove add_nick
mess from ProcessManager
This commit is contained in:
parent
8cff244256
commit
59140d4096
@ -97,7 +97,7 @@ sub get_meta {
|
||||
}
|
||||
|
||||
# main entry point for PBot::Core::Interpreter to interpret a registered bot command
|
||||
# see also PBot::Core::Factoids::interpreter() for factoid commands
|
||||
# see also PBot::Core::Factoids::Interpreter for factoid commands
|
||||
sub interpreter {
|
||||
my ($self, $context) = @_;
|
||||
|
||||
@ -168,6 +168,11 @@ sub interpreter {
|
||||
$context->{preserve_whitespace} = 1;
|
||||
}
|
||||
|
||||
# tell PBot::Core::Interpreter to prepend caller's nick to output
|
||||
if ($self->get_meta($keyword, 'add_nick')) {
|
||||
$context->{add_nick} = 1;
|
||||
}
|
||||
|
||||
unless ($self->get_meta($keyword, 'dont-replace-pronouns')) {
|
||||
$context->{arguments} = $self->{pbot}->{factoids}->{variables}->expand_factoid_vars($context, $context->{arguments});
|
||||
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($context->{arguments});
|
||||
|
@ -219,6 +219,11 @@ sub interpreter {
|
||||
return $usage;
|
||||
}
|
||||
|
||||
# tell PBot::Core::Interpreter to prepend caller's nick to output
|
||||
if ($self->{pbot}->{factoids}->{data}->{storage}->get_data($channel, $keyword, 'add_nick')) {
|
||||
$context->{add_nick} = 1;
|
||||
}
|
||||
|
||||
# factoid action
|
||||
my $action;
|
||||
|
||||
|
@ -890,15 +890,21 @@ sub output_result {
|
||||
if ($context->{nickprefix} && (! $context->{nickprefix_disabled} || $context->{nickprefix_forced})) {
|
||||
$output = "$context->{nickprefix}: $output";
|
||||
}
|
||||
elsif ($context->{add_nick}) {
|
||||
$output = "$context->{nick}: $output";
|
||||
}
|
||||
|
||||
# send the message to the channel/user
|
||||
$self->{pbot}->{conn}->privmsg($to, $output);
|
||||
}
|
||||
elsif ($type eq 'action') {
|
||||
# append nickprefix to output
|
||||
if ($context->{nickprefix} && (! $context->{nickprefix_disabled} || $context->{nickprefix_forced})) {
|
||||
$output = "$output (for $context->{nickprefix})";
|
||||
}
|
||||
#
|
||||
# TODO: probably going to remove this code.
|
||||
#
|
||||
# if ($context->{nickprefix} && (! $context->{nickprefix_disabled} || $context->{nickprefix_forced})) {
|
||||
# $output = "$output (for $context->{nickprefix})";
|
||||
# }
|
||||
|
||||
# CTCP ACTION the message to the channel/user
|
||||
$self->{pbot}->{conn}->me($to, $output);
|
||||
|
@ -109,7 +109,7 @@ sub execute_process {
|
||||
|
||||
# execute the provided subroutine, results are stored in $context
|
||||
eval {
|
||||
local $SIG{ALRM} = sub { die "Process `$context->{commands}->[0]` timed-out" };
|
||||
local $SIG{ALRM} = sub { die "Process `$context->{commands}->[0]` timed-out\n" };
|
||||
alarm $timeout;
|
||||
$subref->($context);
|
||||
alarm 0;
|
||||
@ -119,13 +119,9 @@ sub execute_process {
|
||||
if ($@) {
|
||||
$context->{result} = $@;
|
||||
|
||||
$context->{'timed-out'} = 1 if $context->{result} =~ /^Process .* timed-out at PBot\/ProcessManager/;
|
||||
$context->{'timed-out'} = 1 if $context->{result} =~ /^Process .* timed-out/;
|
||||
|
||||
$self->{pbot}->{logger}->log("Error executing process: $context->{result}\n");
|
||||
|
||||
# strip internal PBot source data for IRC output
|
||||
$context->{result} =~ s/ at PBot.*$//ms;
|
||||
$context->{result} =~ s/\s+...propagated at .*$//ms;
|
||||
}
|
||||
|
||||
# print $context to pipe
|
||||
@ -189,42 +185,6 @@ sub process_pipe_reader {
|
||||
$context->{result} = $self->{pbot}->{factoids}->{interpreter}->handle_action($context, $context->{result});
|
||||
}
|
||||
|
||||
# if nick isn't overridden yet, check for a potential nick prefix
|
||||
# TODO: this stuff should be moved to Interpreter::output_result
|
||||
if (not $context->{nickprefix}) {
|
||||
$context->{trigger} //= '';
|
||||
|
||||
# if add_nick is set on the factoid, set the nick override to the caller's nick
|
||||
if (exists $context->{special} and $context->{special} ne 'code-factoid'
|
||||
and $self->{pbot}->{factoids}->{data}->{storage}->exists($context->{channel}, $context->{trigger}, 'add_nick')
|
||||
and $self->{pbot}->{factoids}->{data}->{storage}->get_data($context->{channel}, $context->{trigger}, 'add_nick') != 0)
|
||||
{
|
||||
$context->{nickprefix} = $context->{nick};
|
||||
$context->{nickprefix_disabled} = 0;
|
||||
$context->{nickprefix_forced} = 1;
|
||||
} else {
|
||||
# extract nick-like thing from process result
|
||||
if ($context->{result} =~ s/^(\S+): //) {
|
||||
my $nick = $1;
|
||||
|
||||
if (lc $nick eq "usage") {
|
||||
# put it back on result if it's a usage message
|
||||
$context->{result} = "$nick: $context->{result}";
|
||||
} else {
|
||||
my $present = $self->{pbot}->{nicklist}->is_present($context->{channel}, $nick);
|
||||
|
||||
if ($present) {
|
||||
# nick is present in channel
|
||||
$context->{nickprefix} = $present;
|
||||
} else {
|
||||
# nick not present, put it back on result
|
||||
$context->{result} = "$nick: $context->{result}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# send the result off to the bot to be handled
|
||||
$context->{checkflood} = 1;
|
||||
$self->{pbot}->{interpreter}->handle_result($context);
|
||||
|
@ -22,7 +22,7 @@ package PBot::VERSION;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4318,
|
||||
BUILD_REVISION => 4319,
|
||||
BUILD_DATE => "2021-07-27",
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user