Skip to content

Commit

Permalink
feat(chat): use context filter instead of config
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 18, 2021
1 parent 2827a5c commit 2060ed5
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/koishi/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function createWatcher() {

const logger = new Logger('app:watcher')
function triggerFullReload() {
if (!fullReload) return
if (fullReload === false) return
logger.info('trigger full reload')
process.exit(114)
}
Expand Down
9 changes: 1 addition & 8 deletions packages/plugin-chat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ declare module 'koishi-plugin-webui' {

export interface Config extends ReceiverConfig {
whitelist?: string[]
includeUsers?: string[]
includeChannels?: string[]
}

template.set('chat', {
Expand Down Expand Up @@ -57,15 +55,10 @@ const builtinWhitelist = [
export const name = 'chat'

export function apply(ctx: Context, options: Config = {}) {
const { includeUsers, includeChannels } = options

ctx.plugin(receiver, options)

ctx.on('chat/receive', async (message, session) => {
if (session.subtype === 'private') {
if (includeUsers && !includeUsers.includes(session.userId)) return
} else {
if (includeChannels && !includeChannels.includes(session.channelId)) return
if (session.subtype !== 'private') {
const { assignee } = await session.observeChannel(['assignee'])
if (assignee !== session.selfId) return
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-chat/src/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ export default function apply(ctx: Context, config: ReceiverConfig = {}) {
ctx.emit('chat/receive', params, session)
}

ctx.on('message', handleMessage)
ctx.on('send', handleMessage)
ctx.all().on('message', handleMessage)
ctx.all().on('send', handleMessage)
}

0 comments on commit 2060ed5

Please sign in to comment.