Skip to content
Extraits de code Groupes Projets
Valider 37192712 rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Add !conf command

parent 274b27c1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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;
......@@ -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]);
......
......@@ -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,
......
......@@ -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));
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter