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

Sam::commands::chan handles unconfigured chans

parent 10f6ef2c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -13,9 +13,14 @@ our $log; ...@@ -13,9 +13,14 @@ our $log;
our $irc; our $irc;
sub exec { sub exec {
my $chan = shift; my $chanName = shift;
my $calendar_id = Sam::Chan->new(name => $chan)->load->calendar_id; my $chan = Sam::Chan->new(name => $chanName);
unless ($chan->load(speculative => 1)) {
die "ce chan n'est pas encore configuré";
}
my $calendar_id = $chan->load->calendar_id;
my $events = Sam::Event::Manager->get_events( my $events = Sam::Event::Manager->get_events(
query => query =>
[ [
...@@ -23,11 +28,11 @@ sub exec { ...@@ -23,11 +28,11 @@ sub exec {
'calendar_id' => $calendar_id, 'calendar_id' => $calendar_id,
], ],
sort_by => 'date', sort_by => 'date',
limit => ($chan =~ /^#/) ? 2 : 10, limit => ($chanName =~ /^#/) ? 2 : 10,
); );
if (scalar @{$events} == 0) { if (scalar @{$events} == 0) {
$irc->yield(privmsg => $chan => "Aucune soirée à venir enregistrée, on se fait bien chier…"); $irc->yield(privmsg => $chanName => "Aucune soirée à venir enregistrée, on se fait bien chier…");
return; return;
} }
...@@ -37,7 +42,7 @@ sub exec { ...@@ -37,7 +42,7 @@ sub exec {
$msg .= " @ ".$_->place if ($_->place); $msg .= " @ ".$_->place if ($_->place);
$msg .= " : ".$_->description if ($_->description); $msg .= " : ".$_->description if ($_->description);
$msg .= " <".$_->link.">" if ($_->link); $msg .= " <".$_->link.">" if ($_->link);
$irc->yield(privmsg => $chan => $msg); $irc->yield(privmsg => $chanName => $msg);
} }
my $events_nb = Sam::Event::Manager->get_events_count( my $events_nb = Sam::Event::Manager->get_events_count(
...@@ -45,7 +50,7 @@ sub exec { ...@@ -45,7 +50,7 @@ sub exec {
); );
$events_nb -= 2; $events_nb -= 2;
$events_nb -= 8 if ($chan !~ /^#/); # query $events_nb -= 8 if ($chanName !~ /^#/); # query
if ($events_nb > 0) { if ($events_nb > 0) {
my $msg = $events_nb . " autre"; my $msg = $events_nb . " autre";
...@@ -53,7 +58,7 @@ sub exec { ...@@ -53,7 +58,7 @@ sub exec {
$msg .= " soirée"; $msg .= " soirée";
$msg .= "s" if ($events_nb > 1); $msg .= "s" if ($events_nb > 1);
$msg .= " sur http://nightiies.iiens.net/sam/"; $msg .= " sur http://nightiies.iiens.net/sam/";
$irc->yield(privmsg => $chan => $msg); $irc->yield(privmsg => $chanName => $msg);
} }
} }
......
...@@ -108,7 +108,13 @@ sub exec { ...@@ -108,7 +108,13 @@ sub exec {
} }
} }
elsif ($msg =~ /^Sam(?:,|:) +liste/) { elsif ($msg =~ /^Sam(?:,|:) +liste/) {
eval {
Sam::commands::list::exec($chan->[0]); Sam::commands::list::exec($chan->[0]);
};
if ($@) {
$irc->yield(privmsg => $chan => "Erreur : $@");
}
} }
elsif ($msg =~ /^Sam(?:,|:) +(help|aide)/) { elsif ($msg =~ /^Sam(?:,|:) +(help|aide)/) {
$irc->yield(privmsg => $nick => 'Sam: <titre de la soirée> le jj/mm/aa @ <salle/lieu> : <description>'); $irc->yield(privmsg => $nick => 'Sam: <titre de la soirée> le jj/mm/aa @ <salle/lieu> : <description>');
......
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