From d2150f4777ec1be531ad8f160d546e7d6008050f Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <erdnaxeli@gmail.com> Date: Sat, 16 Aug 2014 21:07:46 +0200 Subject: [PATCH] we can now do !get -1 (works only with 1) --- lib/commands/later.pm | 30 +++++++++++++++++++++++++++--- lib/commands/parser.pm | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/commands/later.pm b/lib/commands/later.pm index c1c365c..96d54e9 100644 --- a/lib/commands/later.pm +++ b/lib/commands/later.pm @@ -12,16 +12,40 @@ sub exec { $time = 6 if (!$time); $time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600; - $kernel->delay_set('_later', $time, $nick, $id); + + if ($id == -1) { + my $sth = $dbh->prepare_cached(' + SELECT content + FROM playbot_chan + WHERE id < (SELECT id + FROM playbot_chan + WHERE content = ?) + AND chan = (SELECT chan + FROM playbot_chan + WHERE content = ?) + ORDER BY id DESC + LIMIT 1'); + unless (defined $sth) { + $log->error("Couldn't prepare querie; aborting"); + return; + } + $sth->execute($id, $id) + or $log->error("Couldn't finish transaction: " . $dbh->errstr); + + return unless ($content); + my $content = $sth->fetch; + $id = $content->[0]; + } my $sth = $dbh->prepare_cached('INSERT INTO playbot_later (content, nick, date) VALUES (?, ?, ?)'); unless (defined $sth) { $log->error("Couldn't prepare querie; aborting"); return; - } - + } $sth->execute($id, $nick, time + $time) or $log->error("Couldn't finish transaction: " . $dbh->errstr); + + $kernel->delay_set('_later', $time, $nick, $id); } 1; diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm index e209fd7..17be634 100644 --- a/lib/commands/parser.pm +++ b/lib/commands/parser.pm @@ -43,7 +43,7 @@ sub exec { commands::fav::exec($nick, $id) } - elsif ($msg =~ /^ *!later(?: ([0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) { + elsif ($msg =~ /^ *!later(?: (-?[0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) { my $id = ($1) ? $1 : $lastID->{$chan->[0]}; my ($time, $unit) = ($2, $3); -- GitLab