diff --git a/lib/commands/later.pm b/lib/commands/later.pm index 49d2868bb325a658cadc34d6c4ec37f893d7eebe..cc8cd2ccbf670d61b0d40b60134d75cd1dcd4600 100644 --- a/lib/commands/later.pm +++ b/lib/commands/later.pm @@ -4,42 +4,11 @@ our $dbh; our $log; sub exec { - my ($kernel, $nick, $id, $offset, $chan, $time, $unit) = @_; + my ($kernel, $nick, $id, $chan, $time, $unit) = @_; $time = 6 if (!$time); $time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600; - while ($offset < 0) { - my $sth = $dbh->prepare_cached(' - SELECT content - FROM playbot_chan - WHERE date < (SELECT date - FROM playbot_chan - WHERE content = ? - AND chan = ? - ORDER BY date DESC - LIMIT 1) - AND chan = (SELECT chan - FROM playbot_chan - WHERE content = ? - AND chan = ? - ORDER BY date DESC - LIMIT 1) - ORDER BY date DESC - LIMIT 1'); - unless (defined $sth) { - $log->error("Couldn't prepare querie; aborting"); - return; - } - $sth->execute($id, $chan->[0], $id, $chan->[0]) - or $log->error("Couldn't finish transaction: " . $dbh->errstr); - - my $content = $sth->fetch; - return unless ($content); - $id = $content->[0]; - $offset++; - } - my $sth = $dbh->prepare_cached('INSERT INTO playbot_later (content, nick, date) VALUES (?, ?, ?)'); unless (defined $sth) { $log->error("Couldn't prepare querie; aborting"); diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm index 70e57f84e5b95bbcab57155feeadbfd90990f9eb..a11a7ce5972acf56a3730a6bcf808827fa0961a9 100644 --- a/lib/commands/parser.pm +++ b/lib/commands/parser.pm @@ -49,23 +49,16 @@ sub exec { commands::fav::exec($nick, $id) } elsif ($msg =~ /^ *!later(?: (-?[0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) { - my $id = $1; + my $index = $1; my $offset = ($1) ? $1 : 0; my ($time, $unit) = ($2, $3); - if ($id eq '' || $id =~ /^-/) { - my $sth = $dbh->prepare(' - SELECT content - FROM playbot_chan - WHERE chan = ? - AND date <= NOW() - ORDER BY date DESC - LIMIT 1'); - $sth->execute($chan->[0]); - $id = $sth->fetch->[0]; - } - - commands::later::exec($kernel, $nick, $id, $offset, $chan, $time, $unit); + try { + my $id = utils::id::get($chan->[0], $index); + commands::later::exec($kernel, $nick, $id, $chan, $time, $unit); + } catch { + $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]); + }; } elsif ($msg =~ /^( *!tag)(?:( +)(-?[0-9]+))?/) { my $index = $3; @@ -83,7 +76,6 @@ sub exec { commands::tag::exec($id, $msg); } catch { $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]); - return 1; }; } elsif ($msg =~ /^( *!get)(?: +.*)?$/) {