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

blob

parent 4ee959e2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -50,7 +50,7 @@ sub exec { ...@@ -50,7 +50,7 @@ sub exec {
# we check is there is result with global # we check is there is result with global
my $q = PlayBot::commands::get::query->new( my $q = PlayBot::commands::get::query->new(
chan => $query->chan, chan => $query->chan,
query => $query->query . ' -a' query => $query->query . ' -a',
fts => $fts, fts => $fts,
); );
......
...@@ -34,7 +34,7 @@ my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $co ...@@ -34,7 +34,7 @@ my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $co
or die("Couldn't connect to database: ".DBI->errstr); or die("Couldn't connect to database: ".DBI->errstr);
# config # config
my $serveur = 'irc.iiens.net'; my $serveur = '193.54.225.86';
my $nick = $conf->{'nick'}; my $nick = $conf->{'nick'};
my $port = 6667; my $port = 6667;
my $ircname = 'nightiies'; my $ircname = 'nightiies';
...@@ -129,7 +129,9 @@ sub bot_start { ...@@ -129,7 +129,9 @@ sub bot_start {
my $kernel = $_[KERNEL]; my $kernel = $_[KERNEL];
$kernel->alias_set('bot'); $kernel->alias_set('bot');
$log->info("register all");
$irc->yield(register => "all"); $irc->yield(register => "all");
$log->info("connecting");
$irc->yield( $irc->yield(
connect => { connect => {
Nick => $nick, Nick => $nick,
...@@ -147,9 +149,9 @@ sub on_connect ...@@ -147,9 +149,9 @@ sub on_connect
{ {
my $kernel = $_[ KERNEL ]; my $kernel = $_[ KERNEL ];
$log->info('connected');
setConf(); setConf();
$irc->yield(privmsg => "NickServ" => "identify ".$conf->{'nickserv_pwd'}) unless ($debug); $irc->yield(privmsg => "NickServ" => "identify ".$conf->{'nickserv_pwd'}) unless ($debug);
$log->info('connected');
foreach (@channels) { foreach (@channels) {
$irc->delay([join => $_], 20); $irc->delay([join => $_], 20);
......
...@@ -8,6 +8,10 @@ use LWP::UserAgent; ...@@ -8,6 +8,10 @@ use LWP::UserAgent;
use JSON; use JSON;
use Scalar::Util qw(looks_like_number); use Scalar::Util qw(looks_like_number);
use PlayBot::utils::Logging;
my $log = PlayBot::utils::Logging->new('STDOUT', 1);
my $root = 'http://api.soundcloud.com'; my $root = 'http://api.soundcloud.com';
my $clientId = 'f4956716fe1a9dc9c3725af822963365'; my $clientId = 'f4956716fe1a9dc9c3725af822963365';
...@@ -76,6 +80,12 @@ sub get { ...@@ -76,6 +80,12 @@ sub get {
); );
my $response; my $response;
$log->info("the id is ".$id);
my $retries = 0;
while ($retries < 10) {
$log->info("Soundcloud API is half break, try number ".($retries + 1));
if (looks_like_number($id)) if (looks_like_number($id))
{ {
$response = $ua->get($root.'/tracks/'.$id.'?client_id='.$clientId); $response = $ua->get($root.'/tracks/'.$id.'?client_id='.$clientId);
...@@ -83,8 +93,20 @@ sub get { ...@@ -83,8 +93,20 @@ sub get {
else else
{ {
my $url = 'https://www.soundcloud.com/'.$id; my $url = 'https://www.soundcloud.com/'.$id;
$log->info("the url is ".$root.'/resolve.json?url='.$url.'&client_id='.$clientId);
$response = $ua->get($root.'/resolve.json?url='.$url.'&client_id='.$clientId); $response = $ua->get($root.'/resolve.json?url='.$url.'&client_id='.$clientId);
} }
if ($response->code == 404)
{
$retries++;
sleep(1);
}
else
{
last;
}
}
die($response->status_line) unless ($response->is_success); die($response->status_line) unless ($response->is_success);
my $content = decode_json($response->decoded_content); my $content = decode_json($response->decoded_content);
......
...@@ -25,13 +25,14 @@ sub main_session { ...@@ -25,13 +25,14 @@ sub main_session {
} }
sub get_new_session { sub get_new_session {
my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}, $conf->{'user'}, $conf->{'passwd'}, { my $dbh = DBI->connect('DBI:mysql:'.$conf->{'bdd'}.';host='.$conf->{'host'}.';mysql_enable_utf8mb4=1', $conf->{'user'}, $conf->{'passwd'}, {
RaiseError => 1, RaiseError => 1,
AutoCommit => 0 AutoCommit => 0
}) })
or die("Couldn't connect to database: ".DBI->errstr); or die("Couldn't connect to database: ".DBI->errstr);
$dbh->do(qq{SET NAMES 'utf8';}); #$dbh->{'mysql_enable_utf8mb4'} = 1;
#$dbh->do(qq{SET NAMES utf8;});
return $dbh; return $dbh;
} }
......
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