Recherche des tweets de réponse avec l'API Tweeter
This commit is contained in:
81
app/Jobs/ProcessNews.php
Normal file
81
app/Jobs/ProcessNews.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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;
|
||||
|
||||
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{
|
||||
$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(15);
|
||||
}
|
||||
}
|
||||
}catch (Exception $exception){
|
||||
$text = "Le compte Twitter " . $user->name . " : " . $exception->getMessage();
|
||||
|
||||
// L'URL des deux liens
|
||||
$url = 'https://myx.ovh/nova/resources/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
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user