diff --git a/lib/commands/parser.pm b/lib/commands/parser.pm index 9dc60689951ab1207c5c9fffc73f3411a1a5a9c2..70e57f84e5b95bbcab57155feeadbfd90990f9eb 100644 --- a/lib/commands/parser.pm +++ b/lib/commands/parser.pm @@ -14,6 +14,8 @@ my $lastID; my $irc; my $dbh; +my @insultes = ("Ahahahah ! 23 à 0 !", "C'est la piquette, Jack !", "Tu sais pas jouer, Jack !", "T'es mauvais, Jack !"); + sub setConf { my ($ircNew, $dbhNew, $log, $lastIDnew) = @_; @@ -65,18 +67,24 @@ sub exec { commands::later::exec($kernel, $nick, $id, $offset, $chan, $time, $unit); } - elsif ($msg =~ /^( *!tag)(?:( +)([0-9]+))?/) { - my $id = $3; + elsif ($msg =~ /^( *!tag)(?:( +)(-?[0-9]+))?/) { + my $index = $3; + my $id; - if ($id) { - $msg = substr $msg, (length $1) + (length $2) + (length $id); + if ($3) { + $msg = substr $msg, (length $1) + (length $2) + (length $3); } else { - $id = $lastID->{$chan->[0]}; $msg = substr $msg, (length $1) + (length $2); } - commands::tag::exec($id, $msg); + try { + $id = utils::id::get($chan->[0], $index); + commands::tag::exec($id, $msg); + } catch { + $irc->yield(privmsg => $chan->[0] => $insultes[rand @insultes]); + return 1; + }; } elsif ($msg =~ /^( *!get)(?: +.*)?$/) { $msg = substr $msg, (length $1) + 1;