mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-25 04:02:37 +01:00
Improve nickoverride processing
This commit is contained in:
parent
98d10b6ccd
commit
78a12b3a46
@ -206,17 +206,31 @@ sub module_pipe_reader {
|
|||||||
$stuff->{checkflood} = 0;
|
$stuff->{checkflood} = 0;
|
||||||
|
|
||||||
if (defined $stuff->{nickoverride}) {
|
if (defined $stuff->{nickoverride}) {
|
||||||
$self->{pbot}->{logger}->log("($stuff->{from}): $stuff->{nick}!$stuff->{user}\@$stuff->{host}) sent to $stuff->{nickoverride}\n");
|
$self->{pbot}->{interpreter}->handle_result($stuff, $stuff->{result});
|
||||||
# get rid of original caller's nick
|
|
||||||
$stuff->{result} =~ s/^\/([^ ]+) \Q$stuff->{nick}\E:\s+/\/$1 /;
|
|
||||||
$stuff->{result} =~ s/^\Q$stuff->{nick}\E:\s+//;
|
|
||||||
$self->{pbot}->{interpreter}->handle_result($stuff, "$stuff->{nickoverride}: $stuff->{result}");
|
|
||||||
} else {
|
} else {
|
||||||
|
# don't override nick if already set
|
||||||
if ($stuff->{command} ne 'code-factoid' and exists $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} and $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} != 0) {
|
if ($stuff->{command} ne 'code-factoid' and exists $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} and $self->{pbot}->{factoids}->{factoids}->hash->{$stuff->{channel}}->{$stuff->{trigger}}->{add_nick} != 0) {
|
||||||
$self->{pbot}->{interpreter}->handle_result($stuff, "$stuff->{nick}: $stuff->{result}");
|
$stuff->{nickoverride} = $stuff->{nick};
|
||||||
} else {
|
} else {
|
||||||
$self->{pbot}->{interpreter}->handle_result($stuff, $stuff->{result});
|
# extract nick-like thing from module result
|
||||||
|
if ($stuff->{result} =~ s/^(\S+): //) {
|
||||||
|
my $nick = $1;
|
||||||
|
if (lc $nick eq "usage") {
|
||||||
|
# put it back on result if it's a usage message
|
||||||
|
$stuff->{result} = "$nick: $stuff->{result}";
|
||||||
|
} else {
|
||||||
|
my $present = $self->{pbot}->{nicklist}->is_present($nick);
|
||||||
|
if ($present) {
|
||||||
|
# nick is present in channel
|
||||||
|
$stuff->{nickoverride} = $present;
|
||||||
|
} else {
|
||||||
|
# nick not present, put it back on result
|
||||||
|
$stuff->{result} = "$nick: $stuff->{result}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$self->{pbot}->{interpreter}->handle_result($stuff, $stuff->{result});
|
||||||
}
|
}
|
||||||
|
|
||||||
my $text = $self->{pbot}->{interpreter}->truncate_result($stuff->{channel}, $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'undef', $stuff->{result}, $stuff->{result}, 0);
|
my $text = $self->{pbot}->{interpreter}->truncate_result($stuff->{channel}, $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'undef', $stuff->{result}, $stuff->{result}, 0);
|
||||||
|
@ -880,13 +880,7 @@ sub handle_action {
|
|||||||
|
|
||||||
|
|
||||||
if ($target and $action !~ /\$(?:nick|args)\b/) {
|
if ($target and $action !~ /\$(?:nick|args)\b/) {
|
||||||
if ($action !~ m/^(\/[^ ]+) /) {
|
$stuff->{nickoverride} = $target;
|
||||||
$action =~ s/^/\/say $target: $keyword is / unless defined $stuff->{nickoverride};
|
|
||||||
} else {
|
|
||||||
if ($1 eq '/say') {
|
|
||||||
$action =~ s/^\/say /\/say $target: /;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -908,24 +902,6 @@ sub handle_action {
|
|||||||
return $self->{pbot}->{interpreter}->interpret($stuff);
|
return $self->{pbot}->{interpreter}->interpret($stuff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $stuff->{nickoverride}) { # !tell foo about bar
|
|
||||||
$self->{pbot}->{logger}->log("($stuff->{from}): $stuff->{nick}!$stuff->{user}\@$stuff->{host}) sent to $stuff->{nickoverride}\n");
|
|
||||||
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
|
|
||||||
|
|
||||||
# get rid of original caller's nick
|
|
||||||
$action =~ s/^\/([^ ]+) \Q$stuff->{nick}\E.\s+/\/$1 /;
|
|
||||||
$action =~ s/^\Q$stuff->{nick}\E.\s+//;
|
|
||||||
|
|
||||||
if ($action =~ s/^\/say\s+//i || $action =~ s/^\/me\s+/* $botnick /i || $action =~ /^\/msg\s+/i) {
|
|
||||||
$action = "/say $stuff->{nickoverride}: $action";
|
|
||||||
} elsif ($action =~ m/^\/kick\s+/i) {
|
|
||||||
} else {
|
|
||||||
$action = "/say $stuff->{nickoverride}: $stuff->{original_keyword} is $action";
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("result set to [$action]\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("(" . (defined $stuff->{from} ? $stuff->{from} : "(undef)") . "): $stuff->{nick}!$stuff->{user}\@$stuff->{host}: $keyword: action: \"$action\"\n");
|
$self->{pbot}->{logger}->log("(" . (defined $stuff->{from} ? $stuff->{from} : "(undef)") . "): $stuff->{nick}!$stuff->{user}\@$stuff->{host}: $keyword: action: \"$action\"\n");
|
||||||
|
|
||||||
if ($self->{factoids}->hash->{$channel}->{$keyword}->{enabled} == 0) {
|
if ($self->{factoids}->hash->{$channel}->{$keyword}->{enabled} == 0) {
|
||||||
|
@ -267,7 +267,7 @@ sub interpret {
|
|||||||
$got_pipe = 1;
|
$got_pipe = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$stuff->{nickoverride} = $stuff->{nick} if defined $stuff->{nickoverride} and $stuff->{nickoverride} eq 'me';
|
$stuff->{nickoverride} = $stuff->{nick} if defined $stuff->{nickoverride} and lc $stuff->{nickoverride} eq 'me';
|
||||||
|
|
||||||
if ((not exists $stuff->{pipe}) and $keyword !~ /^(?:factrem|forget|set|factdel|factadd|add|factfind|find|factshow|show|forget|factdel|factset|factchange|change|msg|tell|cc|eval|u|udict|ud|actiontrigger|urban|perl)$/) {
|
if ((not exists $stuff->{pipe}) and $keyword !~ /^(?:factrem|forget|set|factdel|factadd|add|factfind|find|factshow|show|forget|factdel|factset|factchange|change|msg|tell|cc|eval|u|udict|ud|actiontrigger|urban|perl)$/) {
|
||||||
$keyword =~ s/(\w+)([?!.]+)$/$1/;
|
$keyword =~ s/(\w+)([?!.]+)$/$1/;
|
||||||
@ -482,9 +482,15 @@ sub output_result {
|
|||||||
return if not defined $line or not length $line;
|
return if not defined $line or not length $line;
|
||||||
|
|
||||||
if ($line =~ s/^\/say\s+//i) {
|
if ($line =~ s/^\/say\s+//i) {
|
||||||
|
if (defined $stuff->{nickoverride}) {
|
||||||
|
$line = "$stuff->{nickoverride}: $line";
|
||||||
|
}
|
||||||
$pbot->{conn}->privmsg($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
$pbot->{conn}->privmsg($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $stuff->{checkflood};
|
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $stuff->{checkflood};
|
||||||
} elsif ($line =~ s/^\/me\s+//i) {
|
} elsif ($line =~ s/^\/me\s+//i) {
|
||||||
|
if (defined $stuff->{nickoverride}) {
|
||||||
|
$line = "$line (for $stuff->{nickoverride})";
|
||||||
|
}
|
||||||
$pbot->{conn}->me($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
$pbot->{conn}->me($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $line, 0, 0, 0) if $stuff->{checkflood};
|
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $line, 0, 0, 0) if $stuff->{checkflood};
|
||||||
} elsif ($line =~ s/^\/msg\s+([^\s]+)\s+//i) {
|
} elsif ($line =~ s/^\/msg\s+([^\s]+)\s+//i) {
|
||||||
@ -494,10 +500,16 @@ sub output_result {
|
|||||||
} elsif ($to =~ /.*serv$/i) {
|
} elsif ($to =~ /.*serv$/i) {
|
||||||
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$stuff->{nick}!$stuff->{user}\@$stuff->{host}] [$stuff->{command}] [$line]\n");
|
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$stuff->{nick}!$stuff->{user}\@$stuff->{host}] [$stuff->{command}] [$line]\n");
|
||||||
} elsif ($line =~ s/^\/me\s+//i) {
|
} elsif ($line =~ s/^\/me\s+//i) {
|
||||||
|
if (defined $stuff->{nickoverride}) {
|
||||||
|
$line = "$line (for $stuff->{nickoverride})";
|
||||||
|
}
|
||||||
$pbot->{conn}->me($to, $line) if $to !~ /\Q$botnick\E/i;
|
$pbot->{conn}->me($to, $line) if $to !~ /\Q$botnick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $line, 0, 0, 0) if $stuff->{checkflood};
|
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $line, 0, 0, 0) if $stuff->{checkflood};
|
||||||
} else {
|
} else {
|
||||||
$line =~ s/^\/say\s+//i;
|
$line =~ s/^\/say\s+//i;
|
||||||
|
if (defined $stuff->{nickoverride}) {
|
||||||
|
$line = "$stuff->{nickoverride}: $line";
|
||||||
|
}
|
||||||
$pbot->{conn}->privmsg($to, $line) if $to !~ /\Q$botnick\E/i;
|
$pbot->{conn}->privmsg($to, $line) if $to !~ /\Q$botnick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $stuff->{checkflood};
|
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $stuff->{checkflood};
|
||||||
}
|
}
|
||||||
@ -523,6 +535,9 @@ sub output_result {
|
|||||||
$pbot->{conn}->privmsg($stuff->{from}, "$victim: $reason") if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
$pbot->{conn}->privmsg($stuff->{from}, "$victim: $reason") if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (defined $stuff->{nickoverride}) {
|
||||||
|
$line = "$stuff->{nickoverride}: $line";
|
||||||
|
}
|
||||||
$pbot->{conn}->privmsg($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
$pbot->{conn}->privmsg($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} !~ /\Q$botnick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $stuff->{checkflood};
|
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $stuff->{checkflood};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user