fix: various fixes (#3023)

* improve twitch error message

* fix worldcosplay notice

* fix: add new video image to telegram

* fix: reuters

* fix: formula1

* twitter
This commit is contained in:
Dag 2022-09-09 20:18:50 +02:00 committed by GitHub
parent 6ac347d5ac
commit 94ae098ef5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 32 deletions

View file

@ -11,7 +11,6 @@ class Formula1Bridge extends BridgeAbstract
const API_URL = 'https://api.formula1.com/v1/editorial/articles?limit=%u';
const ARTICLE_AUTHOR = 'Formula 1';
const ARTICLE_HTML = '<p>%s</p><a href="%s" target="_blank"><img src="%s" alt="%s" title="%s"></a>';
const ARTICLE_URL = 'https://formula1.com/en/latest/article.%s.%s.html';
const LIMIT_MIN = 1;
@ -58,8 +57,8 @@ class Formula1Bridge extends BridgeAbstract
$item['enclosures'] = [$article->thumbnail->image->url];
$item['uid'] = $article->id;
$item['content'] = sprintf(
self::ARTICLE_HTML,
$article->metaDescription,
'<p>%s</p><a href="%s" target="_blank"><img src="%s" alt="%s" title="%s"></a>',
$article->metaDescription ?? $article->title,
$item['uri'],
$item['enclosures'][0],
$caption,

View file

@ -612,7 +612,7 @@ EOD;
// Some article cause unexpected behaviour like redirect to another site not API.
// Attempt to check article source type to avoid this.
if (!$this->useWireAPI && $source_type != 'Package') { // Only Reuters PF api have this, Wire don't.
$author = $this->handleAuthorName($story['authors']);
$author = $this->handleAuthorName($story['authors'] ?? []);
$timestamp = $story['published_time'];
$image_placeholder = '';
if (isset($story['thumbnail'])) {

View file

@ -280,6 +280,8 @@ EOD;
preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo);
} elseif ($messageDiv->find('i.link_preview_video_thumb')) {
preg_match($this->backgroundImageRegex, $messageDiv->find('i.link_preview_video_thumb', 0)->style, $photo);
} elseif ($messageDiv->find('i.tgme_widget_message_roundvideo_thumb')) {
preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_roundvideo_thumb', 0)->style, $photo);
}
$this->enclosures[] = $photo[1];

View file

@ -30,13 +30,6 @@ class TwitchBridge extends BridgeAbstract
]
]];
/*
* Official instructions for obtaining your own client ID can be found here:
* https://dev.twitch.tv/docs/v5/#getting-a-client-id
*/
const CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
const API_ENDPOINT = 'https://gql.twitch.tv/gql';
const BROADCAST_TYPES = [
'all' => [
'ARCHIVE',
@ -214,8 +207,12 @@ EOD;
'query' => $query,
'variables' => $variables
];
/**
* Official instructions for obtaining your own client ID can be found here:
* https://dev.twitch.tv/docs/v5/#getting-a-client-id
*/
$header = [
'Client-ID: ' . self::CLIENT_ID
'Client-ID: kimne78kx3ncx6brgo4mv6wki5h1ko'
];
$opts = [
CURLOPT_CUSTOMREQUEST => 'POST',
@ -223,17 +220,13 @@ EOD;
];
Debug::log("Sending GraphQL query:\n" . $query);
Debug::log("Sending GraphQL variables:\n"
. json_encode($variables, JSON_PRETTY_PRINT));
$response = json_decode(getContents(self::API_ENDPOINT, $header, $opts));
Debug::log("Got GraphQL response:\n"
. json_encode($response, JSON_PRETTY_PRINT));
Debug::log("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
$response = json_decode(getContents('https://gql.twitch.tv/gql', $header, $opts));
Debug::log("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));
if (isset($response->errors)) {
$messages = array_column($response->errors, 'message');
returnServerError('API error(s): ' . implode("\n", $messages));
throw new \Exception(sprintf('twitch api: `%s`', implode("\n", $messages)));
}
return $response->data;

View file

@ -273,7 +273,7 @@ EOD
if (!$data) {
switch ($this->queriedContext) {
case 'By keyword or hashtag':
returnServerError('No results for this query.');
returnServerError('twitter: No results for this query.');
// fall-through
case 'By username':
returnServerError('Requested username can\'t be found.');
@ -645,16 +645,7 @@ EOD;
}
// fall-through
default:
$code = $e->getCode();
$data = $e->getMessage();
returnServerError(
<<<EOD
Failed to make api call: $api
HTTP Status: $code
Errormessage: $data
EOD
);
break;
throw $e;
}
}
} while ($retry);

View file

@ -107,11 +107,14 @@ class WorldCosplayBridge extends BridgeAbstract
$item = [
'uri' => self::URI . substr($image->url, 1),
'title' => $image->subject,
'timestamp' => $image->created_at,
'author' => $img->member->global_name,
'enclosures' => [$image->large_url],
'uid' => $image->id,
];
// Context cosplayer don't have created_at
if (isset($image->created_at)) {
$item['timestamp'] = $image->created_at;
}
$item['content'] = sprintf(
self::CONTENT_HTML,
$item['uri'],

View file

@ -34,6 +34,7 @@ final class Logger
'Exception InvalidArgumentException: Format name invalid!',
'Exception InvalidArgumentException: Unknown format given!',
'Exception InvalidArgumentException: Bridge name invalid!',
'Exception Exception: twitter: No results for this query',
];
foreach ($ignoredExceptions as $ignoredException) {
if (str_starts_with($context['message'], $ignoredException)) {