feat: telegram check addrss exists (#705)

This commit is contained in:
Dream Hunter
2025-08-08 13:26:45 +08:00
committed by GitHub
parent 9843b35f54
commit 840496c48f
2 changed files with 13 additions and 5 deletions
+9 -1
View File
@@ -51,6 +51,14 @@ export const jwtListToAddressData = async (
for (const jwt of jwtList) { for (const jwt of jwtList) {
try { try {
const { address, address_id } = await Jwt.verify(jwt, c.env.JWT_SECRET, "HS256"); 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); addressList.push(address as string);
addressIdMap[address as string] = address_id as number; addressIdMap[address as string] = address_id as number;
} catch (e) { } catch (e) {
@@ -75,7 +83,7 @@ export const bindTelegramAddress = async (
return address as string; return address as string;
} }
if (jwtList.length >= getIntValue(c.env.TG_MAX_ADDRESS, 5)) { 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])); await c.env.KV.put(`${CONSTANTS.TG_KV_PREFIX}:${userId}`, JSON.stringify([...jwtList, jwt]));
// for mail push to telegram // for mail push to telegram
+4 -4
View File
@@ -41,8 +41,8 @@ const COMMANDS = [
description: "查看邮件, 请输入 /mails <邮箱地址>, 不输入地址默认查看第一个地址" description: "查看邮件, 请输入 /mails <邮箱地址>, 不输入地址默认查看第一个地址"
}, },
{ {
command: "cleaninvalidadress", command: "cleaninvalidaddress",
description: "清理无效地址, 请输入 /cleaninvalidadress" description: "清理无效地址, 请输入 /cleaninvalidaddress"
}, },
] ]
@@ -159,7 +159,7 @@ export function newTelegramBot(c: Context<HonoCustomType>, token: string): Teleg
} }
try { try {
// @ts-ignore // @ts-ignore
const address = ctx?.message?.text.slice("/unbind".length).trim(); const address = ctx?.message?.text.slice("/delete".length).trim();
if (!address) { if (!address) {
return await ctx.reply("请输入地址"); return await ctx.reply("请输入地址");
} }
@@ -186,7 +186,7 @@ export function newTelegramBot(c: Context<HonoCustomType>, token: string): Teleg
} }
}); });
bot.command("cleaninvalidadress", async (ctx: TgContext) => { bot.command("cleaninvalidaddress", async (ctx: TgContext) => {
const userId = ctx?.message?.from?.id; const userId = ctx?.message?.from?.id;
if (!userId) { if (!userId) {
return await ctx.reply("无法获取用户信息"); return await ctx.reply("无法获取用户信息");