diff --git a/app/Http/Controllers/WebHookController.php b/app/Http/Controllers/WebHookController.php index 2926df4b..aa775371 100644 --- a/app/Http/Controllers/WebHookController.php +++ b/app/Http/Controllers/WebHookController.php @@ -3,7 +3,6 @@ namespace App\Http\Controllers; use App\Jobs\TelegramMessage; -use App\Services\TelegramBot; use Illuminate\Http\Request; class WebHookController extends Controller @@ -16,11 +15,10 @@ class WebHookController extends Controller * * @return void */ - public function telegram(Request $request, TelegramBot $telegramBot): void + public function telegram(Request $request): void { TelegramMessage::dispatch( - $request->collect('message'), - $telegramBot, + $request->collect('message') ); } } diff --git a/app/Jobs/TelegramMessage.php b/app/Jobs/TelegramMessage.php index 746ab7de..639d0975 100644 --- a/app/Jobs/TelegramMessage.php +++ b/app/Jobs/TelegramMessage.php @@ -22,7 +22,7 @@ class TelegramMessage implements ShouldQueue /** * Create a new job instance. */ - public function __construct(public Collection $message, public TelegramBot $telegramBot) + public function __construct(public Collection $message) { $this->text = $this->message->only(['text', 'caption'])->first(); $this->messageId = $this->message->get('message_id'); @@ -33,7 +33,7 @@ public function __construct(public Collection $message, public TelegramBot $tele /** * Execute the job. */ - public function handle(): void + public function handle(TelegramBot $telegramBot): void { // If the message is a reply to another message, it's likely not spam. // Let's not disrupt the conversation and ignore it. @@ -41,20 +41,12 @@ public function handle(): void return; } - if ($this->telegramBot->isSpam($this->text)) { - $this->blocked(); - } - } + if ($telegramBot->isSpam($this->text)) { + // Delete the spam message from the group chat. + $telegramBot->deleteMessage($this->chatId, $this->messageId); - /** - * Block the message and mute the sender in the group. - */ - public function blocked(): void - { - // Delete the spam message from the group chat. - $this->telegramBot->deleteMessage($this->chatId, $this->messageId); - - // Mute the sender of the spam message in the group chat. - $this->telegramBot->muteUserInGroup($this->chatId, $this->from); + // Mute the sender of the spam message in the group chat. + $telegramBot->muteUserInGroup($this->chatId, $this->from); + } } }