xernerx 2.0.0 → 2.0.3
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
CHANGED
|
Binary file
|
package/docs/docs.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# A lightweight class based Discord.js framework.
|
|
4
|
+
|
|
5
|
+
> - [Client](#Client)
|
|
6
|
+
> - [Handlers](#Handlers)
|
|
7
|
+
> > - [Commands](#Commands)
|
|
8
|
+
> > - [Events](#Events)
|
|
9
|
+
> - [Arguments](#Arguments)
|
|
10
|
+
> > - [Types](#Argument#Types)
|
|
11
|
+
|
|
12
|
+
## Client
|
|
13
|
+
|
|
14
|
+
> An extended discord.js client.
|
|
15
|
+
>
|
|
16
|
+
> ```js
|
|
17
|
+
> const { Client } require('xernerx');
|
|
18
|
+
>
|
|
19
|
+
> const client = new Client({intents:[0]});
|
|
20
|
+
> ```
|
|
21
|
+
>
|
|
22
|
+
> | parameter | type | default | required | description |
|
|
23
|
+
> | --------------- | -------- | ------- | -------- | --------------------------------------------------------------- |
|
|
24
|
+
> | intents | Number[] | none | true | Discord#Intents |
|
|
25
|
+
> | partials | [] | none | false | Discord#Partials |
|
|
26
|
+
> | prefix | String[] | none | false | Prefix for message commands |
|
|
27
|
+
> | ownerId | String[] | none | false | Id(s) of the bot developer(s) |
|
|
28
|
+
> | guildId | String | none | true | local guild Id |
|
|
29
|
+
> | global | Boolean | false | true | Whether the interaction commands are local or global |
|
|
30
|
+
> | ignoreOwner | Boolean | false | false | Whether the bot should ignore execute validation or not |
|
|
31
|
+
> | defaultCooldown | Number | 0 | false | The cooldown a user gets before executing another command |
|
|
32
|
+
> | color | Object | FLAGS | false | This appends colors to the bot |
|
|
33
|
+
> | config | Object | {} | false | Here you can save any info to the bot |
|
|
34
|
+
> | logging | Boolean | false | false | Whether the bot should log any events on ready |
|
|
35
|
+
> | cacheTime | Number | 300000 | false | The amount of time before a message gets deleted from the cache |
|
|
36
|
+
> | messages | Object | {} | false | The location where commands get linked with their executions |
|
|
37
|
+
|
|
38
|
+
## Handlers
|
|
39
|
+
|
|
40
|
+
> Below you can see all the different types of handlers. Each command handler needs it's own folder.
|
|
41
|
+
>
|
|
42
|
+
> ### Commands
|
|
43
|
+
>
|
|
44
|
+
> > ```js
|
|
45
|
+
> > const { Client, CommandHandler } = require("xernerx");
|
|
46
|
+
> >
|
|
47
|
+
> > const client = new Client({ intents: [0] });
|
|
48
|
+
> >
|
|
49
|
+
> > const commandHandler = new CommandHandler({ client: client });
|
|
50
|
+
> > ```
|
|
51
|
+
> >
|
|
52
|
+
> > methods
|
|
53
|
+
> >
|
|
54
|
+
> > - [.loadMessageCommands()](<#.loadMessageCommands()>)
|
|
55
|
+
> > - [.loadInteractionCommands()](<#.loadInteractionCommands()>)
|
|
56
|
+
> > - [.loadContextMenuCommands()](<#.loadContextMenuCommands()>)
|
|
57
|
+
> >
|
|
58
|
+
> > #### .loadMessageCommands()
|
|
59
|
+
> >
|
|
60
|
+
> > The message command handler.
|
|
61
|
+
> >
|
|
62
|
+
> > | parameter | type | default | required | description |
|
|
63
|
+
> > | --------- | ------- | ------- | -------- | ---------------------------------------- |
|
|
64
|
+
> > | path | String | none | true | The path of your message command folder. |
|
|
65
|
+
> > | logging | Boolean | false | false | Whether the bot logs commands on start. |
|
|
66
|
+
> >
|
|
67
|
+
> > #### .loadInteractionCommands()
|
|
68
|
+
> >
|
|
69
|
+
> > The interaction command handler.
|
|
70
|
+
> >
|
|
71
|
+
> > | parameter | type | default | required | description |
|
|
72
|
+
> > | --------- | ------- | ------- | -------- | -------------------------------------------- |
|
|
73
|
+
> > | path | String | none | true | The path of your interaction command folder. |
|
|
74
|
+
> > | logging | Boolean | false | false | Whether the bot logs commands on start. |
|
|
75
|
+
> >
|
|
76
|
+
> > #### .loadContextMenuCommands()
|
|
77
|
+
> >
|
|
78
|
+
> > The context menu command handler.
|
|
79
|
+
> >
|
|
80
|
+
> > | parameter | type | default | required | description |
|
|
81
|
+
> > | --------- | ------- | ------- | -------- | --------------------------------------------- |
|
|
82
|
+
> > | path | String | none | true | The path of your context menu command folder. |
|
|
83
|
+
> > | logging | Boolean | false | false | Whether the bot logs commands on start. |
|
|
84
|
+
>
|
|
85
|
+
> ### Events
|
|
86
|
+
>
|
|
87
|
+
> > The event handler is much simpler than the command handler.
|
|
88
|
+
> >
|
|
89
|
+
> > ```js
|
|
90
|
+
> > const { Client, EventHandler } = require("xernerx");
|
|
91
|
+
> >
|
|
92
|
+
> > const client = new Client({ intents: [0] });
|
|
93
|
+
> >
|
|
94
|
+
> > const eventHandler = new EventHandler({ client: client });
|
|
95
|
+
> > ```
|
|
96
|
+
> >
|
|
97
|
+
> > methods
|
|
98
|
+
> >
|
|
99
|
+
> > - [.loadEvents()](<#.loadEvents()>)
|
|
100
|
+
> >
|
|
101
|
+
> > #### .loadEvents()
|
|
102
|
+
> >
|
|
103
|
+
> > The context menu command handler.
|
|
104
|
+
> >
|
|
105
|
+
> > | parameter | type | default | required | description |
|
|
106
|
+
> > | --------- | ------- | ------- | -------- | ------------------------------------- |
|
|
107
|
+
> > | path | String | none | true | The path of your events folder. |
|
|
108
|
+
> > | logging | Boolean | false | false | Whether the bot logs events on start. |
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { s } = require('@sapphire/shapeshift');
|
|
2
|
-
const
|
|
2
|
+
const { SlashCommandSubcommandGroupBuilder, SlashCommandSubcommandBuilder, SlashCommandBuilder } = require('discord.js');
|
|
3
3
|
const { toTitleCase } = require('dumfunctions');
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -26,7 +26,7 @@ class InteractionCommand {
|
|
|
26
26
|
inVoice: s.boolean.optional
|
|
27
27
|
}).parse(options);
|
|
28
28
|
|
|
29
|
-
this.data = new
|
|
29
|
+
this.data = new SlashCommandBuilder()
|
|
30
30
|
.setName(options.name)
|
|
31
31
|
.setDescription(options.description)
|
|
32
32
|
|
|
@@ -75,27 +75,23 @@ class InteractionCommand {
|
|
|
75
75
|
const types = ["boolean", "integer", "number", "string", "user", "role", "channel", "mentionable"];
|
|
76
76
|
|
|
77
77
|
for (const argument of args) {
|
|
78
|
-
|
|
79
78
|
if (!types.includes(argument.type.toLowerCase())) throw new Error(`Expected one of ${types.join(', ')}, received ${argument.type} instead.`);
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
else build[`set${toTitleCase(key, true)}`](value);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
80
|
+
where[`add${toTitleCase(argument.type, true)}Option`](option => {
|
|
81
|
+
option
|
|
82
|
+
.setName(argument.name)
|
|
83
|
+
.setDescription(argument.description)
|
|
84
|
+
.setRequired(argument.required || false)
|
|
85
|
+
if (argument.choices) option.setChoices(...argument?.choices);
|
|
91
86
|
|
|
92
|
-
|
|
87
|
+
return option;
|
|
88
|
+
})
|
|
93
89
|
}
|
|
94
90
|
}
|
|
95
91
|
|
|
96
92
|
addSubcommands(where, subs) {
|
|
97
93
|
for (const sub of subs) {
|
|
98
|
-
let subCommand = new
|
|
94
|
+
let subCommand = new SlashCommandSubcommandBuilder()
|
|
99
95
|
.setName(sub.name)
|
|
100
96
|
.setDescription(sub.description);
|
|
101
97
|
if (sub?.args?.length > 0) {
|
|
@@ -107,7 +103,7 @@ class InteractionCommand {
|
|
|
107
103
|
|
|
108
104
|
addSubcommandGroups(groups) {
|
|
109
105
|
for (const group of groups) {
|
|
110
|
-
let subcommandGroup = new
|
|
106
|
+
let subcommandGroup = new SlashCommandSubcommandGroupBuilder()
|
|
111
107
|
.setName(group.name)
|
|
112
108
|
.setDescription(group.description)
|
|
113
109
|
|
package/models/data/Functions.js
CHANGED
|
@@ -77,7 +77,7 @@ class Functions {
|
|
|
77
77
|
|
|
78
78
|
for (const argument of command.args) {
|
|
79
79
|
|
|
80
|
-
let content = message.content.split(separator).slice(i + 1);
|
|
80
|
+
let content = message.content.replace(new RegExp(`${separator}${separator}+`, "g"), separator).split(separator).slice(i + 1);
|
|
81
81
|
|
|
82
82
|
if (content.join(separator) != '') {
|
|
83
83
|
|
|
@@ -85,6 +85,10 @@ class Functions {
|
|
|
85
85
|
args[argument.name] = content[0];
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
else if (argument.type == 'string') {
|
|
89
|
+
args[argument.name] = content[0];
|
|
90
|
+
}
|
|
91
|
+
|
|
88
92
|
else if (argument.type == 'number') {
|
|
89
93
|
args[argument.name] = parseInt(content[0]);
|
|
90
94
|
}
|
|
@@ -96,13 +100,19 @@ class Functions {
|
|
|
96
100
|
|
|
97
101
|
else if (argument.type == 'user') {
|
|
98
102
|
let user;
|
|
99
|
-
try { user = await message.client.users.fetch(content[0].replace(
|
|
103
|
+
try { user = await message.client.users.fetch(content[0].replace(/<@!?|>/g, "")) } catch (e) { user = e }
|
|
100
104
|
args[argument.name] = user;
|
|
101
105
|
}
|
|
102
106
|
|
|
107
|
+
else if (argument.type == 'role') {
|
|
108
|
+
let role;
|
|
109
|
+
try { role = await message.guild.roles.fetch(content[0].replace(/<@&?|>/g, "")) } catch (e) { role = e }
|
|
110
|
+
args[argument.name] = role;
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
else if (argument.type == 'member') {
|
|
104
114
|
let member;
|
|
105
|
-
try { member = await message.guild.members.fetch(content[0].replace(
|
|
115
|
+
try { member = await message.guild.members.fetch(content[0].replace(/<@!?|>/g, "")) } catch (e) { member = e }
|
|
106
116
|
args[argument.name] = member;
|
|
107
117
|
}
|
|
108
118
|
|
|
@@ -20,16 +20,16 @@ class BuildInInteractionEvent extends Event {
|
|
|
20
20
|
|
|
21
21
|
command.client = interaction.client;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const group = interactionArgs(interaction).group;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const subcommand = interactionArgs(interaction).sub;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const args = interactionArgs(interaction).options;
|
|
28
28
|
|
|
29
29
|
if (access(interaction, command)) return;
|
|
30
30
|
|
|
31
31
|
try {
|
|
32
|
-
await command.exec(interaction, { group: group,
|
|
32
|
+
await command.exec(interaction, { group: group, subcommand: subcommand, args: args });
|
|
33
33
|
|
|
34
34
|
return interaction.client.emit('commandRun', interaction, "interaction", command)
|
|
35
35
|
}
|
|
@@ -35,7 +35,7 @@ class EventHandler {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
if (logging) console.info(logStyle(`Loaded events: ${events.join(', ')}`, 'text', 'purple'));
|
|
38
|
+
if (logging || this.client.logging) console.info(logStyle(`Loaded events: ${events.join(', ')}`, 'text', 'purple'));
|
|
39
39
|
|
|
40
40
|
const builderFiles = fs.readdirSync(`${__dirname}/../events`).filter(file => file.endsWith('.js'))
|
|
41
41
|
|