diff --git a/PlayBot/commands/broken.pm b/PlayBot/commands/broken.pm new file mode 100644 index 0000000000000000000000000000000000000000..07bdb283a9514b2d2136fb6e11d5adfa67a9df35 --- /dev/null +++ b/PlayBot/commands/broken.pm @@ -0,0 +1,89 @@ +package PlayBot::commands::broken; + +use strict; +use warnings; + +use PlayBot::utils::db; +use PlayBot::utils::db::get; +use PlayBot::utils::print; + +use Try::Tiny; + +sub exec { + my ($chan, $id) = @_; + my $dbh = PlayBot::utils::db::main_session; + + my $query = PlayBot::commands::get::query->new( + chan => $chan, + query => $id, + ); + my $db_query = PlayBot::utils::db::get->new(); + my $content = $db_query->get($query); + + die("La cuillère n'existe pas\n") if (not $content); + + if (not $content->{external_id}) + { + return "Cette feature n'est pas encore disponible pour ce contenu"; + } + + + my $content_r; + try + { + my $site = 'PlayBot::sites::'.$content->{site}; + eval "require $site"; + my %h = $site->get($content->{external_id}); + $content_r = \%h; + } + catch + { + # mark as broken + # TODO: be more subtil + my $sth = $dbh->prepare(' + UPDATE playbot + SET broken = 1 + WHERE type = ? AND external_id = ? + '); + $sth->execute($content->{site}, $content->{external_id}); + $dbh->commit; + die "Monde de merde\n"; + }; + + try + { + foreach my $k (keys %$content_r) + { + die if($content_r->{$k} ne $content->{$k}); + } + } + catch + { + # the content needs an update + my $sth = $dbh->prepare(' + UPDATE playbot SET + sender = ?, + title = ?, + duration = ?, + url = ? + WHERE type = ? AND external_id = ? + '); + $sth->execute( + $content_r->{author}, + $content_r->{title}, + $content_r->{duration}, + $content_r->{url}, + $content_r->{site}, + $content_r->{external_id}, + ); + $dbh->commit; + + my $msg = PlayBot::utils::print::print($content); + die"Ça, c’est bon, c’est réparé\n$msg\n"; + }; + + return "http://chezmoicamarche.org/"; +} + + +1; diff --git a/PlayBot/commands/parser.pm b/PlayBot/commands/parser.pm index c953c660effe9e408a5b1b733a25d8064fe3880d..b55cfc633215f6a8560e8cee9231eea0062cfbb3 100644 --- a/PlayBot/commands/parser.pm +++ b/PlayBot/commands/parser.pm @@ -5,11 +5,11 @@ 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; use PlayBot::commands::get; +use PlayBot::commands::broken; use PlayBot::commands::stats; use PlayBot::utils::id; @@ -102,6 +102,23 @@ sub exec { $lastID->{$chan} = $id; } } + elsif ($msg =~ /^ *!broken(?: (\S+))? *$/) { + my $index = $1; + try { + my $id = PlayBot::utils::id::get($chan, $index); + + my @msg; + try { + @msg = PlayBot::commands::broken::exec($chan, $id); + } catch { + @msg = split(/\n/, $_); + }; + + $irc->yield(privmsg => $chan => $_) foreach (@msg); + } catch { + $irc->yield(privmsg => $chan => $insultes[rand @insultes]); + }; + } elsif ($msg =~ /^ *!stats(?: (\S+))? *$/) { my $index = $1; try { @@ -109,7 +126,7 @@ sub exec { PlayBot::commands::stats::exec($chan, $id) } catch { $irc->yield(privmsg => $chan => $insultes[rand @insultes]); - } + }; } elsif ($msg =~ /^ *!conf +(.*)/) { my @args = split(/ +/, $1); @@ -124,6 +141,7 @@ 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 => "!broken [<id>] : marque un contenu comme indisponible"); $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 ».");