Skip to content

Commit

Permalink
feat(core): attach-user & attach-group event
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 24, 2020
1 parent bbcdab2 commit 8285c64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/koishi-core/src/app.ts
Expand Up @@ -359,6 +359,9 @@ export class App extends Context {
const group = await this.database.observeGroup(meta.groupId, Array.from(groupFields))
Object.defineProperty(meta, '$group', { value: group, writable: true })

// emit attach event
this.emitEvent(meta, 'attach-group', meta)

// ignore some group calls
const isAssignee = !group.assignee || group.assignee === this.selfId
const noCommand = group.flag & GroupFlag.noCommand
Expand All @@ -377,6 +380,7 @@ export class App extends Context {

// emit attach event
this.emitEvent(meta, 'attach', meta)
this.emitEvent(meta, 'attach-user', meta)

// ignore some user calls
if (user.flag & UserFlag.ignore) return
Expand Down
6 changes: 5 additions & 1 deletion packages/koishi-core/src/context.ts
Expand Up @@ -294,7 +294,8 @@ export interface EventMap {
'lifecycle/connect' (meta: Meta<'meta_event'>): any
'before-user' (fields: Set<UserField>, argv: ParsedCommandLine): any
'before-group' (fields: Set<GroupField>, argv: ParsedCommandLine): any
'attach' (meta: Meta<'message'>): any
'attach-user' (meta: Meta<'message'>): any
'attach-group' (meta: Meta<'message'>): any
'send' (meta: Meta<'send'>): any
'before-send' (meta: Meta<'send'>): any
'before-command' (argv: ParsedCommandLine): any
Expand All @@ -315,6 +316,9 @@ export interface EventMap {
'connect' (): any
'before-disconnect' (): any
'disconnect' (): any

// TODO: deprecated events
'attach' (meta: Meta<'message'>): any
}

export type Events = keyof EventMap
Expand Down

0 comments on commit 8285c64

Please sign in to comment.