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

get.pm

Blame
  • get.pm 3,00 Kio
    package PlayBot::commands::get;
    
    use strict;
    use warnings;
    use utf8;
    
    use PlayBot::utils::print;
    use PlayBot::utils::db;
    use PlayBot::utils::db::get;
    
    use PlayBot::commands::get::query;
    
    our $irc;
    our $log;
    
    sub exec {
    	my ($chan, $msg, $chan_src) = @_;
    
        my $query = PlayBot::commands::get::query->new(
            chan => $chan,
            query  => ($msg) ? $msg : ''
        );
    
        my $db_query = PlayBot::utils::db::get->new();
        my $rows = $db_query->get_rows($query);
    
        if (scalar @{$query->tags} == 0
                and scalar @{$query->words} > 0
                and $query->id == -1
                and $rows > 10
                and not $query->force)
        {
            $irc->yield(privmsg => $chan => "trop de résultats ($rows), utiliser -f pour forcer la recherche");
            return;
        }
    
        my $content = $db_query->get($query);
    
        if (!$content) {
            if ($rows > 0) {
                # the request was already executed, there is nothing more
                $irc->yield(privmsg => $chan => "Tu tournes en rond, Jack !");
            }
            elsif (@{$query->words} or @{$query->tags}) {
                $msg = "Je n'ai rien dans ce registre.";
    
                if (not $query->is_global) {
                    # we check is there is result with global
                    my $q = PlayBot::commands::get::query->new(
                        chan => $query->chan,
                        query  => $query->query . ' -a'
                    );
    
                    my $rows = $db_query->get_rows($q);
                    if ($rows > 0) {
                        $msg .= ' ' . $rows . ' résultat';
                        $msg .= 's' if ($rows > 1);
                        $msg .= ' trouvé';
                        $msg .= 's' if ($rows > 1);
                        $msg .= ' avec une recherche globale.';
                    }
    
                }
    
                $irc->yield(privmsg => $chan => $msg);
            }
            else {
                $irc->yield(privmsg => $chan => "Poste d'abord du contenu, n00b.");
            }