Correction des différents bugs
This commit is contained in:
@@ -2,27 +2,198 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\TwitterController;
|
||||
use App\Models\Account;
|
||||
use App\Models\Block;
|
||||
use App\Models\Concour;
|
||||
use App\Models\Contest;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Symfony\Component\BrowserKit\HttpBrowser;
|
||||
use Symfony\Component\HttpClient\HttpClient;
|
||||
use Illuminate\Http\Request;
|
||||
use Throwable;
|
||||
|
||||
class BotController extends Controller
|
||||
{
|
||||
public function test($user,$contest){
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
$response = Http::get('https://rtandfollow.com/apibot');
|
||||
$tweets = $response->json();
|
||||
|
||||
$accounts = Account::where('enable', true)->get();
|
||||
|
||||
foreach($accounts as $account){
|
||||
try{
|
||||
$user = $account;
|
||||
$twitter = new TwitterController();
|
||||
$browser = $twitter->connexion($user);
|
||||
$url = $browser->driver->getCurrentURL();
|
||||
|
||||
if($url == 'https://x.com/account/access'){
|
||||
$browser->quit();
|
||||
exec('taskkill /f /im chrome.exe');
|
||||
}else{
|
||||
|
||||
shuffle($tweets);
|
||||
|
||||
$a = 1;
|
||||
|
||||
foreach($tweets as $status) {
|
||||
|
||||
$tweetid = $status['tweetid'];
|
||||
$screen_name = $status['organizer']['screen_name'];
|
||||
$text = $status['description'];
|
||||
|
||||
$concours = DB::table('concours')->where('tweet_id', $tweetid)->where('user', $user->id)->first();
|
||||
$blocking = DB::table('blocks')->where('screen_name', $screen_name)->first();
|
||||
|
||||
$containsBlacklistedWord = preg_match('/' . implode('|', array_map('preg_quote', config('twitter.giveaway_to_blacklist'), ['/'])) . '/i', $text) === 1;
|
||||
|
||||
//On verifie que le concours n'est pas dans la BDD ou que l'utilisateur n'est pas bloqué
|
||||
if (empty($concours) and empty($blocking) and $containsBlacklistedWord !== true) {
|
||||
|
||||
//On recherche la date de fin du concours
|
||||
$fin = $status['fin'];
|
||||
|
||||
if ($fin >= Carbon::now()->format('Y-m-d')) {
|
||||
|
||||
try {
|
||||
|
||||
$tweetspecial = $this->getSpecialComment($text,$tweetid,$screen_name);
|
||||
|
||||
$tweetcomment = $this->getComment($text);
|
||||
|
||||
$tags = $this->getTags($text);
|
||||
|
||||
$hashtags = $this->getHashtags($text);
|
||||
|
||||
$follows = $this->getFollows($text);
|
||||
|
||||
$concours = Concour::create([
|
||||
'description' => $text,
|
||||
'tweet_id' => $tweetid,
|
||||
'name' => $screen_name,
|
||||
'fin' => $fin,
|
||||
'user' => $user->id,
|
||||
]);
|
||||
|
||||
$twitter->retweet($browser, $tweetid);
|
||||
|
||||
if (isset($tweetspecial) && isset($tags)) {
|
||||
$retweet = $tweetspecial . ' ' . $tags . ' ' . $hashtags;
|
||||
$encode = urlencode($retweet);
|
||||
|
||||
//On reply
|
||||
$twitter->reply($browser, $tweetid, $encode);
|
||||
|
||||
}elseif(isset($tweetcomment) && isset($tags)) {
|
||||
$comments = config('twitter.sentence_for_tag');
|
||||
$comment = Arr::random($comments);
|
||||
$retweet = $comment . ' ' . $tags . ' ' . $hashtags;
|
||||
$encode = urlencode($retweet);
|
||||
|
||||
//On reply
|
||||
$twitter->reply($browser, $tweetid, $encode);
|
||||
|
||||
}elseif(isset($tweetspecial)){
|
||||
$retweet = $tweetspecial . ' ' . $hashtags;
|
||||
$encode = urlencode($retweet);
|
||||
|
||||
//On reply
|
||||
$twitter->reply($browser, $tweetid, $encode);
|
||||
|
||||
}elseif(isset($tweetcomment)){
|
||||
$comments = config('twitter.sentence_for_random_comment');
|
||||
$comment = Arr::random($comments);
|
||||
$retweet = $comment . ' ' . $hashtags;
|
||||
$encode = urlencode($retweet);
|
||||
|
||||
//On reply
|
||||
$twitter->reply($browser, $tweetid, $encode);
|
||||
|
||||
}elseif(isset($tags)){
|
||||
$retweet = $tags;
|
||||
$encode = urlencode($retweet);
|
||||
|
||||
//On reply
|
||||
$twitter->reply($browser, $tweetid, $encode);
|
||||
}
|
||||
|
||||
//On follow le créateur
|
||||
$twitter->follow($browser, $screen_name);
|
||||
|
||||
if(isset($follows)){
|
||||
foreach ($follows as $follow){
|
||||
$twitter->follow($browser, $follow);
|
||||
}
|
||||
}
|
||||
|
||||
//On like si besoin
|
||||
preg_match("/LIKE/i", $text, $like);
|
||||
if (isset($like[0])) {
|
||||
$twitter->like($browser, $tweetid);
|
||||
}
|
||||
|
||||
$yes = rand(0,2);
|
||||
|
||||
if($yes == 1){
|
||||
|
||||
$new = $this->combinefeeds()[0];
|
||||
$title = (strlen($new['title']) > 205) ? substr($new['title'],0,205).'...' : $new['title'];
|
||||
//$url = $this->urlshort($new['url']);
|
||||
$short = $title.' '.$new['url'];
|
||||
$short = urlencode($short);
|
||||
//On tweet une info
|
||||
$twitter->tweet($browser, $short);
|
||||
|
||||
}
|
||||
|
||||
$a++;
|
||||
|
||||
if ($a > 2) {
|
||||
echo $user->name.' a bien participé; ';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (Throwable $e) {
|
||||
|
||||
report($e);
|
||||
|
||||
$a++;
|
||||
|
||||
if ($a > 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($browser) && $browser instanceof Browser) {
|
||||
// Récupérez les cookies de la session actuelle
|
||||
$cookies = $browser->driver->manage()->getCookies();
|
||||
|
||||
// Sauvegardez les cookies dans un fichier au format JSON
|
||||
$user->cookies = serialize($cookies);
|
||||
$user->save();
|
||||
|
||||
$browser->quit();
|
||||
}
|
||||
}
|
||||
}catch (Throwable $e) {
|
||||
report($e);
|
||||
}
|
||||
}
|
||||
|
||||
exec('taskkill /f /im chrome.exe');
|
||||
|
||||
}
|
||||
|
||||
public function process($user,$id){
|
||||
$user = Account::find($user);
|
||||
|
||||
$contest = Contest::findOrFail($contest);
|
||||
$contest = Contest::findOrFail($id);
|
||||
|
||||
$text = $contest->description;
|
||||
|
||||
@@ -77,14 +248,7 @@ class BotController extends Controller
|
||||
// Récupérer la phrase avec le comptage le plus élevé
|
||||
$phrasePlusFrequente = ($indexPhrasePlusFrequente !== null) ? $texts[$indexPhrasePlusFrequente] : null;
|
||||
|
||||
|
||||
if ($phrasePlusFrequente != null) {
|
||||
// Supprimer les hashtags
|
||||
$phrasePlusFrequente = preg_replace('/#\w+\s?/', '', $phrasePlusFrequente);
|
||||
|
||||
// Supprimer les tags
|
||||
$phrasePlusFrequente = preg_replace('/@\w+\s?/', '', $phrasePlusFrequente);
|
||||
|
||||
// Supprimer les emojis
|
||||
$phrasePlusFrequente = $this->remove_emojis($phrasePlusFrequente);
|
||||
|
||||
@@ -189,6 +353,18 @@ class BotController extends Controller
|
||||
|
||||
return $dotProduct / ($magnitude1 * $magnitude2);
|
||||
}
|
||||
private function getFollows(mixed $text)
|
||||
{
|
||||
preg_match_all("/\s@([\w_-]+)/", $text, $mentions);
|
||||
|
||||
if(isset($mentions[1])){
|
||||
$mentions = array_unique($mentions[1]);
|
||||
return $mentions;
|
||||
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
private function remove_emojis($string)
|
||||
{
|
||||
// Match all emojis (including extended ones)
|
||||
@@ -198,4 +374,6 @@ class BotController extends Controller
|
||||
return $clear_string;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user