trivious 1.6.18 → 2.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/README.md +53 -66
- package/dist/{core/builders/util.builders.d.ts → features/builders/utility.builders.d.ts} +0 -9
- package/dist/{core/builders/util.builders.js → features/builders/utility.builders.js} +2 -2
- package/dist/features/builders/utility.builders.js.map +1 -0
- package/dist/features/client/client.types.d.ts +85 -0
- package/dist/features/client/client.types.js +3 -0
- package/dist/{shared/typings/client.js.map → features/client/client.types.js.map} +1 -1
- package/dist/features/client/deploy.client.d.ts +7 -0
- package/dist/features/client/deploy.client.js +43 -0
- package/dist/features/client/deploy.client.js.map +1 -0
- package/dist/features/client/trivious.client.d.ts +3 -0
- package/dist/features/client/trivious.client.js +62 -0
- package/dist/features/client/trivious.client.js.map +1 -0
- package/dist/features/commands/commands.types.d.ts +3 -0
- package/dist/features/commands/commands.types.js +3 -0
- package/dist/{shared/typings/commands.js.map → features/commands/commands.types.js.map} +1 -1
- package/dist/features/commands/methods.commands.d.ts +13 -0
- package/dist/features/commands/methods.commands.js +70 -0
- package/dist/features/commands/methods.commands.js.map +1 -0
- package/dist/features/commands/registry.commands.d.ts +7 -0
- package/dist/features/commands/registry.commands.js +84 -0
- package/dist/features/commands/registry.commands.js.map +1 -0
- package/dist/features/components/components.types.d.ts +3 -0
- package/dist/features/components/components.types.js +10 -0
- package/dist/features/components/components.types.js.map +1 -0
- package/dist/features/components/registry.components.d.ts +7 -0
- package/dist/features/components/registry.components.js +23 -0
- package/dist/features/components/registry.components.js.map +1 -0
- package/dist/features/customId/customid.types.d.ts +13 -0
- package/dist/features/customId/customid.types.js +3 -0
- package/dist/features/customId/customid.types.js.map +1 -0
- package/dist/features/customId/methods.customid.d.ts +20 -0
- package/dist/features/customId/methods.customid.js +24 -0
- package/dist/features/customId/methods.customid.js.map +1 -0
- package/dist/features/events/events.types.d.ts +3 -0
- package/dist/features/events/events.types.js +3 -0
- package/dist/{shared/typings/events.js.map → features/events/events.types.js.map} +1 -1
- package/dist/features/events/presets/clientReady.d.ts +11 -0
- package/dist/{core/events → features/events/presets}/clientReady.js +1 -1
- package/dist/features/events/presets/clientReady.js.map +1 -0
- package/dist/features/events/presets/interactionCreate.d.ts +10 -0
- package/dist/features/events/presets/interactionCreate.js +49 -0
- package/dist/features/events/presets/interactionCreate.js.map +1 -0
- package/dist/features/events/registry.events.d.ts +8 -0
- package/dist/features/events/registry.events.js +45 -0
- package/dist/features/events/registry.events.js.map +1 -0
- package/dist/features/modules/modules.types.d.ts +3 -0
- package/dist/features/modules/modules.types.js +3 -0
- package/dist/{shared/typings/module.js.map → features/modules/modules.types.js.map} +1 -1
- package/dist/features/modules/registry.modules.d.ts +8 -0
- package/dist/features/modules/registry.modules.js +30 -0
- package/dist/features/modules/registry.modules.js.map +1 -0
- package/dist/features/structure/index.structure.d.ts +10 -0
- package/dist/features/structure/index.structure.js +51 -0
- package/dist/features/structure/index.structure.js.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +4 -10
- package/dist/modules.types-Bn4HfuVk.d.ts +165 -0
- package/dist/shared/registries.d.ts +26 -0
- package/dist/shared/registries.js +25 -0
- package/dist/shared/registries.js.map +1 -0
- package/dist/shared/typings.d.ts +4 -0
- package/dist/shared/typings.js +9 -0
- package/dist/shared/typings.js.map +1 -0
- package/dist/utility/errors.d.ts +15 -0
- package/dist/utility/errors.js +24 -0
- package/dist/utility/errors.js.map +1 -0
- package/dist/utility/functions.d.ts +4 -0
- package/dist/utility/functions.js +32 -0
- package/dist/utility/functions.js.map +1 -0
- package/package.json +7 -3
- package/dist/core/builders/util.builders.js.map +0 -1
- package/dist/core/client/trivious.client.d.ts +0 -6
- package/dist/core/client/trivious.client.js +0 -115
- package/dist/core/client/trivious.client.js.map +0 -1
- package/dist/core/commands/methods.command.d.ts +0 -6
- package/dist/core/commands/methods.command.js +0 -90
- package/dist/core/commands/methods.command.js.map +0 -1
- package/dist/core/events/clientReady.d.ts +0 -14
- package/dist/core/events/clientReady.js.map +0 -1
- package/dist/core/events/interactionCreate.d.ts +0 -14
- package/dist/core/events/interactionCreate.js +0 -84
- package/dist/core/events/interactionCreate.js.map +0 -1
- package/dist/core/registry/command.registry.d.ts +0 -6
- package/dist/core/registry/command.registry.js +0 -54
- package/dist/core/registry/command.registry.js.map +0 -1
- package/dist/core/registry/component.registry.d.ts +0 -6
- package/dist/core/registry/component.registry.js +0 -41
- package/dist/core/registry/component.registry.js.map +0 -1
- package/dist/core/registry/event.registry.d.ts +0 -6
- package/dist/core/registry/event.registry.js +0 -71
- package/dist/core/registry/event.registry.js.map +0 -1
- package/dist/core/registry/index.d.ts +0 -22
- package/dist/core/registry/index.js +0 -39
- package/dist/core/registry/index.js.map +0 -1
- package/dist/core/registry/module.registry.d.ts +0 -6
- package/dist/core/registry/module.registry.js +0 -55
- package/dist/core/registry/module.registry.js.map +0 -1
- package/dist/index-DbWA_10I.d.ts +0 -439
- package/dist/shared/typings/client.d.ts +0 -74
- package/dist/shared/typings/client.js +0 -3
- package/dist/shared/typings/commands.d.ts +0 -6
- package/dist/shared/typings/commands.js +0 -3
- package/dist/shared/typings/components.d.ts +0 -6
- package/dist/shared/typings/components.js +0 -10
- package/dist/shared/typings/components.js.map +0 -1
- package/dist/shared/typings/events.d.ts +0 -6
- package/dist/shared/typings/events.js +0 -3
- package/dist/shared/typings/index.d.ts +0 -6
- package/dist/shared/typings/index.js +0 -9
- package/dist/shared/typings/index.js.map +0 -1
- package/dist/shared/typings/module.d.ts +0 -6
- package/dist/shared/typings/module.js +0 -3
- package/dist/shared/typings/permissions.d.ts +0 -16
- package/dist/shared/typings/permissions.js +0 -13
- package/dist/shared/typings/permissions.js.map +0 -1
- package/dist/shared/typings/registry.d.ts +0 -51
- package/dist/shared/typings/registry.js +0 -61
- package/dist/shared/typings/registry.js.map +0 -1
- package/dist/shared/utility/components.utility.d.ts +0 -6
- package/dist/shared/utility/components.utility.js +0 -17
- package/dist/shared/utility/components.utility.js.map +0 -1
- package/dist/shared/utility/functions.d.ts +0 -60
- package/dist/shared/utility/functions.js +0 -81
- package/dist/shared/utility/functions.js.map +0 -1
- package/dist/shared/utility/permissions.utility.d.ts +0 -6
- package/dist/shared/utility/permissions.utility.js +0 -12
- package/dist/shared/utility/permissions.utility.js.map +0 -1
package/README.md
CHANGED
|
@@ -20,18 +20,17 @@ pnpm add trivious
|
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
22
|
// src/index.ts
|
|
23
|
-
import { TriviousClient
|
|
23
|
+
import { TriviousClient } from "trivious";
|
|
24
24
|
import { GatewayIntentBits } from "discord.js";
|
|
25
25
|
|
|
26
26
|
const client = new TriviousClient({
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
intents: [GatewayIntentBits.Guilds],
|
|
31
|
-
rolePermissions: {
|
|
32
|
-
// Altneratively can be set via client.rolePermissions
|
|
33
|
-
"123456789012345678": PermissionLevel.GUILD_MODERATOR, // Role ID → PermissionLevel
|
|
27
|
+
credentials: {
|
|
28
|
+
tokenReference: "BOT_TOKEN",
|
|
29
|
+
clientIdReference: "CLIENT_ID",
|
|
34
30
|
},
|
|
31
|
+
corePath: "core", // Folder containing your bot's processes
|
|
32
|
+
intents: [GatewayIntentBits.Guilds],
|
|
33
|
+
ownerUserIds: ["1234"],
|
|
35
34
|
});
|
|
36
35
|
|
|
37
36
|
(async () => {
|
|
@@ -40,9 +39,9 @@ const client = new TriviousClient({
|
|
|
40
39
|
// Registers all commands, events, components, modules;
|
|
41
40
|
// Deploys slash commands globally and then logs into the bot
|
|
42
41
|
|
|
43
|
-
// To separately register commands, events, etc - use client.register()
|
|
44
42
|
// To separately deploy commands - use client.deploy() followed by client.login()
|
|
45
|
-
} catch (
|
|
43
|
+
} catch (err: unknown) {
|
|
44
|
+
const error = err as Error;
|
|
46
45
|
console.error("Failed to start bot:", error);
|
|
47
46
|
}
|
|
48
47
|
})();
|
|
@@ -53,36 +52,53 @@ const client = new TriviousClient({
|
|
|
53
52
|
### Included Default Events
|
|
54
53
|
|
|
55
54
|
Trivious automatically includes and inserts `clientReady` and `interactionCreate` handlers, which can be overwritten.
|
|
56
|
-
It is recommended to use the default interactionCreate handler, which requires zero
|
|
55
|
+
It is recommended to use the default interactionCreate handler, which requires zero setup in your own code.
|
|
57
56
|
|
|
58
|
-
These default events can be found in `src/
|
|
57
|
+
These default events can be found in `src/features/events/presets` in the Trivious repository.
|
|
59
58
|
|
|
60
59
|
---
|
|
61
60
|
|
|
62
61
|
### Creating a Slash Command
|
|
63
62
|
|
|
64
63
|
```ts
|
|
65
|
-
//
|
|
64
|
+
// commands/debug/index.ts
|
|
66
65
|
import { SlashCommandBuilder } from "discord.js";
|
|
67
|
-
import {
|
|
66
|
+
import { SlashCommandData } from "trivious";
|
|
68
67
|
|
|
69
68
|
export default {
|
|
70
69
|
active: true,
|
|
71
70
|
context: "SlashCommand",
|
|
72
|
-
flags: ["
|
|
73
|
-
permission: PermissionLevel.BOT_OWNER,
|
|
71
|
+
flags: ["Cached", "EphemeralReply", "DeferReply"],
|
|
74
72
|
data: new SlashCommandBuilder().setName("debug").setDescription("Debug commands"),
|
|
75
|
-
} satisfies
|
|
73
|
+
} satisfies SlashCommandData;
|
|
76
74
|
```
|
|
77
75
|
|
|
78
|
-
|
|
76
|
+
### Creating a Subcommand Group
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
// commands/debug/config/index.ts
|
|
80
|
+
import { Collection, SlashCommandSubcommandGroupBuilder } from "discord.js";
|
|
81
|
+
import { SlashSubcommandGroupData } from "trivious";
|
|
82
|
+
|
|
83
|
+
export default {
|
|
84
|
+
context: "SlashSubcommandGroup",
|
|
85
|
+
data: new SlashCommandSubcommandGroupBuilder()
|
|
86
|
+
.setName("config")
|
|
87
|
+
.setDescription("Config commands"),
|
|
88
|
+
subcommands: new Collection(),
|
|
89
|
+
} satisfies SlashSubcommandGroupData;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
> Subcommands go in the same directory as the subcommand group file and are auto-detected.
|
|
93
|
+
|
|
94
|
+
---
|
|
79
95
|
|
|
80
96
|
### Creating a Subcommand
|
|
81
97
|
|
|
82
98
|
```ts
|
|
83
|
-
//
|
|
99
|
+
// commands/debug/ping.ts
|
|
84
100
|
import { SlashCommandSubcommandBuilder } from "discord.js";
|
|
85
|
-
import {
|
|
101
|
+
import { interactionReply, SlashSubcommandData } from "trivious";
|
|
86
102
|
|
|
87
103
|
export default {
|
|
88
104
|
active: true,
|
|
@@ -92,61 +108,32 @@ export default {
|
|
|
92
108
|
async execute(client, interaction) {
|
|
93
109
|
const ping = (await interaction.fetchReply()).createdTimestamp - interaction.createdTimestamp;
|
|
94
110
|
|
|
95
|
-
await
|
|
96
|
-
|
|
111
|
+
await interactionReply({
|
|
112
|
+
interaction,
|
|
113
|
+
replyPayload: {
|
|
114
|
+
content: `Pong!\nBot latency: ${ping}ms, API latency: ${client.ws.ping.toString()}ms`,
|
|
115
|
+
},
|
|
116
|
+
flags: ["EphemeralReply"],
|
|
97
117
|
});
|
|
98
118
|
},
|
|
99
|
-
} satisfies
|
|
119
|
+
} satisfies SlashSubcommandData;
|
|
100
120
|
```
|
|
101
121
|
|
|
102
122
|
---
|
|
103
123
|
|
|
104
|
-
###
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
enum PermissionLevel {
|
|
108
|
-
USER = 0,
|
|
109
|
-
GUILD_STAFF = 1,
|
|
110
|
-
GUILD_MODERATOR = 2,
|
|
111
|
-
GUILD_ADMINISTRATOR = 3,
|
|
112
|
-
GUILD_OWNER = 4,
|
|
113
|
-
BOT_OWNER = 5,
|
|
114
|
-
}
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
Set role permissions in client options
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
rolePermissions: {
|
|
121
|
-
"987654321098765432": PermissionLevel.GUILD_ADMINISTRATOR,
|
|
122
|
-
moderatorRole.id: PermissionLevel.GUILD_MODERATOR,
|
|
123
|
-
}
|
|
124
|
-
```
|
|
124
|
+
### Project Structure
|
|
125
125
|
|
|
126
|
-
|
|
126
|
+
Any project structure (e.g. type-based, feature-based) is acceptable as long as everything you expect to be registered is within the core directory.
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
client.setRolePermissions({
|
|
130
|
-
"123456": PermissionLevel.GUILD_STAFF,
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
---
|
|
128
|
+
For example, if all of your commands, components, events and modules are anywhere inside src/features, assuming they export the correct data, they will be detected and registered to the client.
|
|
135
129
|
|
|
136
|
-
|
|
130
|
+
The only required specific structure are for slash commands, as shown below.
|
|
137
131
|
|
|
138
132
|
```
|
|
139
|
-
|
|
140
|
-
├──
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
│ ├── events/
|
|
146
|
-
│ │ └── ready.ts
|
|
147
|
-
│ ├── components/
|
|
148
|
-
│ │ └── ticket-create.ts
|
|
149
|
-
│ └── modules/
|
|
150
|
-
│ └── logging.ts
|
|
151
|
-
└── index.ts
|
|
133
|
+
command/
|
|
134
|
+
├── index.ts
|
|
135
|
+
├── subcommand.ts
|
|
136
|
+
└── subcommand-group/
|
|
137
|
+
├── index.ts
|
|
138
|
+
└──subcommand.ts
|
|
152
139
|
```
|
|
@@ -2,19 +2,10 @@ import { MessageActionRowComponentBuilder, ActionRowBuilder, EmbedData, APIEmbed
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Utility action row builder
|
|
5
|
-
*
|
|
6
|
-
* @export
|
|
7
|
-
* @template {MessageActionRowComponentBuilder} T
|
|
8
|
-
* @param {...T[]} builders
|
|
9
|
-
* @returns {*}
|
|
10
5
|
*/
|
|
11
6
|
declare function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]): ActionRowBuilder<T>;
|
|
12
7
|
/**
|
|
13
8
|
* Utility embed builder
|
|
14
|
-
*
|
|
15
|
-
* @export
|
|
16
|
-
* @param {?(EmbedData | APIEmbed)} [data]
|
|
17
|
-
* @returns {*}
|
|
18
9
|
*/
|
|
19
10
|
declare function createEmbed(data?: EmbedData | APIEmbed): EmbedBuilder;
|
|
20
11
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/builders/utility.builders.ts"],"names":[],"mappings":";;AAWO,SAAS,mBAA+D,QAAA,EAAe;AAC7F,EAAA,OAAO,IAAI,gBAAA,EAAoB,CAAE,aAAA,CAAc,GAAG,QAAQ,CAAA;AAC3D;AAKO,SAAS,YAAY,IAAA,EAA6B;AACxD,EAAA,OAAO,IAAI,aAAa,IAAI,CAAA;AAC7B","file":"utility.builders.js","sourcesContent":["import {\n\tActionRowBuilder,\n\tAPIEmbed,\n\tEmbedBuilder,\n\tEmbedData,\n\tMessageActionRowComponentBuilder,\n} from \"discord.js\";\n\n/**\n * Utility action row builder\n */\nexport function createActionRow<T extends MessageActionRowComponentBuilder>(...builders: T[]) {\n\treturn new ActionRowBuilder<T>().setComponents(...builders);\n}\n\n/**\n * Utility embed builder\n */\nexport function createEmbed(data?: EmbedData | APIEmbed) {\n\treturn new EmbedBuilder(data);\n}\n"]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ClientOptions } from 'discord.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Login credentials for the Discord application
|
|
5
|
+
*
|
|
6
|
+
* @param token Environment variable name for bot token
|
|
7
|
+
* @param clientId Environment variable name for bot client ID
|
|
8
|
+
*/
|
|
9
|
+
interface TriviousClientCredentials {
|
|
10
|
+
tokenRefernece: string;
|
|
11
|
+
clientIdReference: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Base interface for project structure
|
|
15
|
+
*
|
|
16
|
+
* @param useTypeBasedStructure Whether to use type-based structure or not
|
|
17
|
+
*/
|
|
18
|
+
interface TriviousStructure {
|
|
19
|
+
useTypeBasedStructure: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Type-based project structure configuration
|
|
23
|
+
*
|
|
24
|
+
* Everything is inside `src/core`; `src/core/commands`, `src/core/event`...
|
|
25
|
+
*
|
|
26
|
+
* Directory names of course can be different, but the default expected names are used unless configured otherwise by the user
|
|
27
|
+
*
|
|
28
|
+
* @param useTypeBasedStructure Identify as type-based structure
|
|
29
|
+
* @param corePath The path to the **core** directory
|
|
30
|
+
* @param commandsPath The path to the **commands** directory
|
|
31
|
+
* @param componentsPath The path to the **components** directory
|
|
32
|
+
* @param eventsPath The path to the **components** directory
|
|
33
|
+
* @param modulesPath The path to the **module** directory
|
|
34
|
+
*/
|
|
35
|
+
interface TypeBasedStructure extends TriviousStructure {
|
|
36
|
+
useTypeBasedStructure: true;
|
|
37
|
+
corePath: string;
|
|
38
|
+
commandsPath?: string;
|
|
39
|
+
componentPath?: string;
|
|
40
|
+
eventsPath?: string;
|
|
41
|
+
modulesPath?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Feature-based structure configuration
|
|
45
|
+
*
|
|
46
|
+
* Everything is inside `src/features`; `src/features/moderation` and further; `src/features/moderation/commands/ban/index.ts`
|
|
47
|
+
*
|
|
48
|
+
* Feature directories are expected to contain command, component, event, and module directories.
|
|
49
|
+
* Though event and module directories remain optionally supported in the core path.
|
|
50
|
+
*
|
|
51
|
+
* @param useTypeBasedStructure Identify as feature-based structure
|
|
52
|
+
* @param featuresPath The path to the **features** directory
|
|
53
|
+
* @param corePath The path to the **core** directory - Commands and Components are NOT supported in this structure
|
|
54
|
+
*/
|
|
55
|
+
interface FeatureBasedStructure extends TriviousStructure {
|
|
56
|
+
useTypeBasedStructure: false;
|
|
57
|
+
featuresPath: string;
|
|
58
|
+
corePath?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Command hash configuration for automatic command deployment
|
|
62
|
+
*
|
|
63
|
+
* @param enabled Whether this feature is enabled
|
|
64
|
+
* @param persistentDataPath The path to store the command hash, this should be persistent so the feature works as intended
|
|
65
|
+
*/
|
|
66
|
+
interface CommandHashConfiguration {
|
|
67
|
+
enabled: boolean;
|
|
68
|
+
persistentDataPath: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Trivious client options
|
|
72
|
+
*
|
|
73
|
+
* @param credentials Bot login credentials
|
|
74
|
+
* @param structurePaths Chosen project structure and relevant paths
|
|
75
|
+
* @param ownerUserIds Discord user IDs of bot owner(s)
|
|
76
|
+
* @param commandHashConfig Command auto-deployment configuration
|
|
77
|
+
*/
|
|
78
|
+
interface TriviousClientOptions extends ClientOptions {
|
|
79
|
+
credentials: TriviousClientCredentials;
|
|
80
|
+
corePath: string;
|
|
81
|
+
ownerUserIds?: string[];
|
|
82
|
+
commandHashConfig?: CommandHashConfiguration;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type { CommandHashConfiguration, FeatureBasedStructure, TriviousClientCredentials, TriviousClientOptions, TriviousStructure, TypeBasedStructure };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"client.js"}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"client.types.js"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { REST, Routes } from 'discord.js';
|
|
5
|
+
import { TriviousError } from '../../utility/errors.js';
|
|
6
|
+
|
|
7
|
+
async function commandDeploy(client) {
|
|
8
|
+
const { commandHashConfig } = client.trivious;
|
|
9
|
+
const clientId = process.env[client.trivious.credentials.clientIdReference];
|
|
10
|
+
const token = process.env[client.trivious.credentials.tokenRefernece];
|
|
11
|
+
if (!clientId || !token)
|
|
12
|
+
throw new TriviousError("Invalid clientId or token environment variable");
|
|
13
|
+
const commands = client.stores.commands;
|
|
14
|
+
const body = [
|
|
15
|
+
...commands.chatInput.map((command) => command.data.toJSON()),
|
|
16
|
+
...commands.context.map(
|
|
17
|
+
(command) => command.data.toJSON()
|
|
18
|
+
)
|
|
19
|
+
];
|
|
20
|
+
if (commandHashConfig && commandHashConfig.enabled) {
|
|
21
|
+
const hashFile = join(commandHashConfig.persistentDataPath || "data", "commands.hash");
|
|
22
|
+
const newHash = createHash("sha256").update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString()).digest("hex");
|
|
23
|
+
let oldHash = "";
|
|
24
|
+
if (existsSync(hashFile)) oldHash = readFileSync(hashFile, "utf-8");
|
|
25
|
+
if (newHash === oldHash) {
|
|
26
|
+
console.debug(`[Trivious] No changes in commands found, skipping deployment.`);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const hashDirectory = dirname(hashFile);
|
|
30
|
+
if (!existsSync(hashDirectory)) {
|
|
31
|
+
mkdirSync(hashDirectory, { recursive: true });
|
|
32
|
+
}
|
|
33
|
+
writeFileSync(hashFile, newHash, { encoding: "utf-8" });
|
|
34
|
+
console.debug(`[Trivious] Created new command hash: ${hashFile}`);
|
|
35
|
+
}
|
|
36
|
+
const rest = new REST({ version: "10" }).setToken(token);
|
|
37
|
+
await rest.put(Routes.applicationCommands(clientId), { body });
|
|
38
|
+
console.debug(`[Trivious] Deployed ${body.length} commands`);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { commandDeploy as default };
|
|
42
|
+
//# sourceMappingURL=deploy.client.js.map
|
|
43
|
+
//# sourceMappingURL=deploy.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/client/deploy.client.ts"],"names":[],"mappings":";;;;;;AAQA,eAAO,cAAqC,MAAA,EAAwB;AACnE,EAAA,MAAM,EAAE,iBAAA,EAAkB,GAAI,MAAA,CAAO,QAAA;AAErC,EAAA,MAAM,WAAW,OAAA,CAAQ,GAAA,CAAI,MAAA,CAAO,QAAA,CAAS,YAAY,iBAAiB,CAAA;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AAa,CAAA,EAAG;AAC/B,MAAA,SAAA,CAAU,aAAA,EAAe,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AAAA,IAC7C;AAEA,IAAA,aAAA,CAAc,QAAA,EAAU,OAAA,EAAS,EAAE,QAAA,EAAU,SAAS,CAAA;AACtD,IAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,qCAAA,EAAwC,QAAQ,CAAA,CAAE,CAAA;AAAA,EACjE;AAEA,EAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,EAAE,SAAS,IAAA,EAAM,CAAA,CAAE,QAAA,CAAS,KAAK,CAAA;AACvD,EAAA,MAAM,IAAA,CAAK,IAAI,MAAA,CAAO,mBAAA,CAAoB,QAAQ,CAAA,EAAG,EAAE,MAAM,CAAA;AAC7D,EAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,oBAAA,EAAuB,IAAA,CAAK,MAAM,CAAA,SAAA,CAAW,CAAA;AAC5D","file":"deploy.client.js","sourcesContent":["import { createHash } from \"crypto\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { dirname, join } from \"path\";\nimport { REST, Routes } from \"discord.js\";\nimport { TriviousError } from \"src/utility/errors.js\";\nimport { MessageCommandData, UserCommandData } from \"../commands/commands.types.js\";\nimport TriviousClient from \"./trivious.client.js\";\n\nexport default async function commandDeploy(client: TriviousClient) {\n\tconst { commandHashConfig } = client.trivious;\n\n\tconst clientId = process.env[client.trivious.credentials.clientIdReference];\n\tconst token = process.env[client.trivious.credentials.tokenRefernece];\n\tif (!clientId || !token)\n\t\tthrow new TriviousError(\"Invalid clientId or token environment variable\");\n\n\tconst commands = client.stores.commands;\n\tconst body = [\n\t\t...commands.chatInput.map((command) => command.data.toJSON()),\n\t\t...commands.context.map((command) =>\n\t\t\t(command as UserCommandData | MessageCommandData).data.toJSON()\n\t\t),\n\t];\n\n\tif (commandHashConfig && commandHashConfig.enabled) {\n\t\tconst hashFile = join(commandHashConfig.persistentDataPath || \"data\", \"commands.hash\");\n\t\tconst newHash = createHash(\"sha256\")\n\t\t\t.update(JSON.stringify(body.sort((a, b) => a.name.localeCompare(b.name))).toString())\n\t\t\t.digest(\"hex\");\n\n\t\tlet oldHash = \"\";\n\t\tif (existsSync(hashFile)) oldHash = readFileSync(hashFile, \"utf-8\");\n\n\t\tif (newHash === oldHash) {\n\t\t\tconsole.debug(`[Trivious] No changes in commands found, skipping deployment.`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst hashDirectory = dirname(hashFile);\n\t\tif (!existsSync(hashDirectory)) {\n\t\t\tmkdirSync(hashDirectory, { recursive: true });\n\t\t}\n\n\t\twriteFileSync(hashFile, newHash, { encoding: \"utf-8\" });\n\t\tconsole.debug(`[Trivious] Created new command hash: ${hashFile}`);\n\t}\n\n\tconst rest = new REST({ version: \"10\" }).setToken(token);\n\tawait rest.put(Routes.applicationCommands(clientId), { body });\n\tconsole.debug(`[Trivious] Deployed ${body.length} commands`);\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Client, Collection } from 'discord.js';
|
|
2
|
+
import registries from '../../shared/registries.js';
|
|
3
|
+
import structure from '../structure/index.structure.js';
|
|
4
|
+
import { TriviousError } from '../../utility/errors.js';
|
|
5
|
+
import commandDeploy from './deploy.client.js';
|
|
6
|
+
|
|
7
|
+
class TriviousClient extends Client {
|
|
8
|
+
trivious;
|
|
9
|
+
stores;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.trivious = options;
|
|
13
|
+
this.stores = {
|
|
14
|
+
commands: {
|
|
15
|
+
chatInput: new Collection(),
|
|
16
|
+
context: new Collection()
|
|
17
|
+
},
|
|
18
|
+
components: new Collection(),
|
|
19
|
+
events: new Collection(),
|
|
20
|
+
modules: new Collection()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Register, deploy and log into the bot.
|
|
25
|
+
*
|
|
26
|
+
* @throws {TriviousError} If invalid bot token
|
|
27
|
+
*/
|
|
28
|
+
async start() {
|
|
29
|
+
const token = process.env[this.trivious.credentials.tokenRefernece];
|
|
30
|
+
if (!token) {
|
|
31
|
+
throw new TriviousError(
|
|
32
|
+
`Bot token environment variable '${this.trivious.credentials.tokenRefernece}' does not exist!`,
|
|
33
|
+
"Null environment variable"
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
await this.register();
|
|
37
|
+
await this.deploy();
|
|
38
|
+
try {
|
|
39
|
+
await registries.events.bind(this);
|
|
40
|
+
await registries.modules.bind(this);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
const error = new TriviousError(err.message, "Error during events and modules binds");
|
|
43
|
+
console.error(error);
|
|
44
|
+
}
|
|
45
|
+
await this.login(token);
|
|
46
|
+
}
|
|
47
|
+
async register() {
|
|
48
|
+
const dir = structure.resolveRelativePath(this.trivious.corePath);
|
|
49
|
+
await registries.events.register(this, dir);
|
|
50
|
+
await registries.modules.register(this, dir);
|
|
51
|
+
await registries.commands.register(this, dir);
|
|
52
|
+
await registries.components.register(this, dir);
|
|
53
|
+
console.log(this.stores);
|
|
54
|
+
}
|
|
55
|
+
async deploy() {
|
|
56
|
+
await commandDeploy(this);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export { TriviousClient as default };
|
|
61
|
+
//# sourceMappingURL=trivious.client.js.map
|
|
62
|
+
//# sourceMappingURL=trivious.client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/client/trivious.client.ts"],"names":[],"mappings":";;;;;;AAeA,MAAO,uBAAqC,MAAA,CAAO;AAAA,EAClD,QAAA;AAAA,EACS,MAAA;AAAA,EAUT,YAAY,OAAA,EAAgC;AAC3C,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAEhB,IAAA,IAAA,CAAK,MAAA,GAAS;AAAA,MACb,QAAA,EAAU;AAAA,QACT,SAAA,E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A,CAAW,OAAA,CAAQ,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC3C,IAAA,MAAM,UAAA,CAAW,QAAA,CAAS,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAC5C,IAAA,MAAM,UAAA,CAAW,UAAA,CAAW,QAAA,CAAS,IAAA,EAAM,GAAG,CAAA;AAE9C,IAAA,OAAA,CAAQ,GAAA,CAAI,KAAK,MAAM,CAAA;AAAA,EACxB;AAAA,EAEA,MAAM,MAAA,GAAS;AACd,IAAA,MAAM,cAAc,IAAI,CAAA;AAAA,EACzB;AACD","file":"trivious.client.js","sourcesContent":["import { Client, Collection } from \"discord.js\";\nimport registries from \"src/shared/registries.js\";\nimport structure from \"../structure/index.structure.js\";\n\nimport type {\n\tBaseContextCommandData,\n\tComponent,\n\tEvent,\n\tModule,\n\tSlashCommandData,\n\tTriviousClientOptions,\n} from \"#typings\";\nimport { TriviousError } from \"#utility/errors.js\";\nimport commandDeploy from \"./deploy.client.js\";\n\nexport default class TriviousClient extends Client {\n\ttrivious: TriviousClientOptions;\n\treadonly stores: {\n\t\tcommands: {\n\t\t\tchatInput: Collection<string, SlashCommandData>;\n\t\t\tcontext: Collection<string, BaseContextCommandData>;\n\t\t};\n\t\tcomponents: Collection<string, Component>;\n\t\tevents: Collection<string, Event>;\n\t\tmodules: Collection<string, Module>;\n\t};\n\n\tconstructor(options: TriviousClientOptions) {\n\t\tsuper(options);\n\t\tthis.trivious = options;\n\n\t\tthis.stores = {\n\t\t\tcommands: {\n\t\t\t\tchatInput: new Collection(),\n\t\t\t\tcontext: new Collection(),\n\t\t\t},\n\t\t\tcomponents: new Collection(),\n\t\t\tevents: new Collection(),\n\t\t\tmodules: new Collection(),\n\t\t};\n\t}\n\n\t/**\n\t * Register, deploy and log into the bot.\n\t *\n\t * @throws {TriviousError} If invalid bot token\n\t */\n\tasync start() {\n\t\tconst token = process.env[this.trivious.credentials.tokenRefernece];\n\t\tif (!token) {\n\t\t\tthrow new TriviousError(\n\t\t\t\t`Bot token environment variable '${this.trivious.credentials.tokenRefernece}' does not exist!`,\n\t\t\t\t\"Null environment variable\"\n\t\t\t);\n\t\t}\n\n\t\tawait this.register();\n\t\tawait this.deploy();\n\n\t\ttry {\n\t\t\tawait registries.events.bind(this);\n\t\t\tawait registries.modules.bind(this);\n\t\t} catch (err: any) {\n\t\t\tconst error = new TriviousError(err.message, \"Error during events and modules binds\");\n\t\t\tconsole.error(error);\n\t\t}\n\n\t\tawait this.login(token);\n\t}\n\n\tasync register() {\n\t\tconst dir = structure.resolveRelativePath(this.trivious.corePath);\n\n\t\tawait registries.events.register(this, dir);\n\t\tawait registries.modules.register(this, dir);\n\t\tawait registries.commands.register(this, dir);\n\t\tawait registries.components.register(this, dir);\n\n\t\tconsole.log(this.stores);\n\t}\n\n\tasync deploy() {\n\t\tawait commandDeploy(this);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import 'discord.js';
|
|
2
|
+
export { d as BaseChatInputCommandData, B as BaseCommandData, e as BaseContextCommandData, C as ChatInputCommandContext, b as ChatInputCommandFunction, a as CommandFlags, h as ContextCommandData, c as ContextMenuCommandFunction, M as MessageCommandData, S as SlashCommandData, g as SlashSubcommandData, f as SlashSubcommandGroupData, U as UserCommandData } from '../../modules.types-Bn4HfuVk.js';
|
|
3
|
+
import '../client/client.types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"commands.js"}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"commands.types.js"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as discord_js from 'discord.js';
|
|
2
|
+
import { Interaction, CacheType, InteractionReplyOptions, InteractionEditReplyOptions, MessagePayload, ChatInputCommandInteraction } from 'discord.js';
|
|
3
|
+
import { a as CommandFlags, T as TriviousClient, S as SlashCommandData } from '../../modules.types-Bn4HfuVk.js';
|
|
4
|
+
import '../client/client.types.js';
|
|
5
|
+
|
|
6
|
+
declare function interactionReply(options: {
|
|
7
|
+
interaction: Interaction<CacheType>;
|
|
8
|
+
replyPayload: InteractionReplyOptions | InteractionEditReplyOptions | MessagePayload;
|
|
9
|
+
flags?: (CommandFlags | "FollowUp")[];
|
|
10
|
+
}): Promise<discord_js.Message<boolean> | discord_js.InteractionResponse<boolean> | undefined>;
|
|
11
|
+
declare function handleSlashCommand(client: TriviousClient, command: SlashCommandData, interaction: ChatInputCommandInteraction): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { handleSlashCommand, interactionReply };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
async function interactionReply(options) {
|
|
2
|
+
const { interaction, replyPayload, flags } = options;
|
|
3
|
+
if (!("reply" in interaction)) return;
|
|
4
|
+
const payload = replyPayload;
|
|
5
|
+
if (flags?.includes("EphemeralReply")) payload.flags = ["Ephemeral"];
|
|
6
|
+
if (interaction.deferred || interaction.replied) {
|
|
7
|
+
if (flags?.includes("FollowUp")) return await interaction.followUp(payload);
|
|
8
|
+
return await interaction.editReply(payload);
|
|
9
|
+
}
|
|
10
|
+
return await interaction.reply(payload);
|
|
11
|
+
}
|
|
12
|
+
async function handleSlashCommand(client, command, interaction) {
|
|
13
|
+
const { options } = interaction;
|
|
14
|
+
if (command.flags?.includes("Cached") && !interaction.inCachedGuild()) return;
|
|
15
|
+
if (command.flags?.includes("ExpectModal")) return;
|
|
16
|
+
if (command.flags?.includes("DeferReply")) {
|
|
17
|
+
await interactionReply({
|
|
18
|
+
interaction,
|
|
19
|
+
flags: command.flags,
|
|
20
|
+
replyPayload: { content: "Processing command..." }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if ("run" in command && command.run) {
|
|
24
|
+
try {
|
|
25
|
+
await command.run(client, interaction);
|
|
26
|
+
} catch (err) {
|
|
27
|
+
console.error(err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const subcommandGroup = options.getSubcommandGroup(false);
|
|
31
|
+
const subcommand = options.getSubcommand(false);
|
|
32
|
+
if (subcommandGroup && command.subcommandGroups && subcommand) {
|
|
33
|
+
const foundGroup = command.subcommandGroups.get(subcommandGroup);
|
|
34
|
+
if (!foundGroup) {
|
|
35
|
+
await interactionReply({
|
|
36
|
+
interaction,
|
|
37
|
+
flags: ["EphemeralReply"],
|
|
38
|
+
replyPayload: {
|
|
39
|
+
content: "Subcommand group is outdated, inactive, or does not have a handler!"
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const foundSubcommand = foundGroup.subcommands.get(subcommand);
|
|
45
|
+
if (!foundSubcommand) {
|
|
46
|
+
await interactionReply({
|
|
47
|
+
interaction,
|
|
48
|
+
flags: ["EphemeralReply"],
|
|
49
|
+
replyPayload: { content: "Subcommand is outdated, inactive, or does not have a handler!" }
|
|
50
|
+
});
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
return await foundSubcommand.execute(client, interaction);
|
|
54
|
+
} else if (subcommand && command.subcommands) {
|
|
55
|
+
const foundSubcommand = command.subcommands.get(subcommand);
|
|
56
|
+
if (!foundSubcommand) {
|
|
57
|
+
await interactionReply({
|
|
58
|
+
interaction,
|
|
59
|
+
flags: ["EphemeralReply"],
|
|
60
|
+
replyPayload: { content: "Subcommand is outdated, inactive, or does not have a handler!" }
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return await foundSubcommand.execute(client, interaction);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export { handleSlashCommand, interactionReply };
|
|
69
|
+
//# sourceMappingURL=methods.commands.js.map
|
|
70
|
+
//# sourceMappingURL=methods.commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/features/commands/methods.commands.ts"],"names":[],"mappings":"AAUA,eAAsB,iBAAiB,OAAA,EAIpC;AACF,EAAA,MAAM,EAAE,WAAA,EAAa,YAAA,EAAc,KA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,OAAA,EAAS,+DAAA;AAAgE,OACzF,CAAA;AACD,MAAA;AAAA,IACD;AAEA,IAAA,OAAO,MAAM,eAAA,CAAgB,OAAA,CAAQ,MAAA,EAAQ,WAAW,CAAA;AAAA,EACzD;AACD","file":"methods.commands.js","sourcesContent":["import type {\n\tCacheType,\n\tChatInputCommandInteraction,\n\tInteraction,\n\tInteractionEditReplyOptions,\n\tInteractionReplyOptions,\n\tMessagePayload,\n} from \"discord.js\";\nimport type { CommandFlags, SlashCommandData, TriviousClient } from \"#typings\";\n\nexport async function interactionReply(options: {\n\tinteraction: Interaction<CacheType>;\n\treplyPayload: InteractionReplyOptions | InteractionEditReplyOptions | MessagePayload;\n\tflags?: (CommandFlags | \"FollowUp\")[];\n}) {\n\tconst { interaction, replyPayload, flags } = options;\n\tif (!(\"reply\" in interaction)) return;\n\n\tconst payload = replyPayload as InteractionReplyOptions;\n\tif (flags?.includes(\"EphemeralReply\")) payload.flags = [\"Ephemeral\"];\n\n\tif (interaction.deferred || interaction.replied) {\n\t\tif (flags?.includes(\"FollowUp\")) return await interaction.followUp(payload);\n\t\treturn await interaction.editReply(payload as InteractionEditReplyOptions);\n\t}\n\n\treturn await interaction.reply(payload);\n}\n\nexport async function handleSlashCommand(\n\tclient: TriviousClient,\n\tcommand: SlashCommandData,\n\tinteraction: ChatInputCommandInteraction\n) {\n\tconst { options } = interaction;\n\n\tif (command.flags?.includes(\"Cached\") && !interaction.inCachedGuild()) return;\n\tif (command.flags?.includes(\"ExpectModal\")) return;\n\tif (command.flags?.includes(\"DeferReply\")) {\n\t\tawait interactionReply({\n\t\t\tinteraction,\n\t\t\tflags: command.flags,\n\t\t\treplyPayload: { content: \"Processing command...\" },\n\t\t});\n\t}\n\n\tif (\"run\" in command && command.run) {\n\t\ttry {\n\t\t\tawait command.run(client, interaction);\n\t\t} catch (err: any) {\n\t\t\tconsole.error(err);\n\t\t}\n\t}\n\n\tconst subcommandGroup = options.getSubcommandGroup(false);\n\tconst subcommand = options.getSubcommand(false);\n\n\tif (subcommandGroup && command.subcommandGroups && subcommand) {\n\t\tconst foundGroup = command.subcommandGroups.get(subcommandGroup);\n\t\tif (!foundGroup) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: {\n\t\t\t\t\tcontent: \"Subcommand group is outdated, inactive, or does not have a handler!\",\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst foundSubcommand = foundGroup.subcommands.get(subcommand);\n\t\tif (!foundSubcommand) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: { content: \"Subcommand is outdated, inactive, or does not have a handler!\" },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\treturn await foundSubcommand.execute(client, interaction);\n\t} else if (subcommand && command.subcommands) {\n\t\tconst foundSubcommand = command.subcommands.get(subcommand);\n\t\tif (!foundSubcommand) {\n\t\t\tawait interactionReply({\n\t\t\t\tinteraction,\n\t\t\t\tflags: [\"EphemeralReply\"],\n\t\t\t\treplyPayload: { content: \"Subcommand is outdated, inactive, or does not have a handler!\" },\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\treturn await foundSubcommand.execute(client, interaction);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { T as TriviousClient } from '../../modules.types-Bn4HfuVk.js';
|
|
2
|
+
import 'discord.js';
|
|
3
|
+
import '../client/client.types.js';
|
|
4
|
+
|
|
5
|
+
declare function registerCommands(client: TriviousClient, directory: string): Promise<void>;
|
|
6
|
+
|
|
7
|
+
export { registerCommands as default };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { TriviousError } from '../../utility/errors.js';
|
|
2
|
+
import { importFile } from '../../utility/functions.js';
|
|
3
|
+
import { Collection, ApplicationCommandType } from 'discord.js';
|
|
4
|
+
import { existsSync, promises } from 'fs';
|
|
5
|
+
import path, { join } from 'path';
|
|
6
|
+
|
|
7
|
+
function validateCommand(command, expects) {
|
|
8
|
+
if (!("active" in command && "commandType" in command)) return false;
|
|
9
|
+
if (!command.active) return false;
|
|
10
|
+
return expects(command);
|
|
11
|
+
}
|
|
12
|
+
async function parseSlashSubcommands(directory, data) {
|
|
13
|
+
const subcommands = new Collection();
|
|
14
|
+
const files = promises.glob(join(directory, "./*.js"));
|
|
15
|
+
for await (const file of files) {
|
|
16
|
+
const subcommand = await importFile(file);
|
|
17
|
+
if (!subcommand || !validateCommand(subcommand, (subcmd) => subcmd.context === "SlashSubcommand"))
|
|
18
|
+
continue;
|
|
19
|
+
subcommand.parent = data;
|
|
20
|
+
subcommands.set(subcommand.data.name, subcommand);
|
|
21
|
+
}
|
|
22
|
+
if (subcommands.size > 0) data.subcommands = subcommands;
|
|
23
|
+
return subcommands;
|
|
24
|
+
}
|
|
25
|
+
async function parseSlashCommand(file, parentDir, subdirectories) {
|
|
26
|
+
if (!existsSync(file)) return;
|
|
27
|
+
const command = await importFile(file);
|
|
28
|
+
if (!command || !validateCommand(command, (cmd) => cmd.context === "SlashCommand")) return;
|
|
29
|
+
await parseSlashSubcommands(parentDir, command);
|
|
30
|
+
for (const subdir of subdirectories) {
|
|
31
|
+
const indexFile = path.resolve(subdir.parentPath, subdir.name, "index.js");
|
|
32
|
+
if (!existsSync(indexFile)) continue;
|
|
33
|
+
const group = await importFile(indexFile);
|
|
34
|
+
if (!group || !("context" in group) || group.context !== "SlashSubcommandGroup") continue;
|
|
35
|
+
group.parent = command;
|
|
36
|
+
if (!command.subcommandGroups) command.subcommandGroups = new Collection();
|
|
37
|
+
await parseSlashSubcommands(join(subdir.parentPath, subdir.name), group);
|
|
38
|
+
if (group.subcommands.size > 0) command.subcommandGroups.set(group.data.name, group);
|
|
39
|
+
}
|
|
40
|
+
return command;
|
|
41
|
+
}
|
|
42
|
+
async function parseContextCommands(parentDir) {
|
|
43
|
+
const collection = new Collection();
|
|
44
|
+
const files = promises.glob(join(parentDir, "**/*.js"));
|
|
45
|
+
for await (const file of files) {
|
|
46
|
+
const contextCommand = await importFile(file);
|
|
47
|
+
if (!contextCommand || !validateCommand(
|
|
48
|
+
contextCommand,
|
|
49
|
+
(cmd) => cmd.commandType === ApplicationCommandType.Message || cmd.commandType === ApplicationCommandType.User
|
|
50
|
+
))
|
|
51
|
+
continue;
|
|
52
|
+
contextCommand.data.setType(contextCommand.commandType);
|
|
53
|
+
collection.set(contextCommand.data.name, contextCommand);
|
|
54
|
+
}
|
|
55
|
+
return collection;
|
|
56
|
+
}
|
|
57
|
+
async function registerDirectory(client, parentDir) {
|
|
58
|
+
const entries = await promises.readdir(parentDir, { withFileTypes: true });
|
|
59
|
+
const subdirectories = entries.filter((entry) => entry.isDirectory());
|
|
60
|
+
const indexFile = path.resolve(parentDir, "index.js");
|
|
61
|
+
const slashCommand = await parseSlashCommand(indexFile, parentDir, subdirectories);
|
|
62
|
+
if (slashCommand) client.stores.commands.chatInput.set(slashCommand.data.name, slashCommand);
|
|
63
|
+
const contextCommands = await parseContextCommands(parentDir);
|
|
64
|
+
contextCommands.forEach((cmd) => client.stores.commands.context.set(cmd.data.name, cmd));
|
|
65
|
+
}
|
|
66
|
+
async function registerCommands(client, directory) {
|
|
67
|
+
if (!existsSync(directory))
|
|
68
|
+
throw new TriviousError(
|
|
69
|
+
`Could not register commands; passed directory '${directory}' does not exist!`,
|
|
70
|
+
"Nonexistant directory passed"
|
|
71
|
+
);
|
|
72
|
+
const processedDirectories = /* @__PURE__ */ new Set();
|
|
73
|
+
const files = promises.glob(join(directory, "**/*.js"));
|
|
74
|
+
for await (const file of files) {
|
|
75
|
+
const parentDir = path.dirname(file);
|
|
76
|
+
if (processedDirectories.has(parentDir)) continue;
|
|
77
|
+
processedDirectories.add(parentDir);
|
|
78
|
+
await registerDirectory(client, parentDir);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { registerCommands as default };
|
|
83
|
+
//# sourceMappingURL=registry.commands.js.map
|
|
84
|
+
//# sourceMappingURL=registry.commands.js.map
|