Files
coruna-lab/app/Telegram/TelegramRegistrar.php
2026-08-15 23:05:51 +08:00

51 lines
2.0 KiB
PHP

<?php
namespace App\Telegram;
use App\Telegram\Handlers\ChannelCommand;
use App\Telegram\Handlers\DataCommand;
use App\Telegram\Handlers\HelpCommand;
use App\Telegram\Handlers\JoinedChatHandler;
use App\Telegram\Handlers\PingCommand;
use App\Telegram\Handlers\TransferCommand;
use App\Telegram\Middleware\AuthorizedChat;
use App\Telegram\Middleware\GroupAdminOnly;
use SergiX44\Nutgram\Nutgram;
class TelegramRegistrar
{
/** Single site bot. Official vs agent is resolved from chat_id. */
public function registerOfficial(Nutgram $bot): void
{
// Announce chat_id when invited — must not use AuthorizedChat
// so unconfigured groups can still copy the id into admin settings.
$bot->onMyChatMember(JoinedChatHandler::class);
// HandlerGroup::middleware() unshifts — register GroupAdminOnly first so
// AuthorizedChat ends up outermost (chat allowlist before admin check).
$bot->group(function (Nutgram $bot) {
$bot->onCommand('help', HelpCommand::class)
->description('List available commands');
$bot->onCommand('ping', PingCommand::class)
->description('Health check');
$bot->onCommand('data', DataCommand::class)
->description('Visit stats (today). Optional: /data 1|7|30 [channelId]');
$bot->onCommand('data {args}', DataCommand::class)
->where('args', '.+')
->description('Visit stats for 1/7/30 days, optional channelId');
$bot->onCommand('channel', ChannelCommand::class)
->description('List channels; copy promo iframe (new) or support link (old)');
$bot->onCommand('transfer {args}', TransferCommand::class)
->where('args', '.+')
->description('Transfer TRX or USDT from a device address (omit amount = all)');
})
->middleware(GroupAdminOnly::class)
->middleware(AuthorizedChat::class);
}
}