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

Nouvelle commande edit

parent c9d1f783
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package commands::edit;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec);
use Regexp::Common qw(URI);
our $dbh;
our $log;
our $irc;
sub exec {
my ($id, $command, $arg, $chan) = @_;
my $saveCommit = $dbh->{AutoCommit};
my $saveError = $dbh->{RaiseError};
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
if ($command eq "lien") {
if ($arg !~ /^$RE{URI}{HTTP}{-scheme => qr(https?)}$/) {
$irc->yield(privmsg => $chan => "Ce n'est pas une url valide");
}
else {
eval {
$sth = $dbh->prepare_cached("UPDATE sam SET link = ? WHERE id = ?");
$sth->execute($arg, $id);
if ($sth->rows == 0) {
$irc->yield(privmsg => $chan => "Aucune soirée trouvée avec cet identifiant");
}
else {
$irc->yield(privmsg => $chan => "Oui chef !");
}
$dbh->commit;
};
if ($@) {
$log->error("Quelque chose a chié dans la transaction : $@");
$dbh->rollback;
$irc->yield(privmsg => $chan => "Erreur, commande non exécutée");
}
}
}
else {
$irc->yield(privmsg => $chan => "Commande inconnue");
}
$dbh->{AutoCommit} = $saveCommit;
$dbh->{RaiseError} = $saveError;
}
1;
......@@ -10,6 +10,7 @@ use lib "$FindBin::Bin/lib/";
use commands::add;
use commands::list;
use commands::addUser;
use commands::edit;
my $nick;
my $irc;
......@@ -21,13 +22,16 @@ sub setConf {
$commands::add::dbh = $dbh;
$commands::list::dbh = $dbh;
$commands::addUser::dbh = $dbh;
$commands::edit::dbh = $dbh;
$commands::add::log = $log;
$commands::list::log = $log;
$commands::addUser::log = $log;
$commands::edit::log = $log;
$commands::list::irc = $ircNew;
$commands::addUser::irc = $ircNew;
$commands::edit::irc = $irc;
$nick = $nickNew;
$irc = $ircNew;
......@@ -54,6 +58,13 @@ sub exec {
$irc->yield(privmsg => $chan => "C'est enregistré. N'oubliez pas, conduire ou choisir, il faut boire !");
}
}
elsif ($msg =~ /^Sam(?:,|:) +ajoute(?: +à +la +(\d+)) +: +([a-z]*) += +(.*)/) {
my $id = $1 or $lastID->{$chan->[0]};
my $command = $2;
my $arg = $3;
commands::edit::exec($id, $command, $arg, $chan);
}
elsif ($msg =~ /^Sam(?:,|:) +j'y +vais/) {
commands::addUser::exec($nick, $lastID->{$chan->[0]}, $chan);
}
......@@ -72,7 +83,10 @@ sub exec {
$irc->yield(privmsg => $nick => " vous ajoute aux participants de la dernière soirée postée");
$irc->yield(privmsg => $nick => 'Sam: liste');
$irc->yield(privmsg => $nick => ' retourne les deux prochaines soirées');
$irc->yield(privmsg => $nick => "--------");
$irc->yield(privmsg => $nick => 'Sam: ajoute [à la <id de la soirée>] : <attribut> = <valeur>');
$irc->yield(privmsg => $nick => ' <attribut> peut valoir les valeurs suivantes :');
$irc->yield(privmsg => $nick => ' - lien');
$irc->yield(privmsg => $nick => "------------------");
$irc->yield(privmsg => $nick => 'Notes :');
$irc->yield(privmsg => $nick => ' - « Sam: » ou « Sam, » fonctionnent');
$irc->yield(privmsg => $nick => " - la date peut être au format « jj/mm » ou simplement « jj » (le mois et / ou l'année courante sera alors utilisé)");
......@@ -80,7 +94,7 @@ sub exec {
$irc->yield(privmsg => $nick => " - pensez à vérifier au préalable que la soirée n'a pas déjà été ajoutée");
$irc->yield(privmsg => $nick => " - « liste » en query retourne toutes les prochaines soirées");
$irc->yield(privmsg => $nick => " - tu as perdu") if (int(rand(10)) == 5);
$irc->yield(privmsg => $nick => "--------");
$irc->yield(privmsg => $nick => "------------------");
$irc->yield(privmsg => $nick => "http://nightiies.iiens.net/sam/ (si t'es motivé pour dev un vrai site, /query moise)");
$irc->yield(privmsg => $nick => "Calendrier ICS : http://nigthiies.iiens.net/sam/events.php (ajoute « ?nick=$nick » à la fin de l'URL pour n'avoir que les soirées où tu te rends)");
}
......
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