Skip to content

Commit

Permalink
feat(core): support bot.supports() for permission API
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jul 31, 2023
1 parent 88f6f23 commit 0f373ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class Quester {
return this('PATCH', url, { ...config, data })
}

async head(url: string, config?: AxiosRequestConfig): Promise<Dict<string>> {
async head(url: string, config?: AxiosRequestConfig): Promise<Dict<any>> {
const response = await this.axios(url, { ...config, method: 'HEAD' })
return response.headers
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export abstract class Bot<T extends Bot.Config = Bot.Config> {
const { MessageEncoder } = this.constructor as typeof Bot
return new MessageEncoder(this, channelId, null, options).send(content)
}

async supports(name: string, session: Partial<Session> = {}) {
return !!this[Universal.Methods[name]]
}
}

export namespace Bot {
Expand Down
25 changes: 25 additions & 0 deletions packages/core/src/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ import { SendOptions } from './session'
import { Dict } from 'cosmokit'

export namespace Universal {
export const Methods = {
'message.get': 'getMessage',
'message.list': 'getMessageList',
'message.update': 'editMessage',
'message.delete': 'deleteMessage',
'reaction.create': 'createReaction',
'reaction.delete': 'deleteReaction',
'reaction.clear': 'clearReaction',
'reaction.list': 'getReactions',
'guild.get': 'getGuild',
'guild.list': 'getGuildList',
'guild.member.get': 'getGuildMember',
'guild.member.list': 'getGuildMemberList',
'guild.member.kick': 'kickGuildMember',
'guild.member.mute': 'muteGuildMember',
'guild.member.role': 'setGuildMemberRole',
'guild.role.list': 'getGuildRoles',
'guild.role.create': 'createGuildRole',
'guild.role.update': 'modifyGuildRole',
'guild.role.delete': 'deleteGuildRole',
'channel.get': 'getChannel',
'channel.list': 'getChannelList',
'channel.mute': 'muteChannel',
}

export interface Methods {
// message
sendMessage(channelId: string, content: segment.Fragment, guildId?: string, options?: SendOptions): Promise<string[]>
Expand Down

0 comments on commit 0f373ba

Please sign in to comment.