From 840496c48fb437c5347950c31487b8e0619cb266 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Fri, 8 Aug 2025 13:26:45 +0800 Subject: [PATCH] feat: telegram check addrss exists (#705) --- worker/src/telegram_api/common.ts | 10 +++++++++- worker/src/telegram_api/telegram.ts | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/worker/src/telegram_api/common.ts b/worker/src/telegram_api/common.ts index 0c9347a2..8e7abf66 100644 --- a/worker/src/telegram_api/common.ts +++ b/worker/src/telegram_api/common.ts @@ -51,6 +51,14 @@ export const jwtListToAddressData = async ( for (const jwt of jwtList) { try { const { address, address_id } = await Jwt.verify(jwt, c.env.JWT_SECRET, "HS256"); + const name = await c.env.DB.prepare( + `SELECT name FROM address WHERE id = ? ` + ).bind(address_id).first("name"); + if (!name) { + addressList.push("无效地址"); + invalidJwtList.push(jwt); + continue; + } addressList.push(address as string); addressIdMap[address as string] = address_id as number; } catch (e) { @@ -75,7 +83,7 @@ export const bindTelegramAddress = async ( return address as string; } if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) { - throw Error("绑定地址数量已达上限"); + throw Error("绑定地址数量已达上限, 请先 /cleaninvalidaddress"); } await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, JSON.stringify([...jwtList, jwt])); // for mail push to telegram diff --git a/worker/src/telegram_api/telegram.ts b/worker/src/telegram_api/telegram.ts index 177c946d..c5303587 100644 --- a/worker/src/telegram_api/telegram.ts +++ b/worker/src/telegram_api/telegram.ts @@ -41,8 +41,8 @@ const COMMANDS = [ description: "查看邮件, 请输入 /mails <邮箱地址>, 不输入地址默认查看第一个地址" }, { - command: "cleaninvalidadress", - description: "清理无效地址, 请输入 /cleaninvalidadress" + command: "cleaninvalidaddress", + description: "清理无效地址, 请输入 /cleaninvalidaddress" }, ] @@ -159,7 +159,7 @@ export function newTelegramBot(c: Context, token: string): Teleg } try { // @ts-ignore - const address = ctx?.message?.text.slice("/unbind".length).trim(); + const address = ctx?.message?.text.slice("/delete".length).trim(); if (!address) { return await ctx.reply("请输入地址"); } @@ -186,7 +186,7 @@ export function newTelegramBot(c: Context, token: string): Teleg } }); - bot.command("cleaninvalidadress", async (ctx: TgContext) => { + bot.command("cleaninvalidaddress", async (ctx: TgContext) => { const userId = ctx?.message?.from?.id; if (!userId) { return await ctx.reply("无法获取用户信息");