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

move later management to sessions::irc::later

parent ddd64fb5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -14,6 +14,7 @@ use FindBin; ...@@ -14,6 +14,7 @@ use FindBin;
use lib "$FindBin::Bin/lib/"; use lib "$FindBin::Bin/lib/";
use utils::Logging; use utils::Logging;
use sessions::irc::later;
use sites::parser; use sites::parser;
use commands::parser; use commands::parser;
...@@ -65,7 +66,9 @@ POE::Session->create( ...@@ -65,7 +66,9 @@ POE::Session->create(
irc_invite => \&on_invite, irc_invite => \&on_invite,
irc_notice => \&on_notice, irc_notice => \&on_notice,
_flux => \&flux, _flux => \&flux,
_later => \&later _later => sub {
sessions::irc::later::consume($_[ARG0], $_[ARG1])
}
}, },
); );
...@@ -99,35 +102,6 @@ sub flux ...@@ -99,35 +102,6 @@ sub flux
} }
sub later
{
my ($nick, $id) = @_[ARG0,ARG1];
my $sth = $dbh->prepare('SELECT url, sender, title FROM playbot WHERE id = ?');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute($id)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
if ($sth->rows) {
my @donnees = $sth->fetchrow_array;
$irc->yield(privmsg => $nick => '['.$id.'] '.$donnees[2].' | '.$donnees[1]);
$irc->yield(privmsg => $nick => $donnees[0]);
# save the content in the history
my $sth2 = $dbh->prepare('
INSERT INTO playbot_chan (content, chan, sender_irc)
VALUES (?,?,?)');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth2);
$sth2->execute($id, $nick, $nick)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
$lastID{$nick} = $id;
}
}
sub cycle sub cycle
{ {
my ($arg) = @_; my ($arg) = @_;
...@@ -144,6 +118,9 @@ sub setConf ...@@ -144,6 +118,9 @@ sub setConf
{ {
commands::parser::setConf($irc, $dbh, $log, \%lastID); commands::parser::setConf($irc, $dbh, $log, \%lastID);
$sessions::irc::later::irc = $irc;
$sessions::irc::later::log = $log;
$sites::parser::irc = $irc; $sites::parser::irc = $irc;
$sites::parser::log = $log; $sites::parser::log = $log;
} }
......
package utils::later;
use lib "$FindBin::Bin/lib/";
use utils::db;
use utils::print;
our $irc;
our $log;
sub consume
{
my ($nick, $id) = @_;
my $dbh = utils::db::main_session();
my $sth = $dbh->prepare('SELECT url, sender, title FROM playbot WHERE id = ?');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth);
$sth->execute($id)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
if ($sth->rows) {
my @donnees = $sth->fetchrow_array;
$irc->yield(privmsg => $nick => '['.$id.'] '.$donnees[2].' | '.$donnees[1]);
$irc->yield(privmsg => $nick => $donnees[0]);
# save the content in the history
my $sth2 = $dbh->prepare('
INSERT INTO playbot_chan (content, chan, sender_irc)
VALUES (?,?,?)');
$log->error("Couldn't prepare querie; aborting") unless (defined $sth2);
$sth2->execute($id, $nick, $nick)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
}
$dbh->commit;
}
1;
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