@stelliajs/framework 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/StelliaClient.d.ts +27 -0
- package/dist/client/StelliaClient.js +37 -0
- package/dist/client/StelliaUtils.d.ts +18 -0
- package/dist/client/StelliaUtils.js +164 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/constants/apiVersion.d.ts +1 -0
- package/dist/constants/apiVersion.js +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/managers/AutoCompleteManager.d.ts +11 -0
- package/dist/managers/AutoCompleteManager.js +21 -0
- package/dist/managers/BaseManager.d.ts +15 -0
- package/dist/managers/BaseManager.js +9 -0
- package/dist/managers/ButtonManager.d.ts +12 -0
- package/dist/managers/ButtonManager.js +21 -0
- package/dist/managers/CommandManager.d.ts +12 -0
- package/dist/managers/CommandManager.js +21 -0
- package/dist/managers/ContextMenuManager.d.ts +12 -0
- package/dist/managers/ContextMenuManager.js +21 -0
- package/dist/managers/EventManager.d.ts +12 -0
- package/dist/managers/EventManager.js +30 -0
- package/dist/managers/ModalManager.d.ts +12 -0
- package/dist/managers/ModalManager.js +21 -0
- package/dist/managers/SelectMenuManager.d.ts +12 -0
- package/dist/managers/SelectMenuManager.js +21 -0
- package/dist/managers/index.d.ts +8 -0
- package/dist/managers/index.js +8 -0
- package/dist/structures/Event.d.ts +11 -0
- package/dist/structures/Event.js +1 -0
- package/dist/structures/Interaction.d.ts +32 -0
- package/dist/structures/Interaction.js +1 -0
- package/dist/structures/index.d.ts +2 -0
- package/dist/structures/index.js +2 -0
- package/dist/typescript/index.d.ts +1 -0
- package/dist/typescript/index.js +1 -0
- package/dist/typescript/types.d.ts +39 -0
- package/dist/typescript/types.js +10 -0
- package/dist/utils/ephemeralReponse.d.ts +3 -0
- package/dist/utils/ephemeralReponse.js +38 -0
- package/dist/utils/files.d.ts +4 -0
- package/dist/utils/files.js +35 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/package.json +24 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Client, type ClientOptions } from "discord.js";
|
|
2
|
+
import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager, EventManager, type ManagerOptions, ModalManager, SelectMenuManager } from "../managers/index.js";
|
|
3
|
+
import { type AnyInteraction } from "../typescript/index.js";
|
|
4
|
+
export declare class StelliaClient<Ready extends boolean = boolean> extends Client<Ready> {
|
|
5
|
+
private readonly utils;
|
|
6
|
+
readonly autoCompletes: AutoCompleteManager;
|
|
7
|
+
readonly buttons: ButtonManager;
|
|
8
|
+
readonly commands: CommandManager;
|
|
9
|
+
readonly contextMenus: ContextMenuManager;
|
|
10
|
+
readonly events: EventManager;
|
|
11
|
+
readonly selectMenus: SelectMenuManager;
|
|
12
|
+
readonly modals: ModalManager;
|
|
13
|
+
constructor(clientOptions: ClientOptions, stelliaOptions: StelliaOptions);
|
|
14
|
+
connect: (token: string) => Promise<void>;
|
|
15
|
+
initializeCommands: () => Promise<void>;
|
|
16
|
+
handleInteraction: (interaction: AnyInteraction) => Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
interface StelliaOptions {
|
|
19
|
+
autoCompletes: ManagerOptions;
|
|
20
|
+
buttons: ManagerOptions;
|
|
21
|
+
commands: ManagerOptions;
|
|
22
|
+
contextMenus: ManagerOptions;
|
|
23
|
+
events: ManagerOptions;
|
|
24
|
+
selectMenus: ManagerOptions;
|
|
25
|
+
modals: ManagerOptions;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Client, Events } from "discord.js";
|
|
2
|
+
import { AutoCompleteManager, ButtonManager, CommandManager, ContextMenuManager, EventManager, ModalManager, SelectMenuManager } from "../managers/index.js";
|
|
3
|
+
import { StelliaUtils } from "./index.js";
|
|
4
|
+
export class StelliaClient extends Client {
|
|
5
|
+
utils;
|
|
6
|
+
autoCompletes;
|
|
7
|
+
buttons;
|
|
8
|
+
commands;
|
|
9
|
+
contextMenus;
|
|
10
|
+
events;
|
|
11
|
+
selectMenus;
|
|
12
|
+
modals;
|
|
13
|
+
constructor(clientOptions, stelliaOptions) {
|
|
14
|
+
super(clientOptions);
|
|
15
|
+
this.utils = new StelliaUtils(this);
|
|
16
|
+
this.autoCompletes = new AutoCompleteManager(this, stelliaOptions.autoCompletes.directoryPath);
|
|
17
|
+
this.buttons = new ButtonManager(this, stelliaOptions.buttons.directoryPath);
|
|
18
|
+
this.commands = new CommandManager(this, stelliaOptions.commands.directoryPath);
|
|
19
|
+
this.contextMenus = new ContextMenuManager(this, stelliaOptions.contextMenus.directoryPath);
|
|
20
|
+
this.events = new EventManager(this, stelliaOptions.events.directoryPath);
|
|
21
|
+
this.selectMenus = new SelectMenuManager(this, stelliaOptions.selectMenus.directoryPath);
|
|
22
|
+
this.modals = new ModalManager(this, stelliaOptions.modals.directoryPath);
|
|
23
|
+
}
|
|
24
|
+
connect = async (token) => {
|
|
25
|
+
this.on(Events.Error, (error) => console.error(error));
|
|
26
|
+
await this.login(token);
|
|
27
|
+
process.on("unhandledRejection", (error) => {
|
|
28
|
+
console.error(`Unhandled promise rejection: ${error}`);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
initializeCommands = async () => {
|
|
32
|
+
await this.utils.initializeCommands();
|
|
33
|
+
};
|
|
34
|
+
handleInteraction = async (interaction) => {
|
|
35
|
+
await this.utils.handleInteraction(interaction);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type StelliaClient } from "./index.js";
|
|
2
|
+
import { AnyInteraction } from "../typescript/index.js";
|
|
3
|
+
export declare class StelliaUtils {
|
|
4
|
+
readonly client: StelliaClient;
|
|
5
|
+
private readonly interactionHandlers;
|
|
6
|
+
constructor(client: StelliaClient);
|
|
7
|
+
initializeCommands: () => Promise<void>;
|
|
8
|
+
handleInteraction: (interaction: AnyInteraction) => Promise<void>;
|
|
9
|
+
private handleAutoCompleteInteraction;
|
|
10
|
+
private handleButtonInteraction;
|
|
11
|
+
private handleCommandInteraction;
|
|
12
|
+
private handleContextMenuInteraction;
|
|
13
|
+
private handleModalInteraction;
|
|
14
|
+
private handleSelectMenuInteraction;
|
|
15
|
+
private handleMessageContextMenuInteraction;
|
|
16
|
+
private handleUserContextMenuInteraction;
|
|
17
|
+
private getInteractionType;
|
|
18
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { ApplicationCommandType, REST, Routes } from "discord.js";
|
|
2
|
+
import { DISCORD_API_VERSION } from "../constants/index.js";
|
|
3
|
+
import { InteractionType } from "../typescript/index.js";
|
|
4
|
+
export class StelliaUtils {
|
|
5
|
+
client;
|
|
6
|
+
interactionHandlers;
|
|
7
|
+
constructor(client) {
|
|
8
|
+
this.client = client;
|
|
9
|
+
this.interactionHandlers = new Map([
|
|
10
|
+
[InteractionType.Autocomplete, this.handleAutoCompleteInteraction],
|
|
11
|
+
[InteractionType.Button, this.handleButtonInteraction],
|
|
12
|
+
[InteractionType.ChatInputCommand, this.handleCommandInteraction],
|
|
13
|
+
[InteractionType.ContextMenuCommand, this.handleContextMenuInteraction],
|
|
14
|
+
[InteractionType.ModalSubmit, this.handleModalInteraction],
|
|
15
|
+
[InteractionType.SelectMenu, this.handleSelectMenuInteraction]
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
initializeCommands = async () => {
|
|
19
|
+
const commands = [
|
|
20
|
+
...Array.from(this.client.commands.getAll().values()).map((command) => command.data),
|
|
21
|
+
...Array.from(this.client.contextMenus.getAll().values()).map((contextMenu) => contextMenu.data),
|
|
22
|
+
];
|
|
23
|
+
if (this.client.isReady()) {
|
|
24
|
+
const rest = new REST({ version: DISCORD_API_VERSION }).setToken(this.client.token);
|
|
25
|
+
try {
|
|
26
|
+
await rest.put(Routes.applicationCommands(this.client.user.id), { body: commands });
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
handleInteraction = async (interaction) => {
|
|
34
|
+
if (interaction.inCachedGuild()) {
|
|
35
|
+
const interactionType = this.getInteractionType(interaction);
|
|
36
|
+
if (interactionType === InteractionType.Unknown) {
|
|
37
|
+
throw new Error("Unknown interaction type");
|
|
38
|
+
}
|
|
39
|
+
const handler = this.interactionHandlers.get(interactionType);
|
|
40
|
+
if (handler) {
|
|
41
|
+
await handler(interaction);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
handleAutoCompleteInteraction = async (interaction) => {
|
|
46
|
+
try {
|
|
47
|
+
const interactionAutoComplete = interaction;
|
|
48
|
+
const autoComplete = this.client.autoCompletes.get(interactionAutoComplete.commandName);
|
|
49
|
+
if (!autoComplete)
|
|
50
|
+
return;
|
|
51
|
+
await autoComplete.execute(this.client, interactionAutoComplete);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
handleButtonInteraction = async (interaction) => {
|
|
58
|
+
try {
|
|
59
|
+
const buttonInteraction = interaction;
|
|
60
|
+
const button = this.client.buttons.get(buttonInteraction.customId);
|
|
61
|
+
if (!button)
|
|
62
|
+
return;
|
|
63
|
+
await button.execute(this.client, buttonInteraction);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error(error);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
handleCommandInteraction = async (interaction) => {
|
|
70
|
+
try {
|
|
71
|
+
const interactionCommand = interaction;
|
|
72
|
+
const command = this.client.commands.get(interactionCommand.commandName);
|
|
73
|
+
if (!command)
|
|
74
|
+
return;
|
|
75
|
+
await command.execute(this.client, interactionCommand);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(error);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
handleContextMenuInteraction = async (interaction) => {
|
|
82
|
+
try {
|
|
83
|
+
const interactionContextMenu = interaction;
|
|
84
|
+
if (interactionContextMenu.commandType === ApplicationCommandType.Message) {
|
|
85
|
+
const messageInteraction = interaction;
|
|
86
|
+
await this.handleMessageContextMenuInteraction(messageInteraction);
|
|
87
|
+
}
|
|
88
|
+
else if (interactionContextMenu.commandType === ApplicationCommandType.User) {
|
|
89
|
+
const userInteraction = interaction;
|
|
90
|
+
await this.handleUserContextMenuInteraction(userInteraction);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
console.error(error);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
handleModalInteraction = async (interaction) => {
|
|
98
|
+
try {
|
|
99
|
+
const interactionModal = interaction;
|
|
100
|
+
const modal = this.client.modals.get(interactionModal.customId);
|
|
101
|
+
if (!modal)
|
|
102
|
+
return;
|
|
103
|
+
await modal.execute(this.client, interactionModal);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error(error);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
handleSelectMenuInteraction = async (interaction) => {
|
|
110
|
+
try {
|
|
111
|
+
const interactionSelectMenu = interaction;
|
|
112
|
+
const selectMenu = this.client.modals.get(interactionSelectMenu.customId);
|
|
113
|
+
if (!selectMenu)
|
|
114
|
+
return;
|
|
115
|
+
await selectMenu.execute(this.client, interactionSelectMenu);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error(error);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
handleMessageContextMenuInteraction = async (interaction) => {
|
|
122
|
+
try {
|
|
123
|
+
const messageContextMenu = this.client.contextMenus.get(interaction.commandName);
|
|
124
|
+
if (!messageContextMenu)
|
|
125
|
+
return;
|
|
126
|
+
await messageContextMenu.execute(this.client, interaction);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error(error);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
handleUserContextMenuInteraction = async (interaction) => {
|
|
133
|
+
try {
|
|
134
|
+
const userContextMenu = this.client.contextMenus.get(interaction.commandName);
|
|
135
|
+
if (!userContextMenu)
|
|
136
|
+
return;
|
|
137
|
+
await userContextMenu.execute(this.client, interaction);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error(error);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
getInteractionType(interaction) {
|
|
144
|
+
if (interaction.isAutocomplete()) {
|
|
145
|
+
return InteractionType.Autocomplete;
|
|
146
|
+
}
|
|
147
|
+
if (interaction.isButton()) {
|
|
148
|
+
return InteractionType.Button;
|
|
149
|
+
}
|
|
150
|
+
if (interaction.isChatInputCommand()) {
|
|
151
|
+
return InteractionType.ChatInputCommand;
|
|
152
|
+
}
|
|
153
|
+
if (interaction.isContextMenuCommand()) {
|
|
154
|
+
return InteractionType.ContextMenuCommand;
|
|
155
|
+
}
|
|
156
|
+
if (interaction.isModalSubmit()) {
|
|
157
|
+
return InteractionType.ModalSubmit;
|
|
158
|
+
}
|
|
159
|
+
if (interaction.isAnySelectMenu()) {
|
|
160
|
+
return InteractionType.SelectMenu;
|
|
161
|
+
}
|
|
162
|
+
return InteractionType.Unknown;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DISCORD_API_VERSION = "10";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const DISCORD_API_VERSION = "10";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./apiVersion.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./apiVersion.js";
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type CustomId } from "../typescript/index.js";
|
|
5
|
+
export declare class AutoCompleteManager extends BaseManager {
|
|
6
|
+
private autoCompletes;
|
|
7
|
+
constructor(client: StelliaClient, directory: string);
|
|
8
|
+
loadData(): Promise<void>;
|
|
9
|
+
get<AutoCompleteStructure>(id: CustomId): AutoCompleteStructure | undefined;
|
|
10
|
+
getAll<AutoCompleteStructure>(): Collection<CustomId, AutoCompleteStructure>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class AutoCompleteManager extends BaseManager {
|
|
5
|
+
autoCompletes = new Collection();
|
|
6
|
+
constructor(client, directory) {
|
|
7
|
+
super(client, directory);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const autoCompletes = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.autoCompletes = autoCompletes;
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const autoComplete = this.autoCompletes.get(id) ?? undefined;
|
|
15
|
+
return autoComplete;
|
|
16
|
+
}
|
|
17
|
+
getAll() {
|
|
18
|
+
const autoCompletes = this.autoCompletes;
|
|
19
|
+
return autoCompletes;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { type CustomId } from "../typescript/index.js";
|
|
4
|
+
import { type AnyInteractionStructure } from "../structures/index.js";
|
|
5
|
+
export interface ManagerOptions {
|
|
6
|
+
directoryPath: string;
|
|
7
|
+
}
|
|
8
|
+
export declare abstract class BaseManager {
|
|
9
|
+
readonly client: StelliaClient;
|
|
10
|
+
readonly directoryPath: string;
|
|
11
|
+
constructor(client: StelliaClient, directory: string);
|
|
12
|
+
abstract loadData(): void;
|
|
13
|
+
abstract get<InteractionStructure extends AnyInteractionStructure>(id: CustomId): InteractionStructure | undefined;
|
|
14
|
+
abstract getAll<InteractionStructure extends AnyInteractionStructure>(): Collection<CustomId, InteractionStructure>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type ButtonStructure } from "../structures/index.js";
|
|
5
|
+
import { type CustomId } from "../typescript/index.js";
|
|
6
|
+
export declare class ButtonManager extends BaseManager {
|
|
7
|
+
buttons: Collection<CustomId, ButtonStructure>;
|
|
8
|
+
constructor(client: StelliaClient, directory: string);
|
|
9
|
+
loadData(): Promise<void>;
|
|
10
|
+
get<ButtonStructure>(id: CustomId): ButtonStructure | undefined;
|
|
11
|
+
getAll<ButtonStructure>(): Collection<CustomId, ButtonStructure>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class ButtonManager extends BaseManager {
|
|
5
|
+
buttons = new Collection();
|
|
6
|
+
constructor(client, directory) {
|
|
7
|
+
super(client, directory);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const buttons = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.buttons = buttons;
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const button = this.buttons.get(id) ?? undefined;
|
|
15
|
+
return button;
|
|
16
|
+
}
|
|
17
|
+
getAll() {
|
|
18
|
+
const buttons = this.buttons;
|
|
19
|
+
return buttons;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type CommandStructure } from "../structures/index.js";
|
|
5
|
+
import { type CustomId } from "../typescript/index.js";
|
|
6
|
+
export declare class CommandManager extends BaseManager {
|
|
7
|
+
commands: Collection<CustomId, CommandStructure>;
|
|
8
|
+
constructor(client: StelliaClient, directory: string);
|
|
9
|
+
loadData(): Promise<void>;
|
|
10
|
+
get<CommandStructure>(id: CustomId): CommandStructure | undefined;
|
|
11
|
+
getAll<CommandStructure>(): Collection<CustomId, CommandStructure>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class CommandManager extends BaseManager {
|
|
5
|
+
commands = new Collection();
|
|
6
|
+
constructor(client, directory) {
|
|
7
|
+
super(client, directory);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const commands = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.commands = commands;
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const command = this.commands.get(id) ?? undefined;
|
|
15
|
+
return command;
|
|
16
|
+
}
|
|
17
|
+
getAll() {
|
|
18
|
+
const commands = this.commands;
|
|
19
|
+
return commands;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type ContextMenuStructure } from "../structures/index.js";
|
|
5
|
+
import { type CustomId } from "../typescript/index.js";
|
|
6
|
+
export declare class ContextMenuManager extends BaseManager {
|
|
7
|
+
contextMenus: Collection<CustomId, ContextMenuStructure>;
|
|
8
|
+
constructor(client: StelliaClient, directory: string);
|
|
9
|
+
loadData(): Promise<void>;
|
|
10
|
+
get<ContextMenuStructure>(id: CustomId): ContextMenuStructure | undefined;
|
|
11
|
+
getAll<ContextMenuStructure>(): Collection<CustomId, ContextMenuStructure>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class ContextMenuManager extends BaseManager {
|
|
5
|
+
contextMenus = new Collection();
|
|
6
|
+
constructor(client, directory) {
|
|
7
|
+
super(client, directory);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const contextMenus = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.contextMenus = contextMenus;
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const contextMenu = this.contextMenus.get(id) ?? undefined;
|
|
15
|
+
return contextMenu;
|
|
16
|
+
}
|
|
17
|
+
getAll() {
|
|
18
|
+
const contextMenus = this.contextMenus;
|
|
19
|
+
return contextMenus;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type EventStructure } from "../structures/index.js";
|
|
5
|
+
import { type CustomId } from "../typescript/index.js";
|
|
6
|
+
export declare class EventManager extends BaseManager {
|
|
7
|
+
events: Collection<CustomId, EventStructure>;
|
|
8
|
+
constructor(client: StelliaClient, directoryPath: string);
|
|
9
|
+
loadData(): Promise<void>;
|
|
10
|
+
get<EventStructure>(id: CustomId): EventStructure | undefined;
|
|
11
|
+
getAll<EventStructure>(): Collection<CustomId, EventStructure>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class EventManager extends BaseManager {
|
|
5
|
+
events = new Collection();
|
|
6
|
+
constructor(client, directoryPath) {
|
|
7
|
+
super(client, directoryPath);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const events = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.events = events;
|
|
12
|
+
for (const event of this.events.values()) {
|
|
13
|
+
const { name, once } = event.data;
|
|
14
|
+
if (once) {
|
|
15
|
+
this.client.once(name, (...args) => event.execute(this.client, ...args));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.client.on(name, (...args) => event.execute(this.client, ...args));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
get(id) {
|
|
23
|
+
const event = this.events.get(id) ?? undefined;
|
|
24
|
+
return event;
|
|
25
|
+
}
|
|
26
|
+
getAll() {
|
|
27
|
+
const events = this.events;
|
|
28
|
+
return events;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type ModalStructure } from "../structures/index.js";
|
|
5
|
+
import { type CustomId } from "../typescript/index.js";
|
|
6
|
+
export declare class ModalManager extends BaseManager {
|
|
7
|
+
modals: Collection<CustomId, ModalStructure>;
|
|
8
|
+
constructor(client: StelliaClient, directory: string);
|
|
9
|
+
loadData(): Promise<void>;
|
|
10
|
+
get<ModalStructure>(id: CustomId): ModalStructure | undefined;
|
|
11
|
+
getAll<ModalStructure>(): Collection<CustomId, ModalStructure>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class ModalManager extends BaseManager {
|
|
5
|
+
modals = new Collection();
|
|
6
|
+
constructor(client, directory) {
|
|
7
|
+
super(client, directory);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const modals = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.modals = modals;
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const modal = this.modals.get(id) ?? undefined;
|
|
15
|
+
return modal;
|
|
16
|
+
}
|
|
17
|
+
getAll() {
|
|
18
|
+
const modals = this.modals;
|
|
19
|
+
return modals;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
import { BaseManager } from "./index.js";
|
|
4
|
+
import { type SelectMenuStructure } from "../structures/index.js";
|
|
5
|
+
import { type CustomId } from "../typescript/index.js";
|
|
6
|
+
export declare class SelectMenuManager extends BaseManager {
|
|
7
|
+
selectMenus: Collection<CustomId, SelectMenuStructure>;
|
|
8
|
+
constructor(client: StelliaClient, directory: string);
|
|
9
|
+
loadData(): Promise<void>;
|
|
10
|
+
get<SelectMenuStructure>(id: CustomId): SelectMenuStructure | undefined;
|
|
11
|
+
getAll<SelectMenuStructure>(): Collection<CustomId, SelectMenuStructure>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { BaseManager } from "./index.js";
|
|
3
|
+
import { requiredFiles } from "../utils/index.js";
|
|
4
|
+
export class SelectMenuManager extends BaseManager {
|
|
5
|
+
selectMenus = new Collection();
|
|
6
|
+
constructor(client, directory) {
|
|
7
|
+
super(client, directory);
|
|
8
|
+
}
|
|
9
|
+
async loadData() {
|
|
10
|
+
const selectMenus = await requiredFiles(this.directoryPath);
|
|
11
|
+
this.selectMenus = selectMenus;
|
|
12
|
+
}
|
|
13
|
+
get(id) {
|
|
14
|
+
const selectMenu = this.selectMenus.get(id) ?? undefined;
|
|
15
|
+
return selectMenu;
|
|
16
|
+
}
|
|
17
|
+
getAll() {
|
|
18
|
+
const selectMenus = this.selectMenus;
|
|
19
|
+
return selectMenus;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./BaseManager.js";
|
|
2
|
+
export * from "./AutoCompleteManager.js";
|
|
3
|
+
export * from "./ButtonManager.js";
|
|
4
|
+
export * from "./CommandManager.js";
|
|
5
|
+
export * from "./ContextMenuManager.js";
|
|
6
|
+
export * from "./EventManager.js";
|
|
7
|
+
export * from "./ModalManager.js";
|
|
8
|
+
export * from "./SelectMenuManager.js";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./BaseManager.js";
|
|
2
|
+
export * from "./AutoCompleteManager.js";
|
|
3
|
+
export * from "./ButtonManager.js";
|
|
4
|
+
export * from "./CommandManager.js";
|
|
5
|
+
export * from "./ContextMenuManager.js";
|
|
6
|
+
export * from "./EventManager.js";
|
|
7
|
+
export * from "./ModalManager.js";
|
|
8
|
+
export * from "./SelectMenuManager.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Awaitable, type ClientEvents } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
type EventArguments<Event extends keyof ClientEvents> = ClientEvents[Event];
|
|
4
|
+
export interface EventStructure<Event extends keyof ClientEvents = keyof ClientEvents> {
|
|
5
|
+
data: {
|
|
6
|
+
name: keyof ClientEvents;
|
|
7
|
+
once: boolean;
|
|
8
|
+
};
|
|
9
|
+
execute(client: StelliaClient, ...args: EventArguments<Event>): Awaitable<unknown>;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type AnySelectMenuInteraction, type AutocompleteInteraction, type Awaitable, type ButtonInteraction, type ChatInputCommandInteraction, type ContextMenuCommandBuilder, type MessageContextMenuCommandInteraction, type ModalSubmitInteraction, type SlashCommandBuilder, type UserContextMenuCommandInteraction } from "discord.js";
|
|
2
|
+
import { type StelliaClient } from "../client/index.js";
|
|
3
|
+
export interface AutoCompleteStructure {
|
|
4
|
+
data: DefaultDataStructure;
|
|
5
|
+
execute(client: StelliaClient, interaction: AutocompleteInteraction<"cached">): Awaitable<unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface ButtonStructure {
|
|
8
|
+
data: DefaultDataStructure;
|
|
9
|
+
execute(client: StelliaClient, interaction: ButtonInteraction<"cached">): Awaitable<unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface CommandStructure {
|
|
12
|
+
data: SlashCommandBuilder;
|
|
13
|
+
execute(client: StelliaClient, interaction: ChatInputCommandInteraction<"cached">): Awaitable<unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface ContextMenuStructure {
|
|
16
|
+
data: ContextMenuCommandBuilder;
|
|
17
|
+
execute(client: StelliaClient, interaction: MessageContextMenuCommandInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">): Awaitable<unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface ModalStructure {
|
|
20
|
+
data: DefaultDataStructure;
|
|
21
|
+
execute(client: StelliaClient, interaction: ModalSubmitInteraction<"cached">): Awaitable<unknown>;
|
|
22
|
+
}
|
|
23
|
+
export interface SelectMenuStructure {
|
|
24
|
+
data: DefaultDataStructure;
|
|
25
|
+
execute(client: StelliaClient, interaction: AnySelectMenuInteraction<"cached">): Awaitable<unknown>;
|
|
26
|
+
}
|
|
27
|
+
export type AnyInteractionStructure = AutoCompleteStructure | ButtonStructure | CommandStructure | ContextMenuStructure | ModalStructure | SelectMenuStructure;
|
|
28
|
+
interface DefaultDataStructure {
|
|
29
|
+
name: string;
|
|
30
|
+
once: boolean;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./types.js";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type AnySelectMenuInteraction, type AutocompleteInteraction, type ButtonInteraction, type ChatInputCommandInteraction, type ContextMenuCommandInteraction, type ModalSubmitInteraction, type UserContextMenuCommandInteraction } from "discord.js";
|
|
2
|
+
export type CustomId = string;
|
|
3
|
+
export type AnyInteraction = AutocompleteInteraction<"cached"> | ButtonInteraction<"cached"> | ChatInputCommandInteraction<"cached"> | ContextMenuCommandInteraction<"cached"> | ModalSubmitInteraction<"cached"> | AnySelectMenuInteraction<"cached"> | UserContextMenuCommandInteraction<"cached">;
|
|
4
|
+
export declare enum InteractionType {
|
|
5
|
+
Autocomplete = "Autocomplete",
|
|
6
|
+
Button = "Button",
|
|
7
|
+
ChatInputCommand = "ChatInputCommand",
|
|
8
|
+
ContextMenuCommand = "ContextMenuCommand",
|
|
9
|
+
ModalSubmit = "ModalSubmit",
|
|
10
|
+
SelectMenu = "SelectMenu",
|
|
11
|
+
Unknown = "Unknown"
|
|
12
|
+
}
|
|
13
|
+
export type InteractionData = {
|
|
14
|
+
commandName: string;
|
|
15
|
+
commandOptions?: CommandOptions;
|
|
16
|
+
autoCompletes?: AutoCompletes;
|
|
17
|
+
buttons?: Buttons;
|
|
18
|
+
modals?: Modals;
|
|
19
|
+
selectMenus?: SelectMenus;
|
|
20
|
+
};
|
|
21
|
+
type CommandOptions = {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
};
|
|
24
|
+
type AutoCompletes = {
|
|
25
|
+
[key: string]: string;
|
|
26
|
+
};
|
|
27
|
+
type Buttons = {
|
|
28
|
+
[key: string]: string;
|
|
29
|
+
};
|
|
30
|
+
type Modals = {
|
|
31
|
+
[key: string]: {
|
|
32
|
+
customId: string;
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
type SelectMenus = {
|
|
37
|
+
[key: string]: string;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var InteractionType;
|
|
2
|
+
(function (InteractionType) {
|
|
3
|
+
InteractionType["Autocomplete"] = "Autocomplete";
|
|
4
|
+
InteractionType["Button"] = "Button";
|
|
5
|
+
InteractionType["ChatInputCommand"] = "ChatInputCommand";
|
|
6
|
+
InteractionType["ContextMenuCommand"] = "ContextMenuCommand";
|
|
7
|
+
InteractionType["ModalSubmit"] = "ModalSubmit";
|
|
8
|
+
InteractionType["SelectMenu"] = "SelectMenu";
|
|
9
|
+
InteractionType["Unknown"] = "Unknown";
|
|
10
|
+
})(InteractionType || (InteractionType = {}));
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type BaseMessageOptions, type RepliableInteraction } from "discord.js";
|
|
2
|
+
export declare const ephemeralFollowUpResponse: (interaction: RepliableInteraction, data: string | BaseMessageOptions, automaticDeletion?: boolean) => Promise<void>;
|
|
3
|
+
export declare const ephemeralReplyResponse: (interaction: RepliableInteraction, data: BaseMessageOptions, automaticDeletion?: boolean) => Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const ephemeralFollowUpResponse = async (interaction, data, automaticDeletion = false) => {
|
|
2
|
+
if (!interaction.deferred) {
|
|
3
|
+
await interaction.deferReply({ ephemeral: true });
|
|
4
|
+
}
|
|
5
|
+
if (typeof data === "string") {
|
|
6
|
+
await interaction.followUp({ content: data, ephemeral: true });
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
await interaction.followUp({ ...data, ephemeral: true });
|
|
10
|
+
}
|
|
11
|
+
if (automaticDeletion) {
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
try {
|
|
14
|
+
interaction.deleteReply();
|
|
15
|
+
}
|
|
16
|
+
catch { }
|
|
17
|
+
}, 60 * 1000);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const ephemeralReplyResponse = async (interaction, data, automaticDeletion = false) => {
|
|
21
|
+
if (!interaction.deferred) {
|
|
22
|
+
await interaction.deferReply({ ephemeral: true });
|
|
23
|
+
}
|
|
24
|
+
if (typeof data === "string") {
|
|
25
|
+
await interaction.reply({ content: data, ephemeral: true });
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
await interaction.reply({ ...data, ephemeral: true });
|
|
29
|
+
}
|
|
30
|
+
if (automaticDeletion) {
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
try {
|
|
33
|
+
interaction.deleteReply();
|
|
34
|
+
}
|
|
35
|
+
catch { }
|
|
36
|
+
}, 60 * 1000);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { type AnyInteractionStructure } from "../structures/index.js";
|
|
3
|
+
import { type CustomId } from "../typescript/index.js";
|
|
4
|
+
export declare const requiredFiles: <InteractionStructure extends AnyInteractionStructure>(directoryPath: string) => Promise<Collection<CustomId, InteractionStructure>>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Collection } from "discord.js";
|
|
2
|
+
import { readdirSync, statSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
export const requiredFiles = async (directoryPath) => {
|
|
5
|
+
const collection = new Collection();
|
|
6
|
+
const filesPath = getAllFilesPath(directoryPath).filter((file) => file.endsWith(".ts"));
|
|
7
|
+
for (const filePath of filesPath) {
|
|
8
|
+
const data = await loadInteraction(filePath);
|
|
9
|
+
collection.set(data.data.name, data);
|
|
10
|
+
}
|
|
11
|
+
return collection;
|
|
12
|
+
};
|
|
13
|
+
const loadInteraction = async (filePath) => {
|
|
14
|
+
try {
|
|
15
|
+
const module = await import(`file://${filePath}`);
|
|
16
|
+
const data = module.default;
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const getAllFilesPath = (dirPath, arrayOfFiles = []) => {
|
|
24
|
+
const files = readdirSync(dirPath);
|
|
25
|
+
files.forEach((file) => {
|
|
26
|
+
if (statSync(dirPath + "/" + file).isDirectory()) {
|
|
27
|
+
arrayOfFiles = getAllFilesPath(dirPath + "/" + file, arrayOfFiles);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const __dirname = path.resolve();
|
|
31
|
+
arrayOfFiles.push(path.join(__dirname, dirPath, "/", file));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return arrayOfFiles;
|
|
35
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stelliajs/framework",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc && tsc-alias"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/stelliajs/framework.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "Tweenty_",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"discord-api-types": "^0.37.92",
|
|
17
|
+
"discord.js": "^14.15.3"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"ts-node": "^10.9.2",
|
|
21
|
+
"tsc-alias": "^1.8.10"
|
|
22
|
+
},
|
|
23
|
+
"type": "module"
|
|
24
|
+
}
|