Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Telegram API Error BOT_COMMAND_INVALID 时 显示造成错误的指令 #1433

Closed
Ikaleio opened this issue Jul 31, 2024 · 8 comments
Closed
Labels

Comments

@Ikaleio
Copy link

Ikaleio commented Jul 31, 2024

Describe the problem related to the feature request

如果你的机器人有许多插件,那么接入 Telegram 时很可能会报如下错误:

2024-07-31 11:04:26 [W] app Error: Telegram API error 400. Bad Request: BOT_COMMAND_INVALID
                            at _Internal.<computed> [as setMyCommands] (/koishi/node_modules/@satorijs/adapter-telegram/lib/index.cjs:78:17)
                            at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                            at async Proxy.updateCommands (/koishi/node_modules/@satorijs/adapter-telegram/lib/index.cjs:1022:5)

这会导致斜杠指令无法使用且不与 Koishi 侧同步,若关闭斜杠指令则机器人不再响应 @ 它的消息。

Describe the solution you'd like

希望能在报错时显示哪个指令引发错误(如果 Telegram API 回传了此信息的话)

或者提供一个插件二分法等方式快速定位造成问题的插件(可能难以开发,不知道有没有别的方法)

Describe alternatives you've considered

No response

Additional context

No response

@Ikaleio Ikaleio added the feature 新特性 label Jul 31, 2024
@shigma
Copy link
Member

shigma commented Aug 7, 2024

嗯这个问题我们本身也比较困扰。

理论上我们应该在注册 telegram 斜线指令的时候就过滤掉不合法的部分。但是似乎 telegram 并没有给出具体的信息?(discord 的话返回值会包含具体哪个指令因为什么原因炸了。)

如果有人定位了出现问题的指令,可以回复此 issue,我们会添加注册前检查的逻辑。

@shigma shigma added bug BUG help wanted 欢迎 Pull Requests adapter: telegram and removed feature 新特性 labels Aug 7, 2024
@Ikaleio
Copy link
Author

Ikaleio commented Aug 7, 2024

Telegram API doc 说只有 32 字符以内的纯英文字母、数字、下划线受支持,除此之外没有其他相关内容

是否可能将带 . 的复合指令或中文指令或其他类似的东西传进去了?

感觉可以先加个 debug 在控制台显示到底往 Telegram API 传了什么指令。

@shigma
Copy link
Member

shigma commented Aug 7, 2024

如果你愿意帮忙调试的话,可以按照这个流程查看:

  1. 打开 koishi.yml,并加入以下内容:
+ logger:
+   levels:
+     telegram: 3

注意:不是写在 plugins 下面,而是与 plugins 同级放一个 logger。

  1. 重新运行 koishi,此时你将看到 telegram 适配器发出的所有请求。

@Ikaleio
Copy link
Author

Ikaleio commented Aug 8, 2024

2024-08-08 13:19:52 [D] telegram [response] { ok: true, result: true, description: 'Webhook was set' }
2024-08-08 13:19:52 [D] telegram listening updates telegram: 7331283530
2024-08-08 13:19:52 [D] telegram connected to telegram:7331283530
2024-08-08 13:19:52 [D] telegram [request] setMyCommands { commands: [ { command: 'command', description: '指令管理' }, { command: 'help', description: '显示帮助信息' }, { command: 'inspect', description: '查看用户、频道或消息的详细信息' }, { command: 'echo', description: '发送消息' }, { command: 'shutdown', description: '关闭或重启 Koishi' }, { command: 'jieba', description: '通过 jieba 分词' }, { command: 'clear', description: '清空聊天记录' }, { command: 'status', description: '查看运行状态' }, { command: 'wordclear', description: '清除本群的记录词数' }, { command: 'feedback', description: '发送反馈信息给作者' }, { command: 'novelai', description: 'AI 画图' }, { command: 'user', description: '用户管理' }, { command: 'channel', description: '频道管理' }, { command: 'authorize', description: '权限管理' }, { command: 'assign', description: '受理者账号' }, { command: 'bind', description: '绑定到账号' }, { command: 'usage', description: '调用次数信息' }, { command: 'timer', description: '定时器信息' }, { command: 'sudo', description: '在特定上下文中触发指令' }, { command: 'broadcast', description: '全服广播' }, { command: 'plugin', description: '插件管理' }, { command: 'cloud', description: '查询本群词云' } ], language_code: 'zh' }
2024-08-08 13:19:53 [D] telegram [response] { ok: true, result: true }
2024-08-08 13:19:53 [D] telegram [request] setMyCommands { commands: [ { command: 'help', description: 'Show help' }, { command: 'shutdown', description: 'Power off or reboot Koishi' }, { command: 'novelai', description: 'Generate Images from Novel AI' }, { command: 'bind', description: 'Bind to account' } ], language_code: 'en' }
2024-08-08 13:19:53 [D] telegram [response] { ok: true, result: true }
2024-08-08 13:19:53 [D] telegram [request] setMyCommands { commands: [ { command: 'novelai', description: 'Générer des images sur IA' } ], language_code: 'fr' }
2024-08-08 13:19:53 [D] telegram [response] { ok: true, result: true }
2024-08-08 13:19:53 [D] telegram [request] setMyCommands { commands: [ { command: 'novelai', description: 'AI で絵を描く' } ], language_code: 'ja' }
2024-08-08 13:19:54 [D] telegram [response] { ok: true, result: true }
2024-08-08 13:19:54 [D] telegram [request] setMyCommands { commands: [ { command: 'command', description: 'command' }, { command: 'help', description: 'help' }, { command: 'inspect', description: 'inspect' }, { command: 'echo', description: 'echo' }, { command: 'shutdown', description: 'shutdown' }, { command: 'jieba', description: 'jieba' }, { command: 'clear', description: 'clear' }, { command: 'status', description: 'status' }, { command: '隐藏图生成', description: '发送两张图片来进行隐藏图生成' }, { command: 'alpha-simple', description: 'alpha-simple' }, { command: 'wordclear', description: 'wordclear' }, { command: 'feedback', description: 'feedback' }, { command: 'chess', description: '棋类游戏' }, { command: 'novelai', description: 'novelai' }, { command: 'user', description: 'user' }, { command: 'channel', description: 'channel' }, { command: 'authorize', description: 'authorize' }, { command: 'assign', description: 'assign' }, { command: 'bind', description: 'bind' }, { command: 'usage', description: 'usage' }, { command: 'timer', description: 'timer' }, { command: '设置消息间隔', description: '设置本群聊消息的发送间隔' }, { command: 'sudo', description: 'sudo' }, { command: 'broadcast', description: 'broadcast' }, { command: 'mc', description: 'mc' }, { command: 'contest', description: '现在提供的比赛平台有:\ncodeforces(cf)\n洛谷(lg)\n' }, { command: 'list', description: '提供指定比赛日程' }, { command: 'messagecounter', description: '查看messageCounter帮助' }, { command: 'chatluna', description: 'chatluna' }, { command: 'plugin', description: 'plugin' }, { command: '喜报', description: '生成一张喜报' }, { command: '悲报', description: '生成一张悲报' }, { command: 'wordlegame', description: '猜单词游戏帮助' }, { command: 'cloud', description: 'cloud' }, { command: 'audio-reverse', description: '对语音进行倒放' } ] }
2024-08-08 13:19:54 [W] app Error: Telegram API error 400. Bad Request: BOT_COMMAND_INVALID
                            at _Internal.<computed> [as setMyCommands] (/koishi/node_modules/@satorijs/adapter-telegram/lib/index.cjs:78:17)
                            at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                            at async Proxy.updateCommands (/koishi/node_modules/@satorijs/adapter-telegram/lib/index.cjs:1022:5)

以上是一些可能有用的信息

@Ikaleio
Copy link
Author

Ikaleio commented Aug 8, 2024

我注意到问题似乎是由于部分命令(例如:alpha-simple 喜报 悲报)并不满足 Telegram 命令规范(32 字符以内的字母数字下划线)导致的,但问题是我确认已经将这些命令都设置了满足条件的别名,例如:

image

但传给 Telegram API 时仍然传了原始命令。

@Ikaleio
Copy link
Author

Ikaleio commented Aug 8, 2024

在我手动将它们的「斜杠指令」关闭后问题完全消失。

@Ikaleio
Copy link
Author

Ikaleio commented Aug 8, 2024

在测试过程中我还发现,当协议设置为「server」时,关闭插件疑似可能导致 webhook 不重置,造成机器人收不到消息,具体表现为发消息(即使是 /help)也无回复,日志无反应。不过这似乎应该另开一个 Issue。

@DGCK81LNN
Copy link
Contributor

DGCK81LNN commented Aug 9, 2024

Discord 中指令参数跟选项重名会报错,指令名含有中文似乎也不行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants