diff --git a/lib/commands/later.pm b/lib/commands/later.pm index 96d54e9578bf3d245e1bda439b982d5f44fada0a..976fbf35496a0dc390ef007d9c4628046ba422bb 100644 --- a/lib/commands/later.pm +++ b/lib/commands/later.pm @@ -8,32 +8,36 @@ our $dbh; our $log; sub exec { - my ($kernel, $nick, $id, $time, $unit) = @_; + my ($kernel, $nick, $id, $offset, $chan, $time, $unit) = @_; + print ">>@_\n"; $time = 6 if (!$time); $time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600; - if ($id == -1) { + if ($offset == -1) { + print "lolo\n"; my $sth = $dbh->prepare_cached(' SELECT content FROM playbot_chan - WHERE id < (SELECT id + WHERE date < (SELECT date FROM playbot_chan - WHERE content = ?) + WHERE content = ? + AND chan = ?) AND chan = (SELECT chan FROM playbot_chan - WHERE content = ?) - ORDER BY id DESC + WHERE content = ? + AND chan = ?) + ORDER BY date DESC LIMIT 1'); unless (defined $sth) { $log->error("Couldn't prepare querie; aborting"); return; } - $sth->execute($id, $id) + $sth->execute($id, $chan->[0], $id, $chan->[0]) or $log->error("Couldn't finish transaction: " . $dbh->errstr); - return unless ($content); my $content = $sth->fetch; + return unless ($content); $id = $content->[0]; } diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm index c8b925c1e8e5394050676fa1f634921e815b20c3..368cbaceaddc08c01efe0322dfe957c404c900ca 100644 --- a/lib/commands/parser.pm +++ b/lib/commands/parser.pm @@ -14,14 +14,15 @@ use commands::get; my $lastID; my $irc; +my $dbh; sub setConf { - my ($ircNew, $dbh, $log, $lastIDnew) = @_; + my ($ircNew, $dbhNew, $log, $lastIDnew) = @_; - $commands::fav::dbh = $dbh; - $commands::tag::dbh = $dbh; - $commands::get::dbh = $dbh; - $commands::later::dbh = $dbh; + $commands::fav::dbh = $dbhNew; + $commands::tag::dbh = $dbhNew; + $commands::get::dbh = $dbhNew; + $commands::later::dbh = $dbhNew; $commands::fav::log = $log; $commands::tag::log = $log; @@ -31,8 +32,9 @@ sub setConf { $commands::fav::irc = $ircNew; $commands::get::irc = $ircNew; - $irc = $ircNew; $lastID = $lastIDnew; + $irc = $ircNew; + $dbh = $dbhNew; } sub exec { @@ -45,10 +47,23 @@ sub exec { commands::fav::exec($nick, $id) } elsif ($msg =~ /^ *!later(?: (-?[0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) { - my $id = ($1) ? $1 : $lastID->{$chan->[0]}; + my $id = $1; + my $offset = $1; my ($time, $unit) = ($2, $3); - commands::later::exec($kernel, $nick, $id, $time, $unit); + 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); } elsif ($msg =~ /^( *!tag)(?:( +)([0-9]+))?/) { my $id = $3;