41 lines
997 B
PHP
41 lines
997 B
PHP
<?php
|
|
|
|
namespace App\Telegram\Middleware;
|
|
|
|
use SergiX44\Nutgram\Nutgram;
|
|
use SergiX44\Nutgram\Telegram\Properties\ChatMemberStatus;
|
|
|
|
class GroupAdminOnly
|
|
{
|
|
public function __invoke(Nutgram $bot, callable $next): mixed
|
|
{
|
|
$chatId = $bot->chatId();
|
|
$userId = $bot->userId();
|
|
if ($chatId === null || $userId === null) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
$member = $bot->getChatMember($chatId, $userId);
|
|
} catch (\Throwable) {
|
|
$bot->sendMessage('⛔ Unable to verify admin status.');
|
|
|
|
return null;
|
|
}
|
|
|
|
$status = $member?->status;
|
|
$ok = $status === ChatMemberStatus::CREATOR
|
|
|| $status === ChatMemberStatus::ADMINISTRATOR
|
|
|| $status === 'creator'
|
|
|| $status === 'administrator';
|
|
|
|
if (! $ok) {
|
|
$bot->sendMessage('⛔ Only group admins can use this command.');
|
|
|
|
return null;
|
|
}
|
|
|
|
return $next($bot);
|
|
}
|
|
}
|