diff --git a/PlayBot/commands/conf.pm b/PlayBot/commands/conf.pm new file mode 100644 index 0000000000000000000000000000000000000000..b2ab65068e13694b1a9ee9bb95f03b943863d7a6 --- /dev/null +++ b/PlayBot/commands/conf.pm @@ -0,0 +1,104 @@ +package PlayBot::commands::conf; + +use strict; +use warnings; + +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; +} + + +sub add +{ + my ($chan, @sites) = @_; + my $chan_conf = PlayBot::utils::db::chan->new($chan); + + foreach (@sites) + { + $chan_conf->add_site($_); + } +} + + +sub remove +{ + my ($chan, @sites) = @_; + my $chan_conf = PlayBot::utils::db::chan->new($chan); + + foreach (@sites) + { + $chan_conf->remove_site($_); + } +} + +1; diff --git a/PlayBot/commands/parser.pm b/PlayBot/commands/parser.pm index 35c97605070e262f864989610f35645594d61410..5793e38df8ce2c18e9442297c671c5f97e154285 100644 --- a/PlayBot/commands/parser.pm +++ b/PlayBot/commands/parser.pm @@ -4,6 +4,8 @@ use strict; use warnings; use Try::Tiny; +use PlayBot::commands::conf; +use PlayBot::commands::stats; use PlayBot::commands::fav; use PlayBot::commands::later; use PlayBot::commands::tag; @@ -34,6 +36,7 @@ sub setConf { $PlayBot::commands::later::log = $log; $PlayBot::utils::id::log = $log; + $PlayBot::commands::conf::irc = $ircNew; $PlayBot::commands::fav::irc = $ircNew; $PlayBot::commands::get::irc = $ircNew; $PlayBot::commands::stats::irc = $ircNew; @@ -108,6 +111,10 @@ sub exec { $irc->yield(privmsg => $chan => $insultes[rand @insultes]); } } + elsif ($msg =~ /^ *!conf +(.*)/) { + my @args = split(/ +/, $1); + PlayBot::commands::conf::exec($chan, $nick, @args); + } elsif ($msg =~ /^ *!help/) { $irc->yield(privmsg => $nick => '!fav [<id>] : enregistre la vidéo dans les favoris'); $irc->yield(privmsg => $nick => '!tag [<id>] <tag1> <tag2> ... : tag la vidéo'); @@ -117,9 +124,16 @@ sub exec { $irc->yield(privmsg => $nick => '!get [<id>|<query>] : sort aléatoirement une vidéo'); $irc->yield(privmsg => $nick => ' Si un id est précisé, sort ce contenu (s\'il existe).'); $irc->yield(privmsg => $nick => ' <query> : composée de tags commençant par un \'#\' ou de mots. Les mots sont recherché dans le titre ainsi que le nom de l\'auteur du contenu.'); + $irc->yield(privmsg => $nick => "!stats [<id>] : informations sur un contenu"); + $irc->yield(privmsg => $nick => "---"); $irc->yield(privmsg => $nick => "Un tag est de la forme « #[a-zA-Z0-9_]+ ». Par exemple « #loLILol_mdr42 » est un tag valide, tandis que « #céducaca » et « #je-suis-nul » n'en sont pas et seront considéré respectivement comme « #c » et « #je »."); - $irc->yield(privmsg => $nick => "Toutes les commandes fonctionnent en query."); - $irc->yield(privmsg => $nick => 'Niveau vie privée, potentiellement toute commande (excepté !help) entraine un enregistrement dans la base de données avec au minimum la date et l\'heure et le nick de la personne ayant exécuté la commande.'); + $irc->yield(privmsg => $nick => "Toutes ces commandes fonctionnent en query."); + $irc->yield(privmsg => $nick => "---"); + $irc->yield(privmsg => $nick => "Configuration d'un channel, utilisable uniquement par un op :"); + $irc->yield(privmsg => $nick => " !conf list : liste les sites supportés, ceux indiqués avec une astérisque étant activés"); + $irc->yield(privmsg => $nick => " !conf add|remove <site> : active ou désactive le support d'un site"); + $irc->yield(privmsg => $nick => "---"); + $irc->yield(privmsg => $nick => "Niveau vie privée, !fav, !later, et bien sûr poster un lien supporté entrainent un enregistrement dans la base de données avec au minimum la date, l'heure et le nick de la personne ayant exécuté la commande."); } elsif ($msg =~/^ *!(fav|lat|tag|stats)/) { $irc->yield(privmsg => $chan => $insultes[rand @insultes]); diff --git a/PlayBot/sessions/irc.pm b/PlayBot/sessions/irc.pm index dcadc253866645bf19c2125cc8c616a2a54e2fe5..b5147d48436278dc87f43abded22029b44aab881 100644 --- a/PlayBot/sessions/irc.pm +++ b/PlayBot/sessions/irc.pm @@ -5,7 +5,7 @@ use warnings; use DBI; use POE; -use POE::Component::IRC; +use POE::Component::IRC::State; use POSIX 'strftime'; use Tie::File; use JSON; @@ -24,7 +24,7 @@ my $json = <CONF>; my $conf = decode_json($json); ## CONNEXION -my ($irc) = POE::Component::IRC->spawn(); +my ($irc) = POE::Component::IRC::State->spawn(); my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $conf->{'user'}, $conf->{'passwd'}, { PrintError => 0, AutoCommit => 1, diff --git a/PlayBot/utils/db/chan.pm b/PlayBot/utils/db/chan.pm index f62c4ab645a44c87307cba968c07799303631cdb..b37c7778427e26139ea9f01e691f3a5064f3f8f1 100644 --- a/PlayBot/utils/db/chan.pm +++ b/PlayBot/utils/db/chan.pm @@ -91,7 +91,7 @@ sub _update_db my $dbh = PlayBot::utils::db::main_session; my $sth = $dbh->prepare(' update playbot_config - set site = ? + set sites = ? '); $sth->execute(encode_json($sites));