feature
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Telegram\Handlers;
|
||||
|
||||
use SergiX44\Nutgram\Nutgram;
|
||||
|
||||
class PingCommand
|
||||
{
|
||||
public function __invoke(Nutgram $bot): void
|
||||
{
|
||||
$bot->sendMessage('pong');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Telegram\Handlers;
|
||||
|
||||
use App\Services\TransferService;
|
||||
use SergiX44\Nutgram\Nutgram;
|
||||
|
||||
class TransferCommand
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TransferService $transfers,
|
||||
) {}
|
||||
|
||||
public function __invoke(Nutgram $bot, string $args): void
|
||||
{
|
||||
$parts = preg_split('/\s+/', trim($args)) ?: [];
|
||||
|
||||
if (count($parts) < 2) {
|
||||
$bot->sendMessage("Usage: /transfer <toAddress> <amount> [TRX|USDT]\nDefault asset: USDT");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$to = $parts[0];
|
||||
$amount = $parts[1];
|
||||
$asset = strtoupper($parts[2] ?? 'USDT');
|
||||
|
||||
if (! in_array($asset, ['TRX', 'USDT'], true)) {
|
||||
$bot->sendMessage('Asset must be TRX or USDT.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$bot->sendMessage("⏳ Transferring {$amount} {$asset} → {$to} …");
|
||||
|
||||
$result = $this->transfers->handle('tron', $to, $amount, $asset);
|
||||
if (! ($result['ok'] ?? false)) {
|
||||
$bot->sendMessage('❌ '.($result['error'] ?? 'Transfer failed'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$bot->sendMessage(implode("\n", [
|
||||
'✅ Transfer submitted',
|
||||
'From: '.$result['from'],
|
||||
'To: '.$to,
|
||||
'Amount: '.$amount.' '.$asset,
|
||||
'TxID: '.$result['txid'],
|
||||
]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Telegram\Middleware;
|
||||
|
||||
use SergiX44\Nutgram\Nutgram;
|
||||
|
||||
class AuthorizedChat
|
||||
{
|
||||
public function __invoke(Nutgram $bot, callable $next): mixed
|
||||
{
|
||||
$expected = (string) config('coruna.telegram.owner_chat_id', '');
|
||||
if ($expected === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$chatId = $bot->chatId();
|
||||
if ($chatId === null || (string) $chatId !== $expected) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $next($bot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user