From 91414cc4ffeb65e60cccae27cc1377b70b0948dc Mon Sep 17 00:00:00 2001 From: Shigma Date: Tue, 13 Aug 2024 14:09:28 +0800 Subject: [PATCH] fix(telegram): support slash command with at, fix koishijs/koishi#1439 --- adapters/telegram/src/utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adapters/telegram/src/utils.ts b/adapters/telegram/src/utils.ts index 238518f5..47d65ab2 100644 --- a/adapters/telegram/src/utils.ts +++ b/adapters/telegram/src/utils.ts @@ -52,7 +52,11 @@ export async function handleUpdate(update: Telegram.Update, bot: TelegramBot) { if (isBotCommand) { session.type = 'interaction/command' await decodeMessage(bot, message, session.event.message = {}, session.event) - session.content = session.content.slice(1) + // content: /command@bot ...args + const [group] = session.content.split(' ', 1) + const [command, username] = group.slice(1).split('@') + if (username !== bot.user.name) return + session.content = command + session.content.slice(group.length) } else if (message) { if (update.message?.media_group_id) { if (!mediaGroupMap.has(update.message.media_group_id)) { mediaGroupMap.set(update.message.media_group_id, [new Date(), []]) }