Skip to content

Commit

Permalink
fix(accepted events): ensure duration isn't destructured when not ava…
Browse files Browse the repository at this point in the history
…ilable
  • Loading branch information
favna committed Jan 22, 2022
1 parent 85b241e commit 1269305
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ export class CoreListener extends Listener<typeof Events.ChatInputCommandAccepte

const result = await fromAsync(async () => {
this.container.client.emit(Events.ChatInputCommandRun, interaction, command, { ...payload });

const stopwatch = new Stopwatch();
const result = await command.chatInputRun(interaction, context);
const { duration } = stopwatch.stop();

this.container.client.emit(Events.ChatInputCommandSuccess, { ...payload, result, duration });

return { result, duration };
return duration;
});

const { duration } = result.value ?? { duration: -1 };

if (isErr(result)) {
this.container.client.emit(Events.ChatInputCommandError, result.error, { ...payload, duration });
this.container.client.emit(Events.ChatInputCommandError, result.error, { ...payload, duration: result.value ?? -1 });
}

this.container.client.emit(Events.ChatInputCommandFinish, interaction, command, { ...payload, duration });
this.container.client.emit(Events.ChatInputCommandFinish, interaction, command, { ...payload, duration: result.value ?? -1 });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ export class CoreListener extends Listener<typeof Events.ContextMenuCommandAccep

const result = await fromAsync(async () => {
this.container.client.emit(Events.ContextMenuCommandRun, interaction, command, { ...payload });

const stopwatch = new Stopwatch();
const result = await command.contextMenuRun(interaction, context);
const { duration } = stopwatch.stop();

this.container.client.emit(Events.ContextMenuCommandSuccess, { ...payload, result, duration });

return { result, duration };
return duration;
});

const { duration } = result.value ?? { duration: -1 };

if (isErr(result)) {
this.container.client.emit(Events.ContextMenuCommandError, result.error, { ...payload, duration });
this.container.client.emit(Events.ContextMenuCommandError, result.error, { ...payload, duration: result.value ?? -1 });
}

this.container.client.emit(Events.ContextMenuCommandFinish, interaction, command, { ...payload, duration });
this.container.client.emit(Events.ContextMenuCommandFinish, interaction, command, { ...payload, duration: result.value ?? -1 });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export class CoreListener extends Listener<typeof Events.MessageCommandAccepted>

const result = await fromAsync(async () => {
message.client.emit(Events.MessageCommandRun, message, command, { ...payload, args });

const stopwatch = new Stopwatch();
const result = await command.messageRun(message, args, context);
const { duration } = stopwatch.stop();

message.client.emit(Events.MessageCommandSuccess, { ...payload, args, result, duration });

return { result, duration };
return duration;
});

const { duration } = result.value ?? { duration: -1 };

if (isErr(result)) {
message.client.emit(Events.MessageCommandError, result.error, { ...payload, args, duration });
message.client.emit(Events.MessageCommandError, result.error, { ...payload, args, duration: result.value ?? -1 });
}

message.client.emit(Events.MessageCommandFinish, message, command, { ...payload, args, duration });
message.client.emit(Events.MessageCommandFinish, message, command, { ...payload, args, duration: result.value ?? -1 });
}
}

0 comments on commit 1269305

Please sign in to comment.