feat: show telegram group names in manager

This commit is contained in:
ngfchl
2026-07-07 12:59:34 +08:00
parent 3279e33244
commit 3f4af40d0d
4 changed files with 355 additions and 6 deletions
+1 -1
View File
@@ -273,7 +273,7 @@ onBeforeUnmount(() => {
<p>Telegram 群组安全管理面板</p>
</div>
<div class="top-actions">
<select v-model="selectedChatId" class="form-select" @change="reloadByGroup"><option :value="null">全部群组</option><option v-for="g in groups" :key="g.chat_id" :value="g.chat_id">{{ g.name }}</option></select>
<select v-model="selectedChatId" class="form-select" @change="reloadByGroup"><option :value="null">全部群组</option><option v-for="g in groups" :key="g.chat_id" :value="g.chat_id">{{ g.label || g.name }}</option></select>
<span class="conn" :class="sseConnected ? 'on' : 'off'">{{ sseConnected ? '实时连接' : '连接中' }}</span>
<SButton size="xs" variant="outline" color="primary" :disabled="restartingBot" @click="restartBot">重启Bot</SButton>
<SButton size="xs" variant="soft" color="warning" :disabled="restarting" @click="restartService">重启服务</SButton>
+25 -4
View File
@@ -167,10 +167,31 @@ async def api_actions(limit: int = Query(default=100, ge=1, le=500)):
@app.get("/api/groups")
async def api_groups():
rows = await Message.all().distinct().values("chat_id")
extra = await LotteryEvent.all().distinct().values("chat_id")
ids = sorted({int(r["chat_id"]) for r in rows + extra if r.get("chat_id")})
return JSONResponse([{"chat_id": x, "name": str(x)} for x in ids])
import config
from telegram import Bot
from telegram.request import HTTPXRequest
sources = []
for model in (Message, Ban, Action, GameScore, LotteryEvent, ShopItem):
try:
sources.extend(await model.all().distinct().values("chat_id"))
except Exception:
pass
ids = sorted({int(r["chat_id"]) for r in sources if r.get("chat_id")})
if config.TG_CHAT_ID and config.TG_CHAT_ID not in ids:
ids.insert(0, config.TG_CHAT_ID)
bot = Bot(token=config.TG_BOT_TOKEN, request=HTTPXRequest(proxy=getattr(config, "TG_PROXY_URL", config.PROXY_URL), connect_timeout=10.0, read_timeout=10.0))
result = []
for chat_id in ids:
name = str(chat_id)
try:
chat = await bot.get_chat(chat_id=chat_id)
name = chat.title or chat.full_name or chat.username or str(chat_id)
except Exception:
pass
result.append({"chat_id": chat_id, "name": name, "label": f"{name} ({chat_id})"})
return JSONResponse(result)
@app.get("/api/shop-items")
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -4,7 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TG Spam Guard</title>
<script type="module" crossorigin src="/static/assets/index-CH_Qpu86.js"></script>
<script type="module" crossorigin src="/static/assets/index-Cwa1Xd8Y.js"></script>
<link rel="stylesheet" crossorigin href="/static/assets/index-CVeOFNWl.css">
</head>
<body>