Add support to handle string dropdowns
This commit is contained in:
parent
c5fc99d658
commit
39d44cf8dd
7 changed files with 75 additions and 0 deletions
|
@ -38,6 +38,7 @@ const client = new CoreClient([
|
||||||
|
|
||||||
Registry.RegisterCommands();
|
Registry.RegisterCommands();
|
||||||
Registry.RegisterButtonEvents();
|
Registry.RegisterButtonEvents();
|
||||||
|
Registry.RegisterStringDropdownEvents();
|
||||||
|
|
||||||
if (!existsSync(`${process.env.DATA_DIR}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == "true") {
|
if (!existsSync(`${process.env.DATA_DIR}/cards`) && process.env.GDRIVESYNC_AUTO && process.env.GDRIVESYNC_AUTO == "true") {
|
||||||
console.log("Card directory not found, syncing...");
|
console.log("Card directory not found, syncing...");
|
||||||
|
|
|
@ -17,11 +17,14 @@ import AppLogger from "./appLogger";
|
||||||
import TimerHelper from "../helpers/TimerHelper";
|
import TimerHelper from "../helpers/TimerHelper";
|
||||||
import GiveCurrency from "../timers/GiveCurrency";
|
import GiveCurrency from "../timers/GiveCurrency";
|
||||||
import PurgeClaims from "../timers/PurgeClaims";
|
import PurgeClaims from "../timers/PurgeClaims";
|
||||||
|
import StringDropdownEventItem from "../contracts/StringDropdownEventItem";
|
||||||
|
import {StringDropdownEvent} from "../type/stringDropdownEvent";
|
||||||
|
|
||||||
export class CoreClient extends Client {
|
export class CoreClient extends Client {
|
||||||
private static _commandItems: ICommandItem[];
|
private static _commandItems: ICommandItem[];
|
||||||
private static _eventExecutors: EventExecutors;
|
private static _eventExecutors: EventExecutors;
|
||||||
private static _buttonEvents: IButtonEventItem[];
|
private static _buttonEvents: IButtonEventItem[];
|
||||||
|
private static _stringDropdowns: StringDropdownEventItem[];
|
||||||
|
|
||||||
private _events: Events;
|
private _events: Events;
|
||||||
private _util: Util;
|
private _util: Util;
|
||||||
|
@ -45,6 +48,10 @@ export class CoreClient extends Client {
|
||||||
return this._buttonEvents;
|
return this._buttonEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static get stringDropdowns(): StringDropdownEventItem[] {
|
||||||
|
return this._stringDropdowns;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(intents: number[]) {
|
constructor(intents: number[]) {
|
||||||
super({ intents: intents });
|
super({ intents: intents });
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
@ -59,6 +66,7 @@ export class CoreClient extends Client {
|
||||||
|
|
||||||
CoreClient._commandItems = [];
|
CoreClient._commandItems = [];
|
||||||
CoreClient._buttonEvents = [];
|
CoreClient._buttonEvents = [];
|
||||||
|
CoreClient._stringDropdowns = [];
|
||||||
|
|
||||||
this._events = new Events();
|
this._events = new Events();
|
||||||
this._util = new Util();
|
this._util = new Util();
|
||||||
|
@ -408,4 +416,19 @@ export class CoreClient extends Client {
|
||||||
AppLogger.LogVerbose("Client", `Registered Button Event: ${buttonId}`);
|
AppLogger.LogVerbose("Client", `Registered Button Event: ${buttonId}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RegisterStringDropdownEvent(dropdownId: string, event: StringDropdownEvent, environment: Environment = Environment.All) {
|
||||||
|
const item: StringDropdownEventItem = {
|
||||||
|
DropdownId: dropdownId,
|
||||||
|
Event: event,
|
||||||
|
Environment: environment,
|
||||||
|
};
|
||||||
|
|
||||||
|
if ((environment & CoreClient.Environment) == CoreClient.Environment) {
|
||||||
|
CoreClient._stringDropdowns.push(item);
|
||||||
|
|
||||||
|
AppLogger.LogVerbose("Client", `Registered String Dropdown Event: ${dropdownId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,10 @@ export class Events {
|
||||||
AppLogger.LogVerbose("Client", `Button: ${interaction.customId}`);
|
AppLogger.LogVerbose("Client", `Button: ${interaction.customId}`);
|
||||||
Button.onButtonClicked(interaction);
|
Button.onButtonClicked(interaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (interaction.isStringSelectMenu()) {
|
||||||
|
AppLogger.LogVerbose("Client", `StringDropdown: ${interaction.customId}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit when bot is logged in and ready to use
|
// Emit when bot is logged in and ready to use
|
||||||
|
|
29
src/client/interactionCreate/StringDropdown.ts
Normal file
29
src/client/interactionCreate/StringDropdown.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import {StringSelectMenuInteraction} from "discord.js";
|
||||||
|
import {CoreClient} from "../client";
|
||||||
|
import AppLogger from "../appLogger";
|
||||||
|
|
||||||
|
export default class StringDropdown {
|
||||||
|
public static async onStringDropdownSelected(interaction: StringSelectMenuInteraction) {
|
||||||
|
if (!interaction.isStringSelectMenu()) return;
|
||||||
|
|
||||||
|
const item = CoreClient.stringDropdowns.find(x => x.DropdownId == interaction.customId.split(" ")[0]);
|
||||||
|
|
||||||
|
if (!item) {
|
||||||
|
AppLogger.LogVerbose("StringDropdown", `Event not found: ${interaction.customId}`);
|
||||||
|
|
||||||
|
await interaction.reply("Event not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
AppLogger.LogDebug("StringDropdown", `Executing ${interaction.customId}`);
|
||||||
|
|
||||||
|
item.Event.execute(interaction);
|
||||||
|
} catch (e) {
|
||||||
|
AppLogger.LogError("StringDropdown", `Error occurred while executing event: ${interaction.customId}`);
|
||||||
|
AppLogger.LogError("StringDropdown", e as string);
|
||||||
|
|
||||||
|
await interaction.reply("An error occurred while executing the event");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/contracts/StringDropdownEventItem.ts
Normal file
10
src/contracts/StringDropdownEventItem.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import {Environment} from "../constants/Environment";
|
||||||
|
import {StringDropdownEvent} from "../type/stringDropdownEvent";
|
||||||
|
|
||||||
|
interface StringDropdownEventItem {
|
||||||
|
DropdownId: string,
|
||||||
|
Event: StringDropdownEvent,
|
||||||
|
Environment: Environment,
|
||||||
|
}
|
||||||
|
|
||||||
|
export default StringDropdownEventItem;
|
|
@ -64,4 +64,7 @@ export default class Registry {
|
||||||
CoreClient.RegisterButtonEvent("trade", new TradeButtonEvent());
|
CoreClient.RegisterButtonEvent("trade", new TradeButtonEvent());
|
||||||
CoreClient.RegisterButtonEvent("view", new ViewButtonEvent());
|
CoreClient.RegisterButtonEvent("view", new ViewButtonEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RegisterStringDropdownEvents() {
|
||||||
|
}
|
||||||
}
|
}
|
5
src/type/stringDropdownEvent.ts
Normal file
5
src/type/stringDropdownEvent.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import {StringSelectMenuInteraction} from "discord.js";
|
||||||
|
|
||||||
|
export abstract class StringDropdownEvent {
|
||||||
|
abstract execute(interaction: StringSelectMenuInteraction): Promise<void>;
|
||||||
|
}
|
Loading…
Reference in a new issue