Sélectionner une révision Git
-
Alexandre Morignot a rédigéAlexandre Morignot a rédigé
parser.pm 4,83 Kio
package commands::parser;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec);
use strict;
use lib "$FindBin::Bin/lib/";
use commands::add;
use commands::list;
use commands::addUser;
use commands::edit;
my $nick;
my $irc;
my $lastID;
sub setConf {
my ($nickNew, $ircNew, $dbh, $log, $lastIDnew) = @_;
$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 = $ircNew;
$nick = $nickNew;
$irc = $ircNew;
$lastID = $lastIDnew;
}
sub exec {
my ($kernel, $user, $chan, $msg) = @_;
my ($nick, $mask) = split(/!/,$user);
my $re_place_t ="\\ +@\\ +(?<place>[^:]*)";
# see doc/regex.png for an visualisation of this regex
if ($msg =~ m=^Sam(?:,|:) # hl
\ +(?<add_user>je\ +(vais|viens)\ +à\ +)? # add_user
(?<title>[^@]+) # title
(?<place_t>$re_place_t)? # place
\ +le\ +(?<day>\d?\d) # day
(/(?<month>\d?\d) # month
(/(?<year>(\d\d)?\d\d))?)? # year
(?(<place_t>)|($re_place_t)?) # place (only if not match the 1st time)
(\ *:\ +(?<desc>.*))? # description
=xi) {
my (undef, undef, undef, undef, $current_mon, $current_year, undef, undef, undef) =
localtime(time);
my ($title, $place, $desc) = ($+{'title'}, $+{'place'}, $+{'desc'});
my ($day, $month, $year) = ($+{'day'}, $+{'month'} || $current_mon, $+{'year'} || $current_year);
$place =~ s/ $//;
my $id = commands::add::exec($title, $day, $month, $year, $place, $desc);
if ($id) {
$lastID->{$chan->[0]} = $id;
$irc->yield(privmsg => $chan => "C'est enregistré. N'oubliez pas, conduire ou choisir, il faut boire !");