Skip to content

Commit

Permalink
feat: 未设置botname时从api中获取
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXark committed Oct 20, 2023
1 parent 28a5fe4 commit 7c21224
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/message.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -140,7 +140,6 @@ async function msgFilterNonTextMessage(message, context) {
return null;
}


/**
* 处理群消息
*
Expand All @@ -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消息
Expand Down
11 changes: 10 additions & 1 deletion src/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<object>}
* @return {Promise<BotInfo>}
*/
export async function getBot(token) {
const resp = await fetch(
Expand Down

0 comments on commit 7c21224

Please sign in to comment.