feat: new chain
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Telegram\Handlers;
|
||||
|
||||
use App\Models\Channel;
|
||||
use App\Telegram\TelegramBotContext;
|
||||
use SergiX44\Nutgram\Nutgram;
|
||||
use SergiX44\Nutgram\Telegram\Types\Keyboard\CopyTextButton;
|
||||
use SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardButton;
|
||||
use SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup;
|
||||
|
||||
class ChannelCommand
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TelegramBotContext $context,
|
||||
) {}
|
||||
|
||||
public function __invoke(Nutgram $bot): void
|
||||
{
|
||||
$query = Channel::query()->with('user:id,username')->orderByDesc('id');
|
||||
$agent = $this->context->agent();
|
||||
if ($agent !== null) {
|
||||
$query->where('user_id', $agent->id);
|
||||
}
|
||||
|
||||
$channels = $query->limit(30)->get();
|
||||
|
||||
if ($channels->isEmpty()) {
|
||||
$bot->sendMessage('暂无渠道');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$lines = ['📎 渠道列表(点按钮复制链接)', ''];
|
||||
$markup = InlineKeyboardMarkup::make();
|
||||
|
||||
foreach ($channels as $i => $channel) {
|
||||
$remark = trim((string) ($channel->remark ?? ''));
|
||||
$remarkLabel = $remark !== '' ? $remark : '—';
|
||||
$owner = $channel->agentLabel();
|
||||
$status = $channel->isEnabled() ? '启用' : '停用';
|
||||
$lines[] = ($i + 1).'. '.$channel->channel_id;
|
||||
$lines[] = ' 备注: '.$remarkLabel.' | 归属: '.$owner.' | '.$status;
|
||||
|
||||
$links = $channel->supportLinks();
|
||||
$link = $links[0] ?? ('/web/'.$channel->channel_id.'/support.html');
|
||||
if (strlen($link) > 256) {
|
||||
$link = substr($link, 0, 256);
|
||||
}
|
||||
|
||||
$btnText = ($remark !== '' ? mb_substr($remark, 0, 18) : substr($channel->channel_id, 0, 8)).' · 复制链接';
|
||||
$markup->addRow(InlineKeyboardButton::make(
|
||||
text: $btnText,
|
||||
copy_text: CopyTextButton::make($link),
|
||||
));
|
||||
}
|
||||
|
||||
if ($channels->count() >= 30) {
|
||||
$lines[] = '';
|
||||
$lines[] = '(仅显示最近 30 条)';
|
||||
}
|
||||
|
||||
$bot->sendMessage(
|
||||
implode("\n", $lines),
|
||||
reply_markup: $markup,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user