Skip to content

Commit 8153582

Browse files
committed
feat: new events
1 parent 555d054 commit 8153582

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

src/handlers/AutocompleteHandler.ts

+2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ export async function AutocompleteHandler(interaction: AutocompleteInteraction)
4141
await Promise.resolve(argument.run(ctx))
4242
.catch((error) => {
4343
Logger.emit(LoggerEvents.HANDLER_ERROR, ctx, error);
44+
Logger.emit(LoggerEvents.AUTOCOMPLETE_HANDLER_ERROR, ctx, error);
4445
Logger.error(typeof error.code !== 'undefined' ? error.code : '', error.message);
4546
if (error.stack) Logger.trace(error.stack);
4647
})
4748
.then(() => {
4849
Logger.emit(LoggerEvents.HANDLER_RUN, ctx);
50+
Logger.emit(LoggerEvents.AUTOCOMPLETE_HANDLER_RUN, ctx);
4951
Logger.debug(
5052
`Successfully ran autocomplete (${argument.name} -> ${command.name}) for ${interaction.user.username}`,
5153
);

src/handlers/ComponentHandler.ts

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export async function ComponentHandler(interaction: MessageComponentInteraction)
7272
await Promise.resolve(component.run(ctx))
7373
.catch(async (error) => {
7474
Logger.emit(LoggerEvents.HANDLER_ERROR, ctx, error);
75+
Logger.emit(LoggerEvents.COMPONENT_HANDLER_ERROR, ctx, error);
7576
Logger.error(typeof error.code !== 'undefined' ? error.code : '', error.message);
7677
if (error.stack) Logger.trace(error.stack);
7778
const errorReply = () =>
@@ -86,6 +87,7 @@ export async function ComponentHandler(interaction: MessageComponentInteraction)
8687
})
8788
.then(() => {
8889
Logger.emit(LoggerEvents.HANDLER_RUN, ctx);
90+
Logger.emit(LoggerEvents.COMPONENT_HANDLER_RUN, ctx);
8991
if (autoDeferTimeout) clearTimeout(autoDeferTimeout);
9092
Logger.debug(`Successfully ran component (${component.name}) for ${interaction.user.username}`);
9193
});

src/handlers/InteractionCommandHandler.ts

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export async function InteractionCommandHandler(interaction: CommandInteraction
6363
await Promise.resolve(command.run(ctx))
6464
.catch(async (error) => {
6565
Logger.emit(LoggerEvents.HANDLER_ERROR, ctx, error);
66+
Logger.emit(LoggerEvents.COMMAND_HANDLER_ERROR, ctx, error);
6667
Logger.error(typeof error.code !== 'undefined' ? error.code : '', error.message);
6768
if (error.stack) Logger.trace(error.stack);
6869
const errorReply = () =>
@@ -78,6 +79,7 @@ export async function InteractionCommandHandler(interaction: CommandInteraction
7879
})
7980
.then(() => {
8081
Logger.emit(LoggerEvents.HANDLER_RUN, ctx);
82+
Logger.emit(LoggerEvents.COMMAND_HANDLER_RUN, ctx);
8183
if (autoDeferTimeout) clearTimeout(autoDeferTimeout);
8284
Logger.debug(`Successfully ran command (${command.name}) for ${interaction.user.username}`);
8385
});

src/handlers/MessageCommandHandler.ts

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export async function MessageCommandHandler(
9393
await Promise.resolve(command.run(ctx))
9494
.catch(async (error) => {
9595
Logger.emit(LoggerEvents.HANDLER_ERROR, ctx, error);
96+
Logger.emit(LoggerEvents.COMMAND_HANDLER_ERROR, ctx, error);
9697
Logger.error(typeof error.code !== 'undefined' ? error.code : '', error.message);
9798
if (error.stack) Logger.trace(error.stack);
9899
const errorReply = () =>
@@ -106,6 +107,7 @@ export async function MessageCommandHandler(
106107
})
107108
.then(() => {
108109
Logger.emit(LoggerEvents.HANDLER_RUN, ctx);
110+
Logger.emit(LoggerEvents.COMMAND_HANDLER_RUN, ctx);
109111
Logger.debug(`Successfully ran command (${command.name}) for ${message.author.username}`);
110112
});
111113
}

src/lib/util/logger/Logger.ts

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import type { Plugin } from '../../structures/Plugin';
1515
export enum LoggerEvents {
1616
'HANDLER_RUN' = 'handlerRun',
1717
'HANDLER_ERROR' = 'handlerError',
18+
'COMMAND_HANDLER_RUN' = 'commandHandlerRun',
19+
'COMMAND_HANDLER_ERROR' = 'commandHandlerError',
20+
'AUTOCOMPLETE_HANDLER_RUN' = 'autoCompleteHandlerRun',
21+
'AUTOCOMPLETE_HANDLER_ERROR' = 'autoCompleteHandlerError',
22+
'COMPONENT_HANDLER_RUN' = 'componentHandlerRun',
23+
'COMPONENT_HANDLER_ERROR' = 'componentHandlerError',
1824
'COMMAND_REGISTERED' = 'commandRegistered',
1925
'COMMAND_UNREGISTERED' = 'commandUnregistered',
2026
'COMPONENT_REGISTERED' = 'componentRegistered',
@@ -27,6 +33,12 @@ export enum LoggerEvents {
2733
export interface LoggerEventsInterface {
2834
'handlerRun': (ctx: AutocompleteContext | CommandContext | ComponentContext) => void;
2935
'handlerError': (ctx: AutocompleteContext | CommandContext | ComponentContext, error: any) => void;
36+
'commandHandlerRun': (ctx: CommandContext) => void;
37+
'commandHandlerError': (ctx: CommandContext, error: any) => void;
38+
'autoCompleteHandlerRun': (ctx: AutocompleteContext) => void;
39+
'autoCompleteHandlerError': (ctx: AutocompleteContext, error: any) => void;
40+
'componentHandlerRun': (ctx: ComponentContext) => void;
41+
'componentHandlerError': (ctx: ComponentContext, error: any) => void;
3042
'commandRegistered': (command: Command) => void;
3143
'commandUnregistered': (command: Command) => void;
3244
'componentRegistered': (component: Component) => void;

0 commit comments

Comments
 (0)