xernerx 4.6.2 → 4.7.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/build/XernerxInhibitor.d.ts +2 -0
- package/dist/build/XernerxInhibitor.js +3 -5
- package/dist/client/XernerxClient.d.ts +3 -3
- package/dist/handlers/CommandHandler.js +14 -2
- package/dist/types/types.d.ts +1 -1
- package/dist/validators/inhibitorValidations.d.ts +2 -2
- package/dist/validators/inhibitorValidations.js +18 -9
- package/package.json +1 -1
|
@@ -16,10 +16,12 @@ export default class XernerxInhibitor {
|
|
|
16
16
|
readonly filepath: string;
|
|
17
17
|
readonly client: XernerxClientType;
|
|
18
18
|
constructor(id: string, options: XernerxInhibitorOptions);
|
|
19
|
+
pre(interaction: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, args: any): void;
|
|
19
20
|
/**
|
|
20
21
|
* @description The check rule
|
|
21
22
|
* @param interaction - The interaction with the inhibitor, can be message and interaction
|
|
22
23
|
* @param args - The arguments parsed with this command
|
|
23
24
|
*/
|
|
24
25
|
check<T extends XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>>(interaction: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, args: (T extends XernerxMessage ? MessageCommandArguments : T extends XernerxSlashInteraction ? SlashCommandArguments : T extends XernerxUserContextInteraction ? ContextCommandArguments<'user' | 'message'> : never) | null, command: XernerxSlashCommand | XernerxMessageCommand | XernerxContextCommand): Promise<any>;
|
|
26
|
+
post<T extends XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>>(interaction: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, args: (T extends XernerxMessage ? MessageCommandArguments : T extends XernerxSlashInteraction ? SlashCommandArguments : T extends XernerxUserContextInteraction ? ContextCommandArguments<'user' | 'message'> : never) | null, command: XernerxSlashCommand | XernerxMessageCommand | XernerxContextCommand): Promise<any>;
|
|
25
27
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/** @format */
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { XernerxLog } from '../main.js';
|
|
4
3
|
/**
|
|
5
4
|
* @description - The inhibitor builder for inhibitors.
|
|
6
5
|
* @param {String} id - The unique ID of the inhibitor.
|
|
@@ -17,13 +16,12 @@ export default class XernerxInhibitor {
|
|
|
17
16
|
this.type = options.type;
|
|
18
17
|
this.client = this.client;
|
|
19
18
|
}
|
|
19
|
+
pre(interaction, args) { }
|
|
20
20
|
/**
|
|
21
21
|
* @description The check rule
|
|
22
22
|
* @param interaction - The interaction with the inhibitor, can be message and interaction
|
|
23
23
|
* @param args - The arguments parsed with this command
|
|
24
24
|
*/
|
|
25
|
-
async check(interaction, args, command) {
|
|
26
|
-
|
|
27
|
-
return await this.client.emit('commandError', interaction, `${this.name} doesn't have a check rule.`, this, this.filetype);
|
|
28
|
-
}
|
|
25
|
+
async check(interaction, args, command) { }
|
|
26
|
+
async post(interaction, args, command) { }
|
|
29
27
|
}
|
|
@@ -15,12 +15,12 @@ export default class XernerxClient<T = unknown> extends Client {
|
|
|
15
15
|
} | undefined;
|
|
16
16
|
ignore?: {
|
|
17
17
|
owner: boolean;
|
|
18
|
-
self: boolean;
|
|
19
|
-
bots: boolean;
|
|
20
|
-
system: boolean;
|
|
21
18
|
users: string[];
|
|
22
19
|
channels: string[];
|
|
23
20
|
guilds: string[];
|
|
21
|
+
self: boolean;
|
|
22
|
+
bots: boolean;
|
|
23
|
+
system: boolean;
|
|
24
24
|
} | undefined;
|
|
25
25
|
log?: boolean | {
|
|
26
26
|
ready: boolean;
|
|
@@ -150,6 +150,8 @@ export default class CommandHandler extends Handler {
|
|
|
150
150
|
return;
|
|
151
151
|
message.util = new MessageUtil(this.client, message);
|
|
152
152
|
message.user = await xernerxUser(message, this.client);
|
|
153
|
+
if (await inhibitorValidation(message, undefined, undefined, 'pre'))
|
|
154
|
+
return;
|
|
153
155
|
if (typeof message2 === 'object')
|
|
154
156
|
message = message2;
|
|
155
157
|
if (message2 === 'delete' && this.client.modules.options.message?.handleDeletes) {
|
|
@@ -241,6 +243,8 @@ export default class CommandHandler extends Handler {
|
|
|
241
243
|
const filetype = 'SlashCommand';
|
|
242
244
|
interaction.util = new InteractionUtil(this.client, interaction);
|
|
243
245
|
interaction.user = await xernerxUser(interaction, this.client);
|
|
246
|
+
if (await inhibitorValidation(interaction, undefined, undefined, 'pre'))
|
|
247
|
+
return;
|
|
244
248
|
let cmd = null;
|
|
245
249
|
if (this.client.commands.slash.has(interaction.commandName))
|
|
246
250
|
cmd = this.client.commands.slash.get(interaction.commandName);
|
|
@@ -265,6 +269,8 @@ export default class CommandHandler extends Handler {
|
|
|
265
269
|
const filetype = 'ContextCommand';
|
|
266
270
|
interaction.util = new InteractionUtil(this.client, interaction);
|
|
267
271
|
interaction.user = await xernerxUser(interaction, this.client);
|
|
272
|
+
if (await inhibitorValidation(interaction, undefined, undefined, 'pre'))
|
|
273
|
+
return;
|
|
268
274
|
let cmd;
|
|
269
275
|
if (this.client.commands.context.has(interaction.commandName))
|
|
270
276
|
cmd = this.client.commands.context.get(interaction.commandName);
|
|
@@ -275,18 +281,24 @@ export default class CommandHandler extends Handler {
|
|
|
275
281
|
}
|
|
276
282
|
async exec(cmd, event, args, type) {
|
|
277
283
|
try {
|
|
278
|
-
if (cmd.filetype
|
|
284
|
+
if (cmd.filetype == 'SlashCommand' && (cmd?.defer?.reply ?? this.client.modules.options.slash?.defer?.reply)) {
|
|
279
285
|
await event.deferReply({
|
|
280
286
|
ephemeral: cmd.defer?.ephemeral || this.client.modules.options.slash?.defer?.ephemeral || false,
|
|
281
287
|
});
|
|
282
288
|
}
|
|
289
|
+
if (cmd.filetype == 'ContextCommand' && (cmd?.defer?.reply ?? this.client.modules.options.context?.defer?.reply)) {
|
|
290
|
+
await event.deferReply({
|
|
291
|
+
ephemeral: cmd.defer?.ephemeral || this.client.modules.options.context?.defer?.ephemeral || false,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
283
294
|
if (await commandValidation(event, cmd))
|
|
284
295
|
return;
|
|
285
|
-
if (await inhibitorValidation(event, args, cmd))
|
|
296
|
+
if (await inhibitorValidation(event, args, cmd, 'check'))
|
|
286
297
|
return;
|
|
287
298
|
if (cmd.conditions && (await cmd.conditions(event, args)))
|
|
288
299
|
return;
|
|
289
300
|
await cmd.exec(event, args);
|
|
301
|
+
await inhibitorValidation(event, args, cmd, 'post');
|
|
290
302
|
return await this.client.emit('commandFinish', event, type);
|
|
291
303
|
}
|
|
292
304
|
catch (error) {
|
package/dist/types/types.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ export type DiscordEventType = 'applicationCommandPermissionsUpdate' | 'autoMode
|
|
|
11
11
|
export type XernerxEventType = DiscordEventType | 'webhookCreate' | 'webhookError' | 'commandBlock' | 'commandError' | 'commandStart' | 'commandFinish' | 'commandCooldown';
|
|
12
12
|
export type XernerxInteraction<T extends XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction> = T extends XernerxSlashInteraction ? XernerxSlashInteraction : T extends XernerxUserContextInteraction ? XernerxUserContextInteraction : XernerxMessageContextInteraction;
|
|
13
13
|
export type PermissionNames = 'create instant invite' | 'kick members' | 'ban members' | 'administrator' | 'manage channels' | 'manage guild' | 'add reactions' | 'view audit log' | 'priority speaker' | 'stream' | 'view channel' | 'send messages' | 'send tts messages' | 'manage messages' | 'embed links' | 'attach files' | 'read message history' | 'mention everyone' | 'use external emojis' | 'view guild insights' | 'connect' | 'speak' | 'mute members' | 'deafen members' | 'move members' | 'use vad' | 'change nickname' | 'manage nicknames' | 'manage roles' | 'manage webhooks' | 'manage emojis and stickers' | 'use application commands' | 'request to speak' | 'manage events' | 'manage threads' | 'create public threads' | 'create private threads' | 'use external stickers' | 'send messages in threads' | 'start embedded activities' | 'moderate members';
|
|
14
|
-
export type InhibitorType = 'message' | 'interaction' | 'command' | 'channel' | 'user' | 'member' | 'guild' | 'contextCommand' | 'messageCommand' | 'slashCommand';
|
|
14
|
+
export type InhibitorType = '*' | 'message' | 'interaction' | 'command' | 'channel' | 'user' | 'member' | 'guild' | 'contextCommand' | 'messageCommand' | 'slashCommand';
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
import { ContextCommandArguments, MessageCommandArguments, SlashCommandArguments, XernerxContextCommand, XernerxMessageCommand, XernerxSlashCommand } from '../main.js';
|
|
3
3
|
import { XernerxMessage, XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUserContextInteraction } from '../types/extenders.js';
|
|
4
4
|
import { InhibitorType, XernerxInteraction } from '../types/types.js';
|
|
5
|
-
export declare function inhibitorValidation(event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, args
|
|
6
|
-
export declare function inhibitorArguments(event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, cmd: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand | null, type: InhibitorType): import("../main.js").XernerxUser | import("discord.js").GuildMember | import("discord.js").Guild | import("discord.js").TextBasedChannel | XernerxMessageCommand | XernerxSlashCommand | XernerxContextCommand | import("../main.js").APIInteractionGuildMember | null;
|
|
5
|
+
export declare function inhibitorValidation(event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, args?: SlashCommandArguments | MessageCommandArguments | ContextCommandArguments<'user' | 'message'> | null, cmd?: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand, type?: 'pre' | 'check' | 'post'): Promise<boolean>;
|
|
6
|
+
export declare function inhibitorArguments(event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, cmd: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand | null, type: InhibitorType): import("../main.js").XernerxUser | import("discord.js").GuildMember | import("discord.js").Guild | import("discord.js").TextBasedChannel | XernerxMessageCommand | XernerxSlashCommand | XernerxContextCommand | import("../main.js").APIInteractionGuildMember | null | undefined;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
/** @format */
|
|
2
|
-
export async function inhibitorValidation(event, args, cmd) {
|
|
2
|
+
export async function inhibitorValidation(event, args, cmd, type) {
|
|
3
3
|
const client = event.client;
|
|
4
4
|
const inhibits = [];
|
|
5
5
|
for (const [name, inhibitor] of client.inhibitors) {
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
}
|
|
9
18
|
}
|
|
10
19
|
return !!inhibits.length;
|
|
11
20
|
}
|
|
@@ -14,9 +23,9 @@ export function inhibitorArguments(event, cmd, type) {
|
|
|
14
23
|
case 'channel':
|
|
15
24
|
return event.channel || null;
|
|
16
25
|
case 'command':
|
|
17
|
-
return cmd;
|
|
26
|
+
return cmd || null;
|
|
18
27
|
case 'contextCommand':
|
|
19
|
-
return cmd;
|
|
28
|
+
return cmd || null;
|
|
20
29
|
case 'guild':
|
|
21
30
|
return event.guild || null;
|
|
22
31
|
case 'interaction':
|
|
@@ -26,10 +35,10 @@ export function inhibitorArguments(event, cmd, type) {
|
|
|
26
35
|
case 'message':
|
|
27
36
|
return null;
|
|
28
37
|
case 'messageCommand':
|
|
29
|
-
return cmd;
|
|
38
|
+
return cmd || null;
|
|
30
39
|
case 'slashCommand':
|
|
31
|
-
return cmd;
|
|
40
|
+
return cmd || null;
|
|
32
41
|
case 'user':
|
|
33
|
-
return event.user;
|
|
42
|
+
return event.user || null;
|
|
34
43
|
}
|
|
35
44
|
}
|