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

getUsers : qui va à la xxx ?

parent c07488ae
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package commands::getUsers;
our $dbh;
our $log;
our $irc;
my @insultes = ("Ahahahah ! 23 à 0 !", "C'est la piquette, Jack !", "Tu sais pas jouer, Jack !", "T'es mauvais, Jack !");
sub exec {
my ($chan, $id) = @_;
my $sth;
$sth = $dbh->prepare_cached('
SELECT sam.title, sam_users.nick
FROM sam LEFT OUTER JOIN sam_users
ON sam.id = sam_users.event
WHERE sam.id = ?
');
unless (defined $sth) {
$log->error("Couldn't prepare querie; aborting");
return;
}
$sth->execute($id)
or $log->error("Couldn't finish transaction: " . $dbh->errstr);
# FIXME
# mixsql specific trick
if (!$sth->rows) {
$irc->yield(privmsg => $chan => $insultes[rand @insultes]);
return;
}
my $row = $sth->fetch;
my $title = $row->[0];
my @users;
do {
push @users, $row->[1] if $row->[1];
} while ($row = $sth->fetch);
my $msg;
if (scalar @users) {
$msg = $title;
$msg .= ' : ';
foreach (@users) {
$msg .= $_;
$msg .= ' ';
}
} else {
$msg = "Personne ne va à la soirée $title :(";
}
$irc->yield(privmsg => $chan => $msg);
return $id;
}
1;
......@@ -11,6 +11,7 @@ use commands::add;
use commands::list;
use commands::addUser;
use commands::edit;
use commands::getUsers;
my $nick;
my $irc;
......@@ -23,15 +24,18 @@ sub setConf {
$commands::list::dbh = $dbh;
$commands::addUser::dbh = $dbh;
$commands::edit::dbh = $dbh;
$commands::getUsers::dbh = $dbh;
$commands::add::log = $log;
$commands::list::log = $log;
$commands::addUser::log = $log;
$commands::edit::log = $log;
$commands::getUsers::log = $log;
$commands::list::irc = $ircNew;
$commands::addUser::irc = $ircNew;
$commands::edit::irc = $ircNew;
$commands::getUsers::irc = $ircNew;
$nick = $nickNew;
$irc = $ircNew;
......@@ -83,6 +87,13 @@ sub exec {
elsif ($msg =~ /^Sam(?:,|:) +je +vais +à +la +(\d+)/) {
commands::addUser::exec($nick, $1, $chan);
}
elsif ($msg =~ /^Sam(?:,|:) +qui +va +à +la +(\d+) +?/) {
my $id = commands::getUsers::exec($chan->[0], $1);
if ($id) {
$lastID->{$chan->[0]} = $id;
}
}
elsif ($msg =~ /^Sam(?:,|:) +liste/) {
commands::list::exec($chan);
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter