88 lines
2.2 KiB
PHP
88 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use App\Http\Controllers\APIController;
|
|
use App\Models\Account;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class ProcessNews implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public $timeout = 300;
|
|
|
|
private $authid;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct($authid)
|
|
{
|
|
$this->authid= $authid;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$API = new APIController();
|
|
|
|
$user = Account::find($this->authid);
|
|
|
|
try{
|
|
|
|
//On check si le compte est ok
|
|
$API->check($user);
|
|
|
|
//On check les notifs
|
|
$API->unread($user);
|
|
|
|
if (Cache::has('news')) {
|
|
$news = Cache::get('news');
|
|
}else{
|
|
$news = $API->newstweet($user);
|
|
}
|
|
|
|
shuffle($news);
|
|
|
|
$nb = rand(1,3);
|
|
|
|
if (count($news) >= $nb) {
|
|
$selectedArticles = array_slice($news, 0, $nb);
|
|
|
|
foreach ($selectedArticles as $article) {
|
|
$tweetid = $article['conversation_id_str'];
|
|
$API->retweet($user, $tweetid);
|
|
sleep(30);
|
|
}
|
|
}
|
|
}catch (Exception $exception){
|
|
$text = "Le compte Twitter " . $user->name . " : " . $exception->getMessage();
|
|
|
|
// L'URL des deux liens
|
|
$url = 'https://myx.ovh/accounts/'.$user->id;
|
|
|
|
$keyboard = [
|
|
'inline_keyboard' => [
|
|
[
|
|
['text' => 'Cliquez ici pour plus d\'infos', 'url' => $url]
|
|
]
|
|
]
|
|
];
|
|
|
|
// Convertir le tableau de clavier en JSON
|
|
$keyboardJson = json_encode($keyboard);
|
|
|
|
// Envoyer le message avec les deux boutons
|
|
Http::get('https://api.telegram.org/bot6784810105:AAEq3emnkRwdyvCLC-iqdIjVJ2Ke6HwwGjg/sendMessage', [
|
|
'chat_id' => '1970698501',
|
|
'text' => $text,
|
|
'reply_markup' => $keyboardJson
|
|
]);
|
|
}
|
|
}
|
|
} |