diff --git a/lib/commands/later.pm b/lib/commands/later.pm index c1c365c51377a3573204bc9e6ab20a71b5bed480..96d54e9578bf3d245e1bda439b982d5f44fada0a 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 e209fd7d1b0d147daa18e3221aa58ee43c69f520..17be6341e232036fe6737941f9791ee4a7a1283e 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);