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

conf.pm

Blame
  • conf.pm 1,70 Kio
    package PlayBot::commands::conf;
    
    use strict;
    use warnings;
    use utf8;
    
    use Module::Pluggable
      sub_name    => 'sites',
      search_path => ['PlayBot::sites'],
      require     => 1;
    
    use PlayBot::utils::print;
    use PlayBot::utils::db;
    use PlayBot::utils::db::chan;
    
    our $irc;
    
    sub exec {
        my ( $chan, $nick, $cmd, @args ) = @_;
        print "$chan, $nick, $cmd, " . join( '+', @args ) . "\n";
        my $msg = 'done';
    
        if ( not $irc->is_channel_operator( $chan, $nick ) ) {
            $irc->yield( privmsg => $chan => "C'est non." );
            return;
        }
    
        if ( $cmd eq 'list' ) {
            my $sites = list($chan);
            my @list;
    
            foreach ( keys %$sites ) {
                $_ .= '*' if ( $sites->{$_} );
    
                push @list, $_;
            }
    
            $msg = join( ' ', @list );
        }
        elsif ( $cmd eq 'add' ) {
            add( $chan, @args );
        }
        elsif ( $cmd eq 'remove' ) {
            remove( $chan, @args );
        }
        else {
            die;
        }
    
        $irc->yield( privmsg => $chan => $msg );
    }
    
    sub list {
        my $chan = shift;
    
        my $chan_conf = PlayBot::utils::db::chan->new($chan);
        my $sites     = {};
    
        foreach my $site ( __PACKAGE__->sites ) {
            $site = ( split( /::/, $site ) )[-1];
            if ( grep { $site eq $_ } @{ $chan_conf->sites } ) {
                $sites->{$site} = 1;
            }
            else {
                $sites->{$site} = 0;
            }
        }
    
        return $sites;
    }