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

New module commands::parser.

All the commands' code (!later, !tag, …) is now deported in this module.
It will be separated in different modules in the futur.
parent 8ad8e88c
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;
use lib "$FindBin::Bin/lib/";
use Logging;
use sites::parser;
use commands::parser;
# nom du fichier
my $bot = $0;
......@@ -58,6 +59,8 @@ my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $co
})
or die("Couldn't connect to database: ".DBI->errstr);
$commands::parser::irc = $irc;
$commands::parser::dbh = $dbh;
# Evenements que le bot va gérer
POE::Session->create(
......@@ -77,7 +80,6 @@ irc_notice => \&on_notice,
my %commandes_admin = ("cycle" => \&cycle);
### FONCTIONS
sub flux
{
......@@ -259,6 +261,8 @@ sub on_invite
sub on_speak
{
my ($kernel, $user, $chan, $msg) = @_[KERNEL, ARG0, ARG1, ARG2];
my @args = ($kernel, $user, $chan, $msg);
my ($nick,$mask) = split(/!/,$user);
my %content;
......@@ -315,41 +319,8 @@ sub on_speak
$irc->yield(privmsg => $chan => '['.$id.'] '.$content{'title'}) ;
}
}
elsif ($msg =~ /^!fav( ([0-9]+))?/) {
my $id = ($2) ? $2 : $lastID;
my $sth = $dbh->prepare_cached('SELECT user FROM playbot_codes WHERE nick = ?');
$sth->execute($nick)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
if (!$sth->rows) {
$irc->yield(privmsg => $nick => "Ce nick n'est associé à aucun login arise. Va sur http://nightiies.iiens.net/links/fav pour obtenir ton code personel.");
}
else {
my $sth2 = $dbh->prepare_cached('INSERT INTO playbot_fav (id, user) VALUES (?, ?)');
$sth2->execute($id, $sth->fetch->[0])
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
}
}
elsif ($msg =~ /^!later(?: ([0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) {
my ($id, $time, $unit) = ($1, $2, $3);
$id = $lastID if (!$id);
$time = 6 if (!$time);
$time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600;
$kernel->delay_set('_later', $time, $nick, $id);
}
elsif ($msg =~ /^!tag( +([0-9]+))?/) {
my $id = ($2) ? $2 : $lastID;
while ($msg =~ /#([a-zA-Z0-9_-]+)/g) {
addTag($id, $1);
}
}
elsif ($msg =~ /^!help/) {
$irc->yield(privmsg => $chan => '!fav [<id>] : enregistre la vidéo dans les favoris');
$irc->yield(privmsg => $chan => '!tag [<id>] <tag1> <tag2> ... : tag la vidéo');
$irc->yield(privmsg => $chan => '!later [<id>] [in <x>[s|m|h]] : vidéo rappelée par query (par défaut temps de 6h)');
$irc->yield(privmsg => $chan => 'Sans id précisée, la dernière vidéo postée est utilisée.');
commands::parser::exec(@args);
}
}
......
package commands::parser;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec irc);
use lib "$FindBin::Bin/lib/commands/";
#use fav;
#use later;
#use tag;
#use help;
our $irc;
our $dbh;
sub exec {
my ($kernel, $user, $chan, $msg) = @_;
my ($nick,$mask) = split(/!/,$user);
if ($msg =~ /^!fav( ([0-9]+))?/) {
my $id = ($2) ? $2 : $lastID;
my $sth = $dbh->prepare_cached('SELECT user FROM playbot_codes WHERE nick = ?');
$sth->execute($nick)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
if (!$sth->rows) {
$irc->yield(privmsg => $nick => "Ce nick n'est associé à aucun login arise. Va sur http://nightiies.iiens.net/links/fav pour obtenir ton code personel.");
}
else {
my $sth2 = $dbh->prepare_cached('INSERT INTO playbot_fav (id, user) VALUES (?, ?)');
$sth2->execute($id, $sth->fetch->[0])
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
}
}
elsif ($msg =~ /^!later(?: ([0-9]+))?(?: in ([0-9]*)?(h|m|s)?)?/) {
my ($id, $time, $unit) = ($1, $2, $3);
$id = $lastID if (!$id);
$time = 6 if (!$time);
$time *= ($unit eq 's') ? 1 : ($unit eq 'm') ? 60 : 3600;
$kernel->delay_set('_later', $time, $nick, $id);
}
elsif ($msg =~ /^!tag( +([0-9]+))?/) {
my $id = ($2) ? $2 : $lastID;
while ($msg =~ /#([a-zA-Z0-9_-]+)/g) {
addTag($id, $1);
}
}
elsif ($msg =~ /^!help/) {
$irc->yield(privmsg => $chan => '!fav [<id>] : enregistre la vidéo dans les favoris');
$irc->yield(privmsg => $chan => '!tag [<id>] <tag1> <tag2> ... : tag la vidéo');
$irc->yield(privmsg => $chan => '!later [<id>] [in <x>[s|m|h]] : vidéo rappelée par query (par défaut temps de 6h)');
$irc->yield(privmsg => $chan => 'Sans id précisée, la dernière vidéo postée est utilisée.');
}
}
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