feat(bot): 新增命令列表更新功能.

增加`命令列表更新`功能, 该功能可根据已加载的 Ability, 调用 Telegram Bot API 更新命令列表.
后续会尝试支持 BotCommandScope.
This commit is contained in:
2022-03-15 15:18:04 +08:00
parent de83d2c3d3
commit 4b20b0cc59
3 changed files with 47 additions and 0 deletions

View File

@ -119,6 +119,20 @@ internal class Launcher : AutoCloseable {
)
botSessionMap[bot] = botApi.registerBot(bot)
log.info { "机器人 `${bot.botUsername}` 已启动." }
if (botConfig.autoUpdateCommandList) {
log.debug { "[Bot ${botConfig.account.name}] 正在自动更新命令列表..." }
try {
val result = bot.updateCommandList()
if (result) {
log.info { "[Bot ${botConfig.account.name}] 已成功更新 Bot 命令列表." }
} else {
log.warn { "[Bot ${botConfig.account.name}] 自动更新 Bot 命令列表失败!" }
}
} catch (e: Exception) {
log.warn(e) { "命令列表自动更新失败." }
}
}
}
@Synchronized