-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfaf2c5
commit ac6c134
Showing
16 changed files
with
140 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { USE_INTERCEPTORS_DECORATOR } from '../constant/discord.constant'; | ||
import { DiscordInterceptor } from '..'; | ||
|
||
/** | ||
* UseInterceptor decorator | ||
*/ | ||
export const UseInterceptors = (...interceptors: (DiscordInterceptor | Function)[]): MethodDecorator => { | ||
return ( | ||
target: Record<string, any>, | ||
propertyKey: string | symbol, | ||
descriptor: PropertyDescriptor, | ||
): PropertyDescriptor => { | ||
Reflect.defineMetadata(USE_INTERCEPTORS_DECORATOR, interceptors, target, propertyKey); | ||
return descriptor; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { ClientEvents } from "discord.js"; | ||
|
||
/** | ||
* Base interceptor interface | ||
*/ | ||
export interface DiscordInterceptor<T = any> { | ||
intercept( | ||
event: keyof ClientEvents, | ||
context: T | ||
): any | Promise<any>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { DiscordInterceptor } from '..'; | ||
import { ClientEvents, Message } from 'discord.js'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class DiscordInterceptorService { | ||
async applyInterceptors( | ||
interceptors: (DiscordInterceptor | Function)[], | ||
event: keyof ClientEvents, | ||
context: any | ||
): Promise<any> { | ||
return interceptors.reduce(async (prev: Promise<Message>, curr: DiscordInterceptor | Function) => { | ||
let interceptorInstance: DiscordInterceptor; | ||
if (typeof curr === 'function') { | ||
// @ts-ignore | ||
interceptorInstance = new curr(); | ||
} | ||
const prevData = await prev; | ||
return interceptorInstance.intercept(event, prevData); | ||
}, context); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
lib/discord-middleware.service.ts → lib/service/discord-middleware.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isClassDecorator = (target: any): boolean => { | ||
return typeof target === 'function'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters