Skip to content

Commit

Permalink
feat(core): support experimental bot.checkPermission()
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 28, 2023
1 parent 6168c47 commit 84930aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion adapters/onebot/src/bot/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Bot, Context, noop, Schema } from '@satorijs/satori'
import { Bot, Context, noop, Schema, Session } from '@satorijs/satori'
import { HttpServer } from '../http'
import { WsClient, WsServer } from '../ws'
import { QQGuildBot } from './qqguild'
Expand Down Expand Up @@ -95,6 +95,15 @@ export class OneBotBot<T extends OneBotBot.Config = OneBotBot.Config> extends Ba
async muteChannel(channelId: string, guildId?: string, enable?: boolean) {
return this.internal.setGroupWholeBan(channelId, enable)
}

async checkPermission(name: string, session: Partial<Session>) {
if (name === 'onebot.group.admin') {
return session.author?.roles?.[0] === 'admin'
} else if (name === 'onebot.group.owner') {
return session.author?.roles?.[0] === 'owner'
}
return super.checkPermission(name, session)
}
}

export namespace OneBotBot {
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export abstract class Bot<T extends Bot.Config = Bot.Config> {
async supports(name: string, session: Partial<Session> = {}) {
return !!this[Universal.Methods[name]]
}

async checkPermission(name: string, session: Partial<Session>) {
if (name.startsWith('bot.')) {
return this.supports(name.slice(4), session)
}
}
}

export namespace Bot {
Expand Down

0 comments on commit 84930aa

Please sign in to comment.