mirror of
https://github.com/pragma-/pbot.git
synced 2025-02-04 08:24:06 +01:00
Add ability to preserve newlines in output; require explicit factadd
to add factoids
This commit is contained in:
parent
74cffe091c
commit
b15ab7f84f
@ -147,11 +147,9 @@ sub handle_result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $original_result = $result;
|
my $original_result = $result;
|
||||||
$result =~ s/[\n\r]/ /g;
|
|
||||||
|
|
||||||
if($preserve_whitespace == 0 && defined $command) {
|
if($preserve_whitespace == 0 && defined $command) {
|
||||||
my ($cmd, $args) = split / /, $command, 2;
|
my ($cmd, $args) = split / /, $command, 2;
|
||||||
#$self->{pbot}->{logger}->log("calling find_factoid in Interpreter.pm, process_line() for preserve_whitespace\n");
|
|
||||||
my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $cmd, $args, 0, 1);
|
my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($from, $cmd, $args, 0, 1);
|
||||||
if(defined $trigger) {
|
if(defined $trigger) {
|
||||||
$preserve_whitespace = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{preserve_whitespace};
|
$preserve_whitespace = $self->{pbot}->{factoids}->{factoids}->hash->{$chan}->{$trigger}->{preserve_whitespace};
|
||||||
@ -159,35 +157,52 @@ sub handle_result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result =~ s/\s+/ /g unless $preserve_whitespace;
|
my $preserve_newlines = $self->{pbot}->{registry}->get_value($from, 'preserve_newlines');
|
||||||
$result = $self->truncate_result($from, $nick, $text, $original_result, $result, 1);
|
|
||||||
$pbot->{logger}->log("Final result: [$result]\n");
|
|
||||||
|
|
||||||
if($result =~ s/^\/say\s+//i) {
|
$result =~ s/[\n\r]/ /g unless $preserve_newlines;
|
||||||
$pbot->{conn}->privmsg($from, $result) if defined $from && $from !~ /\Q$mynick\E/i;
|
$result =~ s/\s+/ /g unless $preserve_whitespace;
|
||||||
$pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood;
|
|
||||||
} elsif($result =~ s/^\/me\s+//i) {
|
my $lines = 0;
|
||||||
$pbot->{conn}->me($from, $result) if defined $from && $from !~ /\Q$mynick\E/i;
|
foreach my $line (split /[\n\r]/, $result) {
|
||||||
$pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $result, 0, 0, 0) if $checkflood;
|
if (++$lines >= 4) {
|
||||||
} elsif($result =~ s/^\/msg\s+([^\s]+)\s+//i) {
|
$pbot->{conn}->privmsg($from, "And that's all I have to say about that.");
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($preserve_newlines) {
|
||||||
|
$line = $self->truncate_result($from, $nick, $text, $line, $line, 1);
|
||||||
|
} else {
|
||||||
|
$line = $self->truncate_result($from, $nick, $text, $original_result, $line, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pbot->{logger}->log("Final result: [$line]\n");
|
||||||
|
|
||||||
|
if($line =~ s/^\/say\s+//i) {
|
||||||
|
$pbot->{conn}->privmsg($from, $line) if defined $from && $from !~ /\Q$mynick\E/i;
|
||||||
|
$pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $checkflood;
|
||||||
|
} elsif($line =~ s/^\/me\s+//i) {
|
||||||
|
$pbot->{conn}->me($from, $line) if defined $from && $from !~ /\Q$mynick\E/i;
|
||||||
|
$pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $line, 0, 0, 0) if $checkflood;
|
||||||
|
} elsif($line =~ s/^\/msg\s+([^\s]+)\s+//i) {
|
||||||
my $to = $1;
|
my $to = $1;
|
||||||
if($to =~ /,/) {
|
if($to =~ /,/) {
|
||||||
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg multiple users: [$nick!$user\@$host] [$command] [$result]\n");
|
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg multiple users: [$nick!$user\@$host] [$command] [$line]\n");
|
||||||
}
|
}
|
||||||
elsif($to =~ /.*serv$/i) {
|
elsif($to =~ /.*serv$/i) {
|
||||||
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$nick!$user\@$host] [$command] [$result]\n");
|
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$nick!$user\@$host] [$command] [$line]\n");
|
||||||
}
|
}
|
||||||
elsif($result =~ s/^\/me\s+//i) {
|
elsif($line =~ s/^\/me\s+//i) {
|
||||||
$pbot->{conn}->me($to, $result) if $to !~ /\Q$mynick\E/i;
|
$pbot->{conn}->me($to, $line) if $to !~ /\Q$mynick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $result, 0, 0, 0) if $checkflood;
|
$pbot->{antiflood}->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', '/me ' . $line, 0, 0, 0) if $checkflood;
|
||||||
} else {
|
} else {
|
||||||
$result =~ s/^\/say\s+//i;
|
$line =~ s/^\/say\s+//i;
|
||||||
$pbot->{conn}->privmsg($to, $result) if $to !~ /\Q$mynick\E/i;
|
$pbot->{conn}->privmsg($to, $line) if $to !~ /\Q$mynick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood;
|
$pbot->{antiflood}->check_flood($to, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $checkflood;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$pbot->{conn}->privmsg($from, $result) if defined $from && $from !~ /\Q$mynick\E/i;
|
$pbot->{conn}->privmsg($from, $line) if defined $from && $from !~ /\Q$mynick\E/i;
|
||||||
$pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $result, 0, 0, 0) if $checkflood;
|
$pbot->{antiflood}->check_flood($from, $mynick, $pbot->{registry}->get_value('irc', 'username'), 'localhost', $line, 0, 0, 0) if $checkflood;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$pbot->{logger}->log("---------------------------------------------\n");
|
$pbot->{logger}->log("---------------------------------------------\n");
|
||||||
}
|
}
|
||||||
@ -214,19 +229,6 @@ sub interpret {
|
|||||||
($keyword, $arguments, $tonick) = ($2, $3, $1);
|
($keyword, $arguments, $tonick) = ($2, $3, $1);
|
||||||
} elsif($command =~ /^tell\s+(.{1,20})\s+about\s+(.*)$/i) {
|
} elsif($command =~ /^tell\s+(.{1,20})\s+about\s+(.*)$/i) {
|
||||||
($keyword, $tonick) = ($2, $1);
|
($keyword, $tonick) = ($2, $1);
|
||||||
} elsif($command =~ /^([^ ]+)\s+is\s+also\s+(.*)$/i) {
|
|
||||||
($keyword, $arguments) = ("change", "$1 s|\$| - $2|");
|
|
||||||
} elsif($command =~ /^([^ ]+)\s+is\s+(.*)$/i) {
|
|
||||||
my ($k, $a) = ($1, $2);
|
|
||||||
|
|
||||||
$self->{pbot}->{logger}->log("calling find_factoid in Interpreter.pm, interpret() for factadd\n");
|
|
||||||
my ($channel, $trigger) = $pbot->{factoids}->find_factoid($from, $k, $a, 1);
|
|
||||||
|
|
||||||
if(defined $trigger) {
|
|
||||||
($keyword, $arguments) = ($k, "is $a");
|
|
||||||
} else {
|
|
||||||
($keyword, $arguments) = ("factadd", (defined $from ? $from : '.*' ) . " $k is $a");
|
|
||||||
}
|
|
||||||
} elsif($command =~ /^(.*?)\s+(.*)$/) {
|
} elsif($command =~ /^(.*?)\s+(.*)$/) {
|
||||||
($keyword, $arguments) = ($1, $2);
|
($keyword, $arguments) = ($1, $2);
|
||||||
} else {
|
} else {
|
||||||
|
@ -13,7 +13,7 @@ use warnings;
|
|||||||
# These are set automatically by the build/commit script
|
# These are set automatically by the build/commit script
|
||||||
use constant {
|
use constant {
|
||||||
BUILD_NAME => "PBot",
|
BUILD_NAME => "PBot",
|
||||||
BUILD_REVISION => 765,
|
BUILD_REVISION => 766,
|
||||||
BUILD_DATE => "2014-08-04",
|
BUILD_DATE => "2014-08-04",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user