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; if ($channel->isNewBuilder()) { $btnText = ($remark !== '' ? mb_substr($remark, 0, 18) : $channel->channel_id).' · 渠道码'; $markup->addRow(InlineKeyboardButton::make( text: $btnText, copy_text: CopyTextButton::make($channel->channel_id), )); continue; } $links = $channel->supportLinks(); $link = $links[0] ?? $channel->landingPath(); 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, ); } }