refactor(menu): Made sure the menu can be used for more than group
This commit is contained in:
parent
a79898b2e9
commit
1d73ee8a78
16 changed files with 650 additions and 406 deletions
|
|
@ -1,25 +1,33 @@
|
|||
import {
|
||||
AutocompleteInteraction,
|
||||
AnySelectMenuInteraction,
|
||||
AutocompleteInteraction, ButtonInteraction,
|
||||
ChatInputCommandInteraction,
|
||||
inlineCode,
|
||||
Interaction,
|
||||
MessageFlags,
|
||||
MessageFlags, ModalSubmitInteraction,
|
||||
} from "discord.js";
|
||||
import Commands from "./Commands/Commands";
|
||||
import {Logger} from "log4js";
|
||||
import {UserError} from "./UserError";
|
||||
import {Container} from "../Container/Container";
|
||||
import {EventHandler} from "../Events/EventHandler";
|
||||
import {ModalInteractionEvent} from "../Events/ModalInteractionEvent";
|
||||
import {ComponentInteractionEvent} from "../Events/ComponentInteractionEvent";
|
||||
|
||||
enum InteractionRoutingType {
|
||||
Unrouted,
|
||||
Command,
|
||||
AutoComplete,
|
||||
ModalSubmit,
|
||||
ButtonSubmit,
|
||||
MenuSubmit,
|
||||
}
|
||||
|
||||
export class InteractionRouter {
|
||||
constructor(
|
||||
public readonly commands: Commands,
|
||||
public readonly logger: Logger
|
||||
public readonly logger: Logger,
|
||||
private readonly events: EventHandler
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +44,12 @@ export class InteractionRouter {
|
|||
case InteractionRoutingType.AutoComplete:
|
||||
await this.handleAutocomplete(<AutocompleteInteraction>interaction)
|
||||
break;
|
||||
case InteractionRoutingType.ModalSubmit:
|
||||
this.events.dispatch(new ModalInteractionEvent(<ModalSubmitInteraction>interaction));
|
||||
break;
|
||||
case InteractionRoutingType.ButtonSubmit:
|
||||
case InteractionRoutingType.MenuSubmit:
|
||||
this.events.dispatch(new ComponentInteractionEvent(<ButtonInteraction|AnySelectMenuInteraction>interaction))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +61,17 @@ export class InteractionRouter {
|
|||
if (interaction.isAutocomplete()) {
|
||||
return InteractionRoutingType.AutoComplete;
|
||||
}
|
||||
|
||||
if (interaction.isModalSubmit()) {
|
||||
return InteractionRoutingType.ModalSubmit;
|
||||
}
|
||||
|
||||
if (interaction.isButton()) {
|
||||
return InteractionRoutingType.ButtonSubmit;
|
||||
}
|
||||
if (interaction.isAnySelectMenu()) {
|
||||
return InteractionRoutingType.MenuSubmit;
|
||||
}
|
||||
|
||||
return InteractionRoutingType.Unrouted;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue