feat: bot

This commit is contained in:
hashbro
2026-08-15 23:05:51 +08:00
parent 9049fdccad
commit 376b442880
26 changed files with 944 additions and 352 deletions
+40
View File
@@ -2,13 +2,19 @@
namespace App\Telegram\Handlers;
use App\Models\Channel;
use App\Models\Device;
use App\Models\User;
use App\Models\WalletAddress;
use App\Services\TransferService;
use App\Telegram\TelegramBotContext;
use SergiX44\Nutgram\Nutgram;
class TransferCommand
{
public function __construct(
private readonly TransferService $transfers,
private readonly TelegramBotContext $context,
) {}
public function __invoke(Nutgram $bot, string $args): void
@@ -74,6 +80,13 @@ class TransferCommand
$amount = $parts[2];
}
$agent = $this->context->agent();
if ($agent !== null && ! $this->addressOwnedByAgent($from, $agent)) {
$bot->sendMessage('⛔ 无权操作该地址(仅限本代理渠道设备)');
return;
}
$label = $amount === null ? "ALL {$asset}" : "{$amount} {$asset}";
$bot->sendMessage("⏳ Transferring {$label} from {$from} ({$chain}) …");
@@ -151,4 +164,31 @@ class TransferCommand
return $name !== '' ? "telegram:{$id}({$name})" : "telegram:{$id}";
}
private function addressOwnedByAgent(string $fromAddress, User $agent): bool
{
$channelIds = Channel::query()
->where('user_id', $agent->id)
->pluck('channel_id');
if ($channelIds->isEmpty()) {
return false;
}
$deviceIds = Device::query()
->whereIn('channel_id', $channelIds)
->pluck('id');
if ($deviceIds->isEmpty()) {
return false;
}
return WalletAddress::query()
->whereIn('device_id', $deviceIds)
->where(function ($q) use ($fromAddress) {
$q->where('address', $fromAddress);
if (str_starts_with(strtolower($fromAddress), '0x')) {
$q->orWhereRaw('LOWER(address) = ?', [strtolower($fromAddress)]);
}
})
->exists();
}
}