xernerx 4.17.4 → 4.17.6
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/build/XernerxContextCommand.d.ts +75 -47
- package/dist/build/XernerxContextCommand.js +119 -115
- package/dist/build/XernerxEvent.d.ts +10 -10
- package/dist/build/XernerxEvent.js +17 -17
- package/dist/build/XernerxInhibitor.d.ts +39 -15
- package/dist/build/XernerxInhibitor.js +18 -18
- package/dist/build/XernerxMessageCommand.d.ts +78 -52
- package/dist/build/XernerxMessageCommand.js +118 -114
- package/dist/build/XernerxSlashCommand.d.ts +97 -63
- package/dist/build/XernerxSlashCommand.js +176 -172
- package/dist/client/XernerxClient.d.ts +61 -47
- package/dist/client/XernerxClient.js +92 -88
- package/dist/client/XernerxShardClient.d.ts +14 -14
- package/dist/client/XernerxShardClient.js +61 -47
- package/dist/functions/deploy.js +45 -52
- package/dist/functions/load.js +28 -29
- package/dist/functions/reload.js +23 -24
- package/dist/functions/setPresence.d.ts +1 -1
- package/dist/functions/setPresence.js +17 -16
- package/dist/functions/xernerxUser.js +5 -6
- package/dist/handlers/CommandHandler.d.ts +10 -10
- package/dist/handlers/CommandHandler.js +311 -336
- package/dist/handlers/EventHandler.d.ts +3 -3
- package/dist/handlers/EventHandler.js +48 -21
- package/dist/handlers/ExtensionHandler.d.ts +3 -3
- package/dist/handlers/ExtensionHandler.js +23 -23
- package/dist/handlers/Handler.d.ts +22 -14
- package/dist/handlers/Handler.js +46 -50
- package/dist/handlers/InhibitorHandler.d.ts +3 -3
- package/dist/handlers/InhibitorHandler.js +25 -23
- package/dist/handlers/IntegrationHandler.d.ts +6 -6
- package/dist/handlers/IntegrationHandler.js +20 -20
- package/dist/main.d.ts +28 -21
- package/dist/main.js +28 -21
- package/dist/models/Arguments.d.ts +4 -1
- package/dist/models/Arguments.js +134 -149
- package/dist/models/Cooldowns.d.ts +6 -6
- package/dist/models/Cooldowns.js +25 -29
- package/dist/tools/XernerxError.d.ts +4 -4
- package/dist/tools/XernerxError.js +8 -8
- package/dist/tools/XernerxIntents.d.ts +2 -2
- package/dist/tools/XernerxIntents.js +21 -21
- package/dist/tools/XernerxLog.d.ts +25 -23
- package/dist/tools/XernerxLog.js +139 -110
- package/dist/tools/XernerxText.d.ts +23 -23
- package/dist/tools/XernerxText.js +79 -89
- package/dist/types/extenders.d.ts +55 -47
- package/dist/types/interfaces.d.ts +195 -189
- package/dist/types/types.d.ts +104 -5
- package/dist/utils/ClientUtil.d.ts +12 -9
- package/dist/utils/ClientUtil.js +96 -79
- package/dist/utils/InteractionUtil.d.ts +13 -13
- package/dist/utils/InteractionUtil.js +148 -147
- package/dist/utils/MessageUtil.d.ts +14 -14
- package/dist/utils/MessageUtil.js +162 -161
- package/dist/utils/Util.d.ts +7 -4
- package/dist/utils/Util.js +7 -7
- package/dist/validators/commandValidation.d.ts +4 -1
- package/dist/validators/commandValidation.js +157 -114
- package/dist/validators/inhibitorValidations.d.ts +21 -2
- package/dist/validators/inhibitorValidations.js +39 -39
- package/package.json +6 -3
|
@@ -3,122 +3,165 @@ import { ChannelType } from 'discord.js';
|
|
|
3
3
|
import { Style } from 'dumfunctions';
|
|
4
4
|
var CommandTypes;
|
|
5
5
|
(function (CommandTypes) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
CommandTypes['SlashCommand'] = 'slash';
|
|
7
|
+
CommandTypes['MessageCommand'] = 'message';
|
|
8
|
+
CommandTypes['ContextCommand'] = 'context';
|
|
9
9
|
})(CommandTypes || (CommandTypes = {}));
|
|
10
10
|
export default async function commandValidation(event, command) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
11
|
+
const client = event.client;
|
|
12
|
+
if (command.ignore?.owner && client.settings.ownerId?.includes(event.user.id)) return false;
|
|
13
|
+
const cooldownTime = command.cooldown || client.modules.options?.[CommandTypes[command.filetype]]?.cooldown || client.cooldown?.default || 0;
|
|
14
|
+
const cooldown = {
|
|
15
|
+
id: event.user.id,
|
|
16
|
+
command: command.name,
|
|
17
|
+
createdTimestamp: Number(Date.now()) + cooldownTime,
|
|
18
|
+
};
|
|
19
|
+
const clientPermissions = command.permissions?.client || client.modules.options?.[CommandTypes[command.filetype]]?.permissions?.client || client.settings.permissions?.client || [];
|
|
20
|
+
const userPermissions = command.permissions?.user || client.modules.options?.[CommandTypes[command.filetype]]?.permissions?.user || client.settings.permissions?.user || [];
|
|
21
|
+
if (!client.cooldowns.collections.commands.has(`${event.user.id}-${command.name}`)) {
|
|
22
|
+
client.cooldowns.collections.commands.set(`${event.user.id}-${command.name}`, cooldown);
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
client.cooldowns.collections.commands.delete(`${event.user.id}-${command.name}`);
|
|
25
|
+
}, cooldownTime);
|
|
26
|
+
} else {
|
|
27
|
+
const user = client.cooldowns.collections.commands.get(`${event.user.id}-${command.name}`);
|
|
28
|
+
const time = (user?.createdTimestamp || 0) - Number(Date.now());
|
|
29
|
+
return emit(
|
|
30
|
+
event,
|
|
31
|
+
{
|
|
32
|
+
reason: 'cooldown',
|
|
33
|
+
message: `You are on cooldown for \`${command.name}\`, wait another \`${Math.round(time / 10) / 100}s\``,
|
|
34
|
+
startedAt: user.createdTimestamp,
|
|
35
|
+
endsAt: user.createdTimestamp + time,
|
|
36
|
+
time,
|
|
37
|
+
},
|
|
38
|
+
command
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (command.channel && event.channel?.type !== undefined && event.channel?.type >= 0) {
|
|
42
|
+
if (!command.channel.includes(ChannelType[event.channel?.type]))
|
|
43
|
+
return await emit(
|
|
44
|
+
event,
|
|
45
|
+
{
|
|
46
|
+
reason: 'invalidChannel',
|
|
47
|
+
message: `\`${command.name}\` can only be used in ${command.channel.join(', ')} channels`,
|
|
48
|
+
channels: command.channel,
|
|
49
|
+
},
|
|
50
|
+
command
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
if ((command.ignore?.channels?.length || 0) > 0 && command.ignore?.channels?.includes(event.channel?.id)) return true;
|
|
54
|
+
if ((command.ignore?.guilds?.length || 0) > 0 && command.ignore?.guilds?.includes(event.guild?.id)) return true;
|
|
55
|
+
if ((command.ignore?.users?.length || 0) > 0 && command.ignore?.users?.includes(event.user.id)) return true;
|
|
56
|
+
if (command.ignore?.voice && event.member?.voice?.channel)
|
|
57
|
+
return await emit(
|
|
58
|
+
event,
|
|
59
|
+
{
|
|
60
|
+
reason: 'inVoice',
|
|
61
|
+
message: `\`${command.name}\` cannot be ran while in voice chat`,
|
|
62
|
+
},
|
|
63
|
+
command
|
|
64
|
+
);
|
|
65
|
+
if (command.strict?.owner && !client.settings.ownerId.includes(event.user.id))
|
|
66
|
+
return await emit(
|
|
67
|
+
event,
|
|
68
|
+
{
|
|
69
|
+
reason: 'notADeveloper',
|
|
70
|
+
message: `\`${command.name}\` is a developer command`,
|
|
71
|
+
owners: client.settings.ownerId,
|
|
72
|
+
},
|
|
73
|
+
command
|
|
74
|
+
);
|
|
75
|
+
if ((command.strict?.channels?.length || 0) > 0 && !command.strict?.channels?.includes(event.channel?.id))
|
|
76
|
+
return await emit(
|
|
77
|
+
event,
|
|
78
|
+
{
|
|
79
|
+
reason: 'channelRestricted',
|
|
80
|
+
message: `\`${command.name}\` cannot be ran in this channel`,
|
|
81
|
+
channels: command.strict?.channels,
|
|
82
|
+
},
|
|
83
|
+
command
|
|
84
|
+
);
|
|
85
|
+
if ((command.strict?.guilds?.length || 0) > 0 && !command.strict?.guilds?.includes(event.guild?.id))
|
|
86
|
+
return await emit(
|
|
87
|
+
event,
|
|
88
|
+
{
|
|
89
|
+
reason: 'guildRestricted',
|
|
90
|
+
message: `\`${command.name}\` cannot be ran in this guild`,
|
|
91
|
+
guilds: command.strict?.guilds,
|
|
92
|
+
},
|
|
93
|
+
command
|
|
94
|
+
);
|
|
95
|
+
if ((command.strict?.users?.length || 0) > 0 && !command.strict?.users?.includes(event.user.id))
|
|
96
|
+
return await emit(
|
|
97
|
+
event,
|
|
98
|
+
{
|
|
99
|
+
reason: 'userRestricted',
|
|
100
|
+
message: `\`${command.name}\` cannot be ran by you`,
|
|
101
|
+
users: command.strict?.users,
|
|
102
|
+
},
|
|
103
|
+
command
|
|
104
|
+
);
|
|
105
|
+
if (command.strict?.voice && !event.member?.voice?.channel)
|
|
106
|
+
return await emit(
|
|
107
|
+
event,
|
|
108
|
+
{
|
|
109
|
+
reason: 'voiceRestricted',
|
|
110
|
+
message: `\`${command.name}\` cannot be ran while not in voice chat`,
|
|
111
|
+
},
|
|
112
|
+
command
|
|
113
|
+
);
|
|
114
|
+
if (command.permissions?.dm == false && event.channel?.type === ChannelType.DM)
|
|
115
|
+
return await emit(
|
|
116
|
+
event,
|
|
117
|
+
{
|
|
118
|
+
reason: 'DMRestricted',
|
|
119
|
+
message: `\`${command.name}\` can't be used in a DM Channel`,
|
|
120
|
+
},
|
|
121
|
+
command
|
|
122
|
+
);
|
|
123
|
+
if (userPermissions.length) {
|
|
124
|
+
const missing = [];
|
|
125
|
+
userPermissions.map((permission) => (event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission)));
|
|
126
|
+
if (missing.length)
|
|
127
|
+
return await emit(
|
|
128
|
+
event,
|
|
129
|
+
{
|
|
130
|
+
reason: 'missingUserPermissions',
|
|
131
|
+
message: `You are missing the following permissions to run \`${command.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
|
|
132
|
+
required: userPermissions,
|
|
133
|
+
missing,
|
|
134
|
+
},
|
|
135
|
+
command
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (clientPermissions.length) {
|
|
139
|
+
const missing = [];
|
|
140
|
+
clientPermissions.map((permission) => (event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission)));
|
|
141
|
+
if (missing.length)
|
|
142
|
+
return await emit(
|
|
143
|
+
event,
|
|
144
|
+
{
|
|
145
|
+
reason: 'missingClientPermissions',
|
|
146
|
+
message: `I am missing the following permissions to run \`${command.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
|
|
147
|
+
required: clientPermissions,
|
|
148
|
+
missing,
|
|
149
|
+
},
|
|
150
|
+
command
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if ((!command.global || !client.settings.global) && client.settings.local !== event.guild?.id)
|
|
154
|
+
return await emit(
|
|
155
|
+
event,
|
|
156
|
+
{
|
|
157
|
+
reason: 'local',
|
|
158
|
+
message: `\`${command.name}\` is not globally deployed`,
|
|
159
|
+
},
|
|
160
|
+
command
|
|
161
|
+
);
|
|
162
|
+
return false;
|
|
120
163
|
}
|
|
121
164
|
async function emit(event, info, command) {
|
|
122
|
-
|
|
123
|
-
|
|
165
|
+
event.client.emit('commandBlock', event, info, command);
|
|
166
|
+
return true;
|
|
124
167
|
}
|
|
@@ -5,5 +5,24 @@ import XernerxMessageCommand from '../build/XernerxMessageCommand.js';
|
|
|
5
5
|
import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
|
|
6
6
|
import { XernerxMessage, XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUserContextInteraction } from '../types/extenders.js';
|
|
7
7
|
import { InhibitorType, XernerxInteraction } from '../types/types.js';
|
|
8
|
-
export declare function inhibitorValidation(
|
|
9
|
-
|
|
8
|
+
export declare function inhibitorValidation(
|
|
9
|
+
event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>,
|
|
10
|
+
args?: SlashCommandArguments | MessageCommandArguments | ContextCommandArguments<'user' | 'message'> | null,
|
|
11
|
+
cmd?: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand,
|
|
12
|
+
type?: 'pre' | 'check' | 'post'
|
|
13
|
+
): Promise<boolean>;
|
|
14
|
+
export declare function inhibitorArguments(
|
|
15
|
+
event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>,
|
|
16
|
+
cmd: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand | null,
|
|
17
|
+
type: InhibitorType
|
|
18
|
+
):
|
|
19
|
+
| import('../types/extenders.js').XernerxUser
|
|
20
|
+
| import('discord.js').GuildMember
|
|
21
|
+
| import('discord.js').Guild
|
|
22
|
+
| import('discord.js').TextBasedChannel
|
|
23
|
+
| XernerxSlashCommand
|
|
24
|
+
| XernerxContextCommand
|
|
25
|
+
| XernerxMessageCommand
|
|
26
|
+
| import('discord.js').APIInteractionGuildMember
|
|
27
|
+
| null
|
|
28
|
+
| undefined;
|
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
/** @format */
|
|
2
2
|
export async function inhibitorValidation(event, args, cmd, type) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
const client = event.client;
|
|
4
|
+
const inhibits = [];
|
|
5
|
+
for (const [name, inhibitor] of client.inhibitors) {
|
|
6
|
+
if (type == 'pre')
|
|
7
|
+
if (Boolean(await inhibitor.pre(event, await inhibitorArguments(event, cmd || null, inhibitor.type)))) {
|
|
8
|
+
inhibits.push(name);
|
|
9
|
+
}
|
|
10
|
+
if (type == 'check')
|
|
11
|
+
if (Boolean(await inhibitor.check(event, args || null, await inhibitorArguments(event, cmd || null, inhibitor.type)))) {
|
|
12
|
+
inhibits.push(name);
|
|
13
|
+
}
|
|
14
|
+
if (type == 'post')
|
|
15
|
+
if (Boolean(await inhibitor.post(event, args || null, await inhibitorArguments(event, cmd || null, inhibitor.type)))) {
|
|
16
|
+
inhibits.push(name);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return !!inhibits.length;
|
|
20
20
|
}
|
|
21
21
|
export function inhibitorArguments(event, cmd, type) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
22
|
+
switch (type) {
|
|
23
|
+
case 'channel':
|
|
24
|
+
return event.channel || null;
|
|
25
|
+
case 'command':
|
|
26
|
+
return cmd || null;
|
|
27
|
+
case 'contextCommand':
|
|
28
|
+
return cmd || null;
|
|
29
|
+
case 'guild':
|
|
30
|
+
return event.guild || null;
|
|
31
|
+
case 'interaction':
|
|
32
|
+
return null;
|
|
33
|
+
case 'member':
|
|
34
|
+
return event.member || null;
|
|
35
|
+
case 'message':
|
|
36
|
+
return null;
|
|
37
|
+
case 'messageCommand':
|
|
38
|
+
return cmd || null;
|
|
39
|
+
case 'slashCommand':
|
|
40
|
+
return cmd || null;
|
|
41
|
+
case 'user':
|
|
42
|
+
return event.user || null;
|
|
43
|
+
}
|
|
44
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xernerx",
|
|
3
|
-
"version": "4.17.
|
|
3
|
+
"version": "4.17.6",
|
|
4
4
|
"description": "A bot framework for discord.js.",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"node": ">=16.11.0"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
|
+
"cover": "jest",
|
|
24
25
|
"start": "npm i && npm fund && npm audit fix --force && npm link && tsc -w",
|
|
25
26
|
"commit": "npm run write && git add . && node ./.github/scripts/message.js",
|
|
26
27
|
"tag": "node ./.github/scripts/tag.js",
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
"url": "https://github.com/xernerx/xernerx/issues"
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
46
|
+
"@clack/prompts": "^0.7.0",
|
|
45
47
|
"dbl-sdk": "^2.0.3",
|
|
46
48
|
"discord.js": "^14.14.1",
|
|
47
49
|
"dumfunctions": "^2.1.6",
|
|
@@ -49,8 +51,9 @@
|
|
|
49
51
|
"zod": "^3.22.4"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
54
|
+
"jest": "^29.7.0",
|
|
52
55
|
"prettier": "3.0.0",
|
|
53
|
-
"
|
|
54
|
-
"typescript": "5.
|
|
56
|
+
"ts-node": "^10.9.2",
|
|
57
|
+
"typescript": "^5.5.2"
|
|
55
58
|
}
|
|
56
59
|
}
|