Skip to content
Extraits de code Groupes Projets
Valider 32cc42db rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

!later uses utils::id and all its magic

parent 3927607c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -4,42 +4,11 @@ our $dbh; ...@@ -4,42 +4,11 @@ our $dbh;
our $log; our $log;
sub exec { sub exec {
my ($kernel, $nick, $id, $offset, $chan, $time, $unit) = @_; my ($kernel, $nick, $id, $chan, $time, $unit) = @_;
$time = 6 if (!$time); $time = 6 if (!$time);
$time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600; $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 (?, ?, ?)'); my $sth = $dbh->prepare_cached('INSERT INTO playbot_later (content, nick, date) VALUES (?, ?, ?)');
unless (defined $sth) { unless (defined $sth) {
$log->error("Couldn't prepare querie; aborting"); $log->error("Couldn't prepare querie; aborting");
......
...@@ -49,23 +49,16 @@ sub exec { ...@@ -49,23 +49,16 @@ sub exec {
commands::fav::exec($nick, $id) 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; my $index = $1;
my $offset = ($1) ? $1 : 0; my $offset = ($1) ? $1 : 0;
my ($time, $unit) = ($2, $3); my ($time, $unit) = ($2, $3);
if ($id eq '' || $id =~ /^-/) { try {
my $sth = $dbh->prepare(' my $id = utils::id::get($chan->[0], $index);
SELECT content commands::later::exec($kernel, $nick, $id, $chan, $time, $unit);
FROM playbot_chan } catch {
WHERE chan = ? $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]);
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]+))?/) { elsif ($msg =~ /^( *!tag)(?:( +)(-?[0-9]+))?/) {
my $index = $3; my $index = $3;
...@@ -83,7 +76,6 @@ sub exec { ...@@ -83,7 +76,6 @@ sub exec {
commands::tag::exec($id, $msg); commands::tag::exec($id, $msg);
} catch { } catch {
$irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]); $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]);
return 1;
}; };
} }
elsif ($msg =~ /^( *!get)(?: +.*)?$/) { elsif ($msg =~ /^( *!get)(?: +.*)?$/) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter