Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 9e210f6a2487af8e382e0c3e776b188f0f826b69
  • master par défaut protégée
  • rust-playlist-sync
  • rust
  • fix-qt-deprecated-qvariant-type
  • fix-mpris-qtwindow-race-condition
  • rust-appimage-wayland
  • windows-build-rebased
  • v2.5 protégée
  • v2.4 protégée
  • v2.3-1 protégée
  • v2.3 protégée
  • v2.2 protégée
  • v2.1 protégée
  • v2.0 protégée
  • v1.8-3 protégée
  • v1.8-2 protégée
  • v1.8-1 protégée
  • v1.8 protégée
  • v1.7 protégée
  • v1.6 protégée
  • v1.5 protégée
  • v1.4 protégée
  • v1.3 protégée
  • v1.2 protégée
  • v1.1 protégée
  • v1.0 protégée
27 résultats

module_repo.c

Blame
  • get.pm 4,99 Kio
    package commands::get;
    
    use strict;
    use warnings;
    use Scalar::Util qw(looks_like_number);
    
    use lib "$FindBin::Bin/lib/";
    use utils::print;
    use utils::db;
    
    our $dbh;
    our $irc;
    our $log;
    
    my $last_req;
    my $sth;
    
    sub exec {
    	my ($kernel, $nick, $chan, $msg) = @_;
    
        # if we are in a query or arg -all, we search in all the channels
        my $all = 0;
        $all = 1 if ($chan->[0] !~ /^#/ || $msg =~ s/-a(ll)?//);
    
        my @tags = ($msg =~ /#([a-zA-Z0-9_-]+)/g);
        my $content;
        my $req;
        my $rows;
    
        my @words = ($msg =~ /(?:^| )([^#\s]+)/g);
    
        if (not defined $last_req or $msg ne $last_req) {
            my $dbh = utils::db::get_session;
    
            my @words_param;
            foreach (@words) {
                unshift @words_param, '%'.$_.'%';
            }
    
            my $words_sql;
            foreach (@words) {
                $words_sql .= ' and ' if ($words_sql);
                $words_sql .= "concat(sender, ' ', title) like ?";
            }
    
            if (@words && looks_like_number($words[0])) {
                $sth = $dbh->prepare('select id, sender, title, url, duration
                    from playbot
                    where id = ?');
                $sth->execute($words[0]);
            }
            elsif (@tags) {
                my $params = join ', ' => ('?') x @tags;
    
                if ($all) {
                    $req = 'select id, sender, title, url, duration
                        from playbot
                        natural join playbot_tags
                        where tag in ('.$params.')';
                    $req .= ' and '.$words_sql if ($words_sql);
                    $req .= ' group by id
                        having count(*) >= ?
                        order by rand()';
    
                    $sth = $dbh->prepare($req);
                    $sth->execute(@tags, @words_param, scalar @tags);
                }
                else {
                    $req = 'select p.id, p.sender, p.title, p.url, duration
                        from playbot p