mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-19 10:29:30 +01:00
Support +
in recall
command to recall multiple messages, similiar to grab
This commit is contained in:
parent
97261637f1
commit
a9adbcf498
@ -53,7 +53,7 @@ sub initialize {
|
|||||||
$pbot->commands->register(sub { $self->delete_quotegrab(@_) }, "delq", 0);
|
$pbot->commands->register(sub { $self->delete_quotegrab(@_) }, "delq", 0);
|
||||||
$pbot->commands->register(sub { $self->show_random_quotegrab(@_) }, "rq", 0);
|
$pbot->commands->register(sub { $self->show_random_quotegrab(@_) }, "rq", 0);
|
||||||
|
|
||||||
# ought to be in MessageTracker.pm (when it's created)
|
# ought to be in MessageTracker.pm once we create that module
|
||||||
$pbot->commands->register(sub { $self->recall_message(@_) }, "recall", 0);
|
$pbot->commands->register(sub { $self->recall_message(@_) }, "recall", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,85 +475,107 @@ sub recall_message {
|
|||||||
|
|
||||||
$arguments = lc $arguments;
|
$arguments = lc $arguments;
|
||||||
|
|
||||||
my ($recall_nick, $recall_history, $channel) = split(/\s+/, $arguments, 3);
|
my @recalls = split /\s\+\s/, $arguments;
|
||||||
|
|
||||||
if(not defined $recall_history) {
|
my ($recall_nick, $recall_history, $channel, $recall_nicks, $recall_text);
|
||||||
$recall_history = $nick eq $recall_nick ? 2 : 1;
|
|
||||||
}
|
|
||||||
$channel = $from if not defined $channel;
|
|
||||||
|
|
||||||
if($recall_history =~ /^\d+$/ and ($recall_history < 1 || $recall_history > $self->{pbot}->{MAX_NICK_MESSAGES})) {
|
foreach my $recall (@recalls) {
|
||||||
return "/msg $nick Please choose a history between 1 and $self->{pbot}->{MAX_NICK_MESSAGES}";
|
($recall_nick, $recall_history, $channel) = split(/\s+/, $recall, 3);
|
||||||
}
|
|
||||||
|
|
||||||
my $found_mask = undef;
|
if(not defined $recall_history) {
|
||||||
my $last_spoken = 0;
|
$recall_history = $nick eq $recall_nick ? 2 : 1;
|
||||||
foreach my $mask (keys %{ $self->{pbot}->antiflood->message_history }) {
|
|
||||||
if($mask =~ m/^\Q$recall_nick\E!/i) {
|
|
||||||
if(defined $self->{pbot}->antiflood->message_history->{$mask}->{channels}->{$channel}{last_spoken}
|
|
||||||
and $self->{pbot}->antiflood->message_history->{$mask}->{channels}->{$channel}{last_spoken} > $last_spoken) {
|
|
||||||
$last_spoken = $self->{pbot}->antiflood->message_history->{$mask}->{channels}->{$channel}{last_spoken};
|
|
||||||
$found_mask = $mask;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
$channel = $from if not defined $channel;
|
||||||
|
|
||||||
if(not defined $found_mask) {
|
if($recall_history =~ /^\d+$/ and ($recall_history < 1 || $recall_history > $self->{pbot}->{MAX_NICK_MESSAGES})) {
|
||||||
return "No message history for $recall_nick in channel $channel. Usage: recall <nick> [history [channel]]; to specify channel, you must also specify history";
|
return "/msg $nick Please choose a history between 1 and $self->{pbot}->{MAX_NICK_MESSAGES}";
|
||||||
}
|
|
||||||
|
|
||||||
if(not exists $self->{pbot}->antiflood->message_history->{$found_mask}->{channels}->{$channel}) {
|
|
||||||
return "No message history for $recall_nick in channel $channel. Usage: recall <nick> [history [channel]]; to specify channel, you must also specify history";
|
|
||||||
}
|
|
||||||
|
|
||||||
my @messages = @{ $self->{pbot}->antiflood->message_history->{$found_mask}->{channels}->{$channel}{messages} };
|
|
||||||
|
|
||||||
if($recall_history =~ /^\d+$/) {
|
|
||||||
# integral history
|
|
||||||
$recall_history--;
|
|
||||||
|
|
||||||
if($recall_history > $#messages) {
|
|
||||||
return "$recall_nick has only " . ($#messages + 1) . " messages in the history for channel $channel.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$recall_history = $#messages - $recall_history;
|
my $found_mask = undef;
|
||||||
} else {
|
my $last_spoken = 0;
|
||||||
# regex history
|
foreach my $mask (keys %{ $self->{pbot}->antiflood->message_history }) {
|
||||||
my $ret = eval {
|
if($mask =~ m/^\Q$recall_nick\E!/i) {
|
||||||
my $i = $#messages;
|
if(defined $self->{pbot}->antiflood->message_history->{$mask}->{channels}->{$channel}{last_spoken}
|
||||||
$i-- if($nick =~ /^\Q$recall_nick\E$/i); # skip 'recall' command if recallbing own nick
|
and $self->{pbot}->antiflood->message_history->{$mask}->{channels}->{$channel}{last_spoken} > $last_spoken) {
|
||||||
my $found = 0;
|
$last_spoken = $self->{pbot}->antiflood->message_history->{$mask}->{channels}->{$channel}{last_spoken};
|
||||||
while($i >= 0) {
|
$found_mask = $mask;
|
||||||
if($messages[$i]->{msg} =~ m/$recall_history/i) {
|
|
||||||
$recall_history = $i;
|
|
||||||
$found = 1;
|
|
||||||
last;
|
|
||||||
}
|
}
|
||||||
$i--;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(not defined $found_mask) {
|
||||||
|
return "No message history for $recall_nick in channel $channel. Usage: recall <nick> [history [channel]]; to specify channel, you must also specify history";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(not exists $self->{pbot}->antiflood->message_history->{$found_mask}->{channels}->{$channel}) {
|
||||||
|
return "No message history for $recall_nick in channel $channel. Usage: recall <nick> [history [channel]]; to specify channel, you must also specify history";
|
||||||
|
}
|
||||||
|
|
||||||
|
my @messages = @{ $self->{pbot}->antiflood->message_history->{$found_mask}->{channels}->{$channel}{messages} };
|
||||||
|
|
||||||
|
if($recall_history =~ /^\d+$/) {
|
||||||
|
# integral history
|
||||||
|
$recall_history--;
|
||||||
|
|
||||||
|
if($recall_history > $#messages) {
|
||||||
|
return "$recall_nick has only " . ($#messages + 1) . " messages in the history for channel $channel.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if($found == 0) {
|
$recall_history = $#messages - $recall_history;
|
||||||
return "/msg $nick No message containing regex '$recall_history' found for $recall_nick in channel $channel.";
|
} else {
|
||||||
} else {
|
# regex history
|
||||||
return undef;
|
my $ret = eval {
|
||||||
|
my $i = $#messages;
|
||||||
|
$i-- if($nick =~ /^\Q$recall_nick\E$/i); # skip 'recall' command if recallbing own nick
|
||||||
|
my $found = 0;
|
||||||
|
while($i >= 0) {
|
||||||
|
if($messages[$i]->{msg} =~ m/$recall_history/i) {
|
||||||
|
$recall_history = $i;
|
||||||
|
$found = 1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
$i--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($found == 0) {
|
||||||
|
return "/msg $nick No message containing regex '$recall_history' found for $recall_nick in channel $channel.";
|
||||||
|
} else {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return "/msg $nick Bad recall regex: $@" if $@;
|
||||||
|
if(defined $ret) {
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$self->{pbot}->logger->log("$nick ($from) recalled <$recall_nick/$channel> $messages[$recall_history]->{msg}\n");
|
||||||
|
|
||||||
|
if(not defined $recall_nicks) {
|
||||||
|
$recall_nicks = $recall_nick;
|
||||||
|
} else {
|
||||||
|
$recall_nicks .= "+$recall_nick";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $text = $messages[$recall_history]->{msg};
|
||||||
|
my $ago = ago(gettimeofday - $messages[$recall_history]->{timestamp});
|
||||||
|
|
||||||
|
if(not defined $recall_text) {
|
||||||
|
if($text =~ s/^\/me\s+//) {
|
||||||
|
$recall_text = "[$ago] * $recall_nick $text";
|
||||||
|
} else {
|
||||||
|
$recall_text = "[$ago] <$recall_nick> $text";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if($text =~ s/^\/me\s+//) {
|
||||||
|
$recall_text .= " [$ago] * $recall_nick $text";
|
||||||
|
} else {
|
||||||
|
$recall_text .= " [$ago] <$recall_nick> $text";
|
||||||
}
|
}
|
||||||
};
|
|
||||||
return "/msg $nick Bad recall regex: $@" if $@;
|
|
||||||
if(defined $ret) {
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{pbot}->logger->log("$nick ($from) recalled <$recall_nick/$channel> $messages[$recall_history]->{msg}\n");
|
return $recall_text;
|
||||||
|
|
||||||
my $text = $messages[$recall_history]->{msg};
|
|
||||||
my $ago = ago(gettimeofday - $messages[$recall_history]->{timestamp});
|
|
||||||
|
|
||||||
if($text =~ s/^\/me\s+//) {
|
|
||||||
return "$ago: * $recall_nick $text";
|
|
||||||
} else {
|
|
||||||
return "$ago: <$recall_nick> $text";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -13,8 +13,8 @@ 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 => 460,
|
BUILD_REVISION => 461,
|
||||||
BUILD_DATE => "2013-10-26",
|
BUILD_DATE => "2013-10-27",
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user