From 8c3ec48bf4d7ef882db05e2d45bd282599f297ce Mon Sep 17 00:00:00 2001 From: Alexandre Morignot <nightiies@perso.iiens.net> Date: Mon, 1 Nov 2021 22:27:22 +0100 Subject: [PATCH] blob --- PlayBot/commands/get.pm | 2 +- PlayBot/sessions/irc.pm | 6 ++++-- PlayBot/sites/soundcloud.pm | 34 ++++++++++++++++++++++++++++------ PlayBot/utils/db.pm | 5 +++-- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/PlayBot/commands/get.pm b/PlayBot/commands/get.pm index 42ea1c4..014d9a8 100644 --- a/PlayBot/commands/get.pm +++ b/PlayBot/commands/get.pm @@ -50,7 +50,7 @@ sub exec { # we check is there is result with global my $q = PlayBot::commands::get::query->new( chan => $query->chan, - query => $query->query . ' -a' + query => $query->query . ' -a', fts => $fts, ); diff --git a/PlayBot/sessions/irc.pm b/PlayBot/sessions/irc.pm index 8266819..1c75cc5 100644 --- a/PlayBot/sessions/irc.pm +++ b/PlayBot/sessions/irc.pm @@ -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); # config -my $serveur = 'irc.iiens.net'; +my $serveur = '193.54.225.86'; my $nick = $conf->{'nick'}; my $port = 6667; my $ircname = 'nightiies'; @@ -129,7 +129,9 @@ sub bot_start { my $kernel = $_[KERNEL]; $kernel->alias_set('bot'); + $log->info("register all"); $irc->yield(register => "all"); + $log->info("connecting"); $irc->yield( connect => { Nick => $nick, @@ -147,9 +149,9 @@ sub on_connect { my $kernel = $_[ KERNEL ]; + $log->info('connected'); setConf(); $irc->yield(privmsg => "NickServ" => "identify ".$conf->{'nickserv_pwd'}) unless ($debug); - $log->info('connected'); foreach (@channels) { $irc->delay([join => $_], 20); diff --git a/PlayBot/sites/soundcloud.pm b/PlayBot/sites/soundcloud.pm index b488d1f..145f9d1 100644 --- a/PlayBot/sites/soundcloud.pm +++ b/PlayBot/sites/soundcloud.pm @@ -8,6 +8,10 @@ use LWP::UserAgent; use JSON; 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 $clientId = 'f4956716fe1a9dc9c3725af822963365'; @@ -76,16 +80,34 @@ sub get { ); my $response; - if (looks_like_number($id)) - { + $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)) + { $response = $ua->get($root.'/tracks/'.$id.'?client_id='.$clientId); - } - else - { + } + else + { 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); + } + + 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 $infos = { diff --git a/PlayBot/utils/db.pm b/PlayBot/utils/db.pm index 7d879e1..6d74330 100644 --- a/PlayBot/utils/db.pm +++ b/PlayBot/utils/db.pm @@ -25,13 +25,14 @@ sub main_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, AutoCommit => 0 }) 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; } -- GitLab