Sélectionner une révision Git
-
Alexandre Morignot a rédigéAlexandre Morignot a rédigé
parser.pm 5,61 Kio
package Sam::commands::parser;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(exec);
use strict;
use Sam::commands::add;
use Sam::commands::list;
use Sam::commands::addUser;
use Sam::commands::edit;
use Sam::commands::getUsers;
my $nick;
my $irc;
my $lastID;
sub setConf {
my ($nickNew, $ircNew, $dbh, $log, $lastIDnew) = @_;
$Sam::commands::addUser::dbh = $dbh;
$Sam::commands::getUsers::dbh = $dbh;
$Sam::commands::add::log = $log;
$Sam::commands::list::log = $log;
$Sam::commands::addUser::log = $log;
$Sam::commands::edit::log = $log;
$Sam::commands::getUsers::log = $log;
$Sam::commands::list::irc = $ircNew;
$Sam::commands::addUser::irc = $ircNew;
$Sam::commands::edit::irc = $ircNew;
$Sam::commands::getUsers::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);
$current_mon++; # localtime returns month between 0 and 11
$current_year += 1900; # same shit
my ($title, $place, $desc) = ($+{'title'}, $+{'place'}, $+{'desc'});
my ($day, $month, $year) = ($+{'day'}, $+{'month'} || $current_mon, $+{'year'} || $current_year);
$place =~ s/ $//;
my $id;
eval {
$id = Sam::commands::add::exec($chan->[0], $title, $day, $month, $year, $place, $desc);