Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 1abb7c35a37945be531683062ef803147bef8f14
  • master par défaut
  • cinch
  • ruby
  • gh-pages
  • v1.0.0
6 résultats

parser.pm

Blame
  • parser.pm 4,89 Kio
    package PlayBot::commands::parser;
    
    use strict;
    use Try::Tiny;
    
    use PlayBot::commands::fav;
    use PlayBot::commands::later;
    use PlayBot::commands::tag;
    use PlayBot::commands::get;
    use PlayBot::commands::stats;
    use PlayBot::utils::id;
    
    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 !");
    
    # store a chan last command
    my %command;
    
    sub setConf {
        my ($ircNew, $dbhNew, $log, $lastIDnew) = @_;
    
        $PlayBot::commands::fav::dbh = $dbhNew;
        $PlayBot::commands::tag::dbh = $dbhNew;
        $PlayBot::commands::later::dbh = $dbhNew;
        $PlayBot::utils::id::dbh = $dbhNew;
    
        $PlayBot::commands::fav::log = $log;
        $PlayBot::commands::tag::log = $log;
        $PlayBot::commands::get::log = $log;
        $PlayBot::commands::later::log = $log;
        $PlayBot::utils::id::log = $log;
    
        $PlayBot::commands::fav::irc = $ircNew;
        $PlayBot::commands::get::irc = $ircNew;
        $PlayBot::commands::stats::irc = $ircNew;
    
        $lastID = $lastIDnew;
        $irc = $ircNew;
        $dbh = $dbhNew;
    }
    
    sub exec {
    	my ($kernel, $user, $chan, $msg) = @_;
    	my ($nick, $mask) = split(/!/,$user);
    
        if ($msg eq '!' and $command{$chan}) {
            $msg = $command{$chan};
        }
    
        if ($msg =~ /^ *!fav(?: (\S+))? *$/) {
            my $index = $1;
            try {
                my $id = PlayBot::utils::id::get($chan, $index);
                PlayBot::commands::fav::exec($nick, $id)
            } catch {
                $irc->yield(privmsg => $chan => $insultes[rand @insultes]);
            }
    	}
    	elsif ($msg =~ /^ *!later(?: (\S+))?(?: in (\d+)(h|m|s)?)? *$/) {
            my $index = $1;
            my ($time, $unit) = ($2, $3);
    
            try {
                my $id = PlayBot::utils::id::get($chan, $index);
                PlayBot::commands::later::exec($kernel, $nick, $id, $chan, $time, $unit);
            } catch {
                $irc->yield(privmsg => $chan => $insultes[rand @insultes]);