3
0
mirror of https://github.com/pragma-/pbot.git synced 2025-01-09 19:42:38 +01:00

Add functionality to grab multiple nicks in one quotegrab

This commit is contained in:
Pragmatic Software 2013-10-04 04:55:45 +00:00
parent e3ade2cb09
commit 2cb74ecf95
2 changed files with 89 additions and 64 deletions

View File

@ -161,12 +161,17 @@ sub grab_quotegrab {
} }
if(not defined $arguments or not length $arguments) { if(not defined $arguments or not length $arguments) {
return "Usage: grab <nick> [history [channel]] -- where [history] is an optional argument that is either an integer number of recent messages or a regex (without whitespace) of the text within the message; e.g., to grab the 3rd most recent message for nick, use `grab nick 3` or to grab a message containing 'pizza', use `grab nick pizza`; and [channel] is an optional channel, so you can use it from /msg (you will need to also specify [history] in this case)"; return "Usage: grab <nick> [history [channel]] -- where [history] is an optional argument that is either an integral number of recent messages or a regex (without whitespace) of the text within the message; e.g., to grab the 3rd most recent message for nick, use `grab nick 3` or to grab a message containing 'pizza', use `grab nick pizza`; and [channel] is an optional channel, so you can use it from /msg (you will need to also specify [history] in this case)";
} }
$arguments = lc $arguments; $arguments = lc $arguments;
my ($grab_nick, $grab_history, $channel) = split(/\s+/, $arguments, 3); my @grabs = split /\s\+\s/, $arguments;
my ($grab_nick, $grab_history, $channel, $grab_nicks, $grab_text);
foreach my $grab (@grabs) {
($grab_nick, $grab_history, $channel) = split(/\s+/, $grab, 3);
if(not defined $grab_history) { if(not defined $grab_history) {
$grab_history = $nick eq $grab_nick ? 2 : 1; $grab_history = $nick eq $grab_nick ? 2 : 1;
@ -237,12 +242,31 @@ sub grab_quotegrab {
$self->{pbot}->logger->log("$nick ($from) grabbed <$grab_nick/$channel> $messages[$grab_history]->{msg}\n"); $self->{pbot}->logger->log("$nick ($from) grabbed <$grab_nick/$channel> $messages[$grab_history]->{msg}\n");
if(not defined $grab_nicks) {
$grab_nicks = $grab_nick;
} else {
$grab_nicks .= "+$grab_nick";
}
my $text = $messages[$grab_history]->{msg};
if(not defined $grab_text) {
$grab_text = $text;
} else {
if($text =~ s/^\/me\s+//) {
$grab_text .= " * $grab_nick $text";
} else {
$grab_text .= " <$grab_nick> $text";
}
}
}
my $quotegrab = {}; my $quotegrab = {};
$quotegrab->{nick} = $grab_nick; $quotegrab->{nick} = $grab_nicks;
$quotegrab->{channel} = $channel; $quotegrab->{channel} = $channel;
$quotegrab->{timestamp} = $messages[$grab_history]->{timestamp}; $quotegrab->{timestamp} = gettimeofday;
$quotegrab->{grabbed_by} = $nick; $quotegrab->{grabbed_by} = "$nick!$user\@$host";
$quotegrab->{text} = $messages[$grab_history]->{msg}; $quotegrab->{text} = $grab_text;
$quotegrab->{id} = $#{ $self->{quotegrabs} } + 2; $quotegrab->{id} = $#{ $self->{quotegrabs} } + 2;
push @{ $self->{quotegrabs} }, $quotegrab; push @{ $self->{quotegrabs} }, $quotegrab;
@ -250,6 +274,7 @@ sub grab_quotegrab {
$self->save_quotegrabs(); $self->save_quotegrabs();
my $text = $quotegrab->{text}; my $text = $quotegrab->{text};
($grab_nick) = split /\+/, $grab_nicks, 2;
if($text =~ s/^\/me\s+//) { if($text =~ s/^\/me\s+//) {
return "Quote grabbed: " . ($#{ $self->{quotegrabs} } + 1) . ": * $grab_nick $text"; return "Quote grabbed: " . ($#{ $self->{quotegrabs} } + 1) . ": * $grab_nick $text";

View File

@ -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 => 433, BUILD_REVISION => 434,
BUILD_DATE => "2013-09-16", BUILD_DATE => "2013-10-03",
}; };
1; 1;