From 7c212248509bc0f6983a60023eabd4c9661a399b Mon Sep 17 00:00:00 2001 From: TBXark Date: Fri, 20 Oct 2023 14:00:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9C=AA=E8=AE=BE=E7=BD=AEbotname?= =?UTF-8?q?=E6=97=B6=E4=BB=8Eapi=E4=B8=AD=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/message.js | 10 +++++++--- src/telegram.js | 11 ++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/message.js b/src/message.js index 0a19afd2..f29aa170 100644 --- a/src/message.js +++ b/src/message.js @@ -1,6 +1,6 @@ import {CONST, DATABASE, ENV} from './env.js'; import {Context} from './context.js'; -import {sendMessageToTelegramWithContext} from './telegram.js'; +import {getBot, sendMessageToTelegramWithContext} from './telegram.js'; import {handleCommandMessage} from './command.js'; import {errorToString} from './utils.js'; import {chatWithLLM} from './chat.js'; @@ -140,7 +140,6 @@ async function msgFilterNonTextMessage(message, context) { return null; } - /** * 处理群消息 * @@ -154,7 +153,12 @@ async function msgHandleGroupMessage(message, context) { return new Response('Non text message', {status: 200}); } // 处理群组消息,过滤掉AT部分 - const botName = context.SHARE_CONTEXT.currentBotName; + let botName = context.SHARE_CONTEXT.currentBotName; + if (!botName) { + const res = await getBot(context.SHARE_CONTEXT.currentBotToken) + context.SHARE_CONTEXT.currentBotName = res.info.name; + botName = res.info.name; + } if (botName) { let mentioned = false; // Reply消息 diff --git a/src/telegram.js b/src/telegram.js index d95d5049..a67fe40c 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -275,10 +275,19 @@ export async function getChatAdminister(chatId, token) { } // 获取机器人信息 +/** + * @typedef {object} BotInfo + * @property {boolean} ok + * @property {object} info + * @property {string} info.name + * @property {string} info.bot_name + * @property {boolean} info.can_join_groups + * @property {boolean} info.can_read_all_group_messages + */ /** * * @param {string} token - * @return {Promise} + * @return {Promise} */ export async function getBot(token) { const resp = await fetch(