Merge branch 'rewrite' of https://github.com/xHyroM/roles-bot into rewrite

This commit is contained in:
OLIMINATOR 2023-04-08 14:18:19 +02:00
commit f25e3fdcd4
3 changed files with 16 additions and 9 deletions

View file

@ -88,6 +88,7 @@ export default {
return new Response("Unknown component", { status: 404 });
try {
if (component.acknowledge)
return respond({
type: InteractionResponseType.DeferredChannelMessageWithSource,
data: {
@ -95,7 +96,10 @@ export default {
},
});
} finally {
if (component.acknowledge)
component.run(new ComponentContext(interaction, env));
// rome-ignore lint/correctness/noUnsafeFinally: it works, must do better typings etc...
else return component.run(new ComponentContext(interaction, env));
}
}
}

View file

@ -9,7 +9,7 @@ interface CommandOptions {
run: (interaction: CommandContext) => void;
}
export class Command<A> {
export class Command {
public name: string;
public acknowledge: boolean;
public flags: MessageFlags | undefined;

View file

@ -4,17 +4,20 @@ import { ComponentContext } from "./contexts/ComponentContext";
interface ComponentOptions {
id: string;
acknowledge?: boolean;
flags?: MessageFlags;
run: (interaction: ComponentContext) => void;
}
export class Component {
public id: string;
public acknowledge: boolean;
public flags: MessageFlags | undefined;
public run: (interaction: ComponentContext) => void;
public run: (interaction: ComponentContext) => void | Response;
constructor(options: ComponentOptions) {
this.id = options.id;
this.acknowledge = options.acknowledge ?? true;
this.flags = options.flags;
this.run = options.run;