Skip to content

Commit

Permalink
feat(discord, telegram): config.slash, fix koishijs/koishi#1192
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 8, 2023
1 parent 8f9d54a commit 5edd7fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions adapters/discord/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class DiscordBot extends Bot<DiscordBot.Config> {
}

async updateCommands(commands: Universal.Command[]) {
if (!this.config.slash) return
this.commands = commands
const local = Object.fromEntries(commands.map(cmd => [cmd.name, cmd] as const))
const remote = Object.fromEntries((await this.internal.getGlobalApplicationCommands(this.selfId, { with_localizations: true }))
Expand Down Expand Up @@ -250,12 +251,16 @@ function shapeEqual(a: any, b: any) {
export namespace DiscordBot {
export interface Config extends Bot.Config, Quester.Config, DiscordMessageEncoder.Config, WsClient.Config {
token: string
slash?: boolean
}

export const Config: Schema<Config> = Schema.intersect([
Schema.object({
token: Schema.string().description('机器人的用户令牌。').role('secret').required(),
}),
Schema.object({
slash: Schema.boolean().description('是否启用斜线指令。').default(true),
}).description('功能设置'),
WsClient.Config,
DiscordMessageEncoder.Config,
Quester.createConfig('https://discord.com/api/v10'),
Expand Down
5 changes: 5 additions & 0 deletions adapters/telegram/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ export class TelegramBot<T extends TelegramBot.Config = TelegramBot.Config> exte
}

async updateCommands(commands: Universal.Command[]) {
if (!this.config.slash) return
const result = {} as Record<string, Telegram.BotCommand[]>
for (const cmd of commands) {
const { name, description } = cmd
Expand Down Expand Up @@ -335,6 +336,7 @@ export namespace TelegramBot {
protocol: 'server' | 'polling'
token: string
files?: Config.Files
slash?: boolean
}

export type Config = BaseConfig & (HttpServer.Config | HttpPolling.Config)
Expand All @@ -358,6 +360,9 @@ export namespace TelegramBot {
HttpServer.Config,
HttpPolling.Config,
]).description('推送设置'),
Schema.object({
slash: Schema.boolean().description('是否启用斜线指令。').default(true),
}).description('功能设置'),
Quester.createConfig('https://api.telegram.org'),
Schema.object({
files: Schema.object({
Expand Down

0 comments on commit 5edd7fa

Please sign in to comment.