xernerx 3.4.3 → 3.5.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 +10 -10
- package/dist/build/ContextCommandBuilder.js +93 -86
- package/dist/build/EventBuilder.js +34 -35
- package/dist/build/InhibitorBuilder.js +27 -27
- package/dist/build/MessageCommandBuilder.js +90 -78
- package/dist/build/SlashCommandBuilder.js +125 -118
- package/dist/client/XernerxClient.js +101 -83
- package/dist/handlers/CommandHandler.js +42 -42
- package/dist/handlers/EventHandler.js +16 -16
- package/dist/handlers/Handler.js +250 -250
- package/dist/handlers/InhibitorHandler.js +21 -21
- package/dist/main.cjs +2012 -0
- package/dist/main.js +42 -42
- package/dist/models/CommandArguments.js +121 -123
- package/dist/models/Events.js +294 -304
- package/dist/models/Extensions.js +23 -23
- package/dist/tools/XernerxError.js +8 -8
- package/dist/tools/package.js +37 -41
- package/dist/types/enums.js +35 -35
- package/dist/types/interfaces.js +1 -1
- package/dist/types/options.js +1 -1
- package/dist/types/types.js +1 -1
- package/dist/utils/ClientUtil.js +222 -218
- package/dist/utils/CommandUtil.js +248 -260
- package/dist/validators/CommandValidations.js +183 -185
- package/dist/validators/InhibitorValidations.js +42 -42
- package/dist/validators/Shapes.js +1 -0
- package/package.json +54 -39
- package/types/build/ContextCommandBuilder.d.ts +68 -0
- package/{dist → types}/build/EventBuilder.d.ts +21 -17
- package/{dist → types}/build/InhibitorBuilder.d.ts +19 -20
- package/types/build/MessageCommandBuilder.d.ts +59 -0
- package/types/build/SlashCommandBuilder.d.ts +64 -0
- package/{dist → types}/client/XernerxClient.d.ts +28 -28
- package/{dist → types}/handlers/CommandHandler.d.ts +27 -27
- package/{dist → types}/handlers/EventHandler.d.ts +13 -13
- package/{dist → types}/handlers/Handler.d.ts +57 -57
- package/{dist → types}/handlers/InhibitorHandler.d.ts +18 -18
- package/{dist → types}/main.d.ts +44 -30
- package/{dist → types}/models/CommandArguments.d.ts +17 -17
- package/{dist → types}/models/Events.d.ts +24 -24
- package/{dist → types}/models/Extensions.d.ts +7 -7
- package/{dist → types}/tools/XernerxError.d.ts +5 -5
- package/{dist → types}/tools/package.d.ts +38 -38
- package/types/types/enums.d.ts +44 -0
- package/{dist → types}/types/interfaces.d.ts +25 -25
- package/{dist → types}/types/options.d.ts +241 -206
- package/{dist → types}/types/types.d.ts +61 -32
- package/{dist → types}/utils/ClientUtil.d.ts +25 -25
- package/{dist → types}/utils/CommandUtil.d.ts +58 -56
- package/{dist → types}/validators/CommandValidations.d.ts +12 -7
- package/{dist → types}/validators/InhibitorValidations.d.ts +11 -11
- package/types/validators/Shapes.d.ts +1 -0
- package/dist/build/ContextCommandBuilder.d.ts +0 -42
- package/dist/build/MessageCommandBuilder.d.ts +0 -42
- package/dist/build/SlashCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.d.ts +0 -40
- package/dist/build/XContextCommandBuilder.js +0 -84
- package/dist/build/XEventBuilder.d.ts +0 -17
- package/dist/build/XEventBuilder.js +0 -35
- package/dist/build/XInhibitorBuilder.d.ts +0 -20
- package/dist/build/XInhibitorBuilder.js +0 -28
- package/dist/build/XMessageCommandBuilder.d.ts +0 -42
- package/dist/build/XMessageCommandBuilder.js +0 -80
- package/dist/build/XSlashCommandBuilder.d.ts +0 -36
- package/dist/build/XSlashCommandBuilder.js +0 -114
- package/dist/models/CommandValidations.d.ts +0 -4
- package/dist/models/CommandValidations.js +0 -183
- package/dist/models/InhibitorValidations.d.ts +0 -12
- package/dist/models/InhibitorValidations.js +0 -42
- package/dist/types/enums.d.ts +0 -35
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Message, ChannelType } from 'discord.js';
|
|
2
|
-
import { MessageArgOptions, MessageCommandOptions } from '../types/options.js';
|
|
3
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
4
|
-
/**
|
|
5
|
-
* @description - The command builder for message commands.
|
|
6
|
-
* @param {String} id - The unique ID of the command.
|
|
7
|
-
* @param {MessageCommandOptions} options - The command options.
|
|
8
|
-
*/
|
|
9
|
-
export default class XMessageCommandBuilder {
|
|
10
|
-
id: string;
|
|
11
|
-
name: string;
|
|
12
|
-
aliases?: string[];
|
|
13
|
-
description?: string;
|
|
14
|
-
info?: string;
|
|
15
|
-
category?: string;
|
|
16
|
-
prefix?: string | string[];
|
|
17
|
-
regex?: string;
|
|
18
|
-
owner?: boolean;
|
|
19
|
-
channelType?: ChannelType | ChannelType[];
|
|
20
|
-
separator?: string;
|
|
21
|
-
cooldown?: number;
|
|
22
|
-
ignoreOwner?: boolean;
|
|
23
|
-
channels?: string[];
|
|
24
|
-
guilds?: string[];
|
|
25
|
-
userPermissions?: bigint[];
|
|
26
|
-
clientPermissions?: bigint[];
|
|
27
|
-
args?: Array<MessageArgOptions>;
|
|
28
|
-
client: XernerxClient | object;
|
|
29
|
-
constructor(id: string, options: MessageCommandOptions);
|
|
30
|
-
/**
|
|
31
|
-
* @param {Message} message - The Discord message event data.
|
|
32
|
-
* @param {object} args - The arguments you created.
|
|
33
|
-
* @description make any preconditions here.
|
|
34
|
-
*/
|
|
35
|
-
conditions(message: Message, args: MessageArgOptions): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* @param {Message} message - The Discord message event data.
|
|
38
|
-
* @param {object} args - The arguments you created.
|
|
39
|
-
* @description Make your custom command here.
|
|
40
|
-
*/
|
|
41
|
-
exec(message: Message, args: MessageArgOptions): Promise<void>;
|
|
42
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { s } from '@sapphire/shapeshift';
|
|
2
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
-
/**
|
|
4
|
-
* @description - The command builder for message commands.
|
|
5
|
-
* @param {String} id - The unique ID of the command.
|
|
6
|
-
* @param {MessageCommandOptions} options - The command options.
|
|
7
|
-
*/
|
|
8
|
-
export default class XMessageCommandBuilder {
|
|
9
|
-
id;
|
|
10
|
-
name;
|
|
11
|
-
aliases;
|
|
12
|
-
description;
|
|
13
|
-
info;
|
|
14
|
-
category;
|
|
15
|
-
prefix;
|
|
16
|
-
regex;
|
|
17
|
-
owner;
|
|
18
|
-
channelType;
|
|
19
|
-
separator;
|
|
20
|
-
cooldown;
|
|
21
|
-
ignoreOwner;
|
|
22
|
-
channels;
|
|
23
|
-
guilds;
|
|
24
|
-
userPermissions;
|
|
25
|
-
clientPermissions;
|
|
26
|
-
args;
|
|
27
|
-
client;
|
|
28
|
-
constructor(id, options) {
|
|
29
|
-
this.id = id;
|
|
30
|
-
s.object({
|
|
31
|
-
name: s.string,
|
|
32
|
-
aliases: s.union(s.array(s.string).unique, s.string).optional,
|
|
33
|
-
description: s.string.optional,
|
|
34
|
-
info: s.string.optional,
|
|
35
|
-
category: s.string.optional,
|
|
36
|
-
prefix: s.union(s.array(s.string).unique, s.string).optional,
|
|
37
|
-
owner: s.boolean.optional,
|
|
38
|
-
channelType: s.union(s.number, s.array(s.number)).optional,
|
|
39
|
-
separator: s.string.optional,
|
|
40
|
-
cooldown: s.number.optional,
|
|
41
|
-
ignoreOwner: s.boolean.optional,
|
|
42
|
-
channels: s.array(s.string).unique.optional,
|
|
43
|
-
guilds: s.array(s.string).unique.optional,
|
|
44
|
-
userPermissions: s.array(s.bigint).unique.optional,
|
|
45
|
-
clientPermissions: s.array(s.bigint).unique.optional,
|
|
46
|
-
}).parse(options);
|
|
47
|
-
this.name = options.name;
|
|
48
|
-
this.aliases = options.aliases;
|
|
49
|
-
this.description = options.description;
|
|
50
|
-
this.info = options.info;
|
|
51
|
-
this.category = options.category;
|
|
52
|
-
this.prefix = options.prefix ? (Array.isArray(options.prefix) ? options.prefix : [options.prefix]) : [];
|
|
53
|
-
this.regex = options.regex;
|
|
54
|
-
this.owner = options.owner || false;
|
|
55
|
-
this.channelType = options.channelType;
|
|
56
|
-
this.separator = options.separator || ' ';
|
|
57
|
-
this.cooldown = options.cooldown || 0;
|
|
58
|
-
this.ignoreOwner = options.ignoreOwner || false;
|
|
59
|
-
this.channels = options.channels || [];
|
|
60
|
-
this.guilds = options.guilds || [];
|
|
61
|
-
this.userPermissions = options.userPermissions || [];
|
|
62
|
-
this.clientPermissions = options.clientPermissions || [];
|
|
63
|
-
this.args = options.args || [];
|
|
64
|
-
this.client = XernerxClient;
|
|
65
|
-
this.conditions = this.conditions;
|
|
66
|
-
this.exec = this.exec;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @param {Message} message - The Discord message event data.
|
|
70
|
-
* @param {object} args - The arguments you created.
|
|
71
|
-
* @description make any preconditions here.
|
|
72
|
-
*/
|
|
73
|
-
async conditions(message, args) { }
|
|
74
|
-
/**
|
|
75
|
-
* @param {Message} message - The Discord message event data.
|
|
76
|
-
* @param {object} args - The arguments you created.
|
|
77
|
-
* @description Make your custom command here.
|
|
78
|
-
*/
|
|
79
|
-
async exec(message, args) { }
|
|
80
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import Discord, { ChannelType, Interaction } from 'discord.js';
|
|
2
|
-
import { SlashCommandOptions } from '../types/options.js';
|
|
3
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
4
|
-
/**
|
|
5
|
-
* @description - The command builder for slash commands.
|
|
6
|
-
* @param {String} id - The unique ID of the command.
|
|
7
|
-
* @param {SlashCommandOptions} options - The command options.
|
|
8
|
-
*/
|
|
9
|
-
export default class SlashCommandBuilder {
|
|
10
|
-
#private;
|
|
11
|
-
id: string;
|
|
12
|
-
data: Discord.SlashCommandBuilder;
|
|
13
|
-
info?: string;
|
|
14
|
-
category?: string;
|
|
15
|
-
owner?: boolean;
|
|
16
|
-
channelType?: ChannelType | ChannelType[];
|
|
17
|
-
separator?: string;
|
|
18
|
-
cooldown?: number;
|
|
19
|
-
ignoreOwner?: boolean;
|
|
20
|
-
channels?: string[];
|
|
21
|
-
guilds?: string[];
|
|
22
|
-
userPermissions?: bigint[];
|
|
23
|
-
clientPermissions?: bigint[];
|
|
24
|
-
args?: object[];
|
|
25
|
-
subcommands?: object[];
|
|
26
|
-
groups?: object[];
|
|
27
|
-
defer?: {
|
|
28
|
-
reply?: boolean;
|
|
29
|
-
ephemeral?: boolean;
|
|
30
|
-
fetchReply?: boolean;
|
|
31
|
-
};
|
|
32
|
-
client: XernerxClient | object;
|
|
33
|
-
constructor(id: string, options: SlashCommandOptions);
|
|
34
|
-
conditions(interaction: Interaction): Promise<void>;
|
|
35
|
-
exec(interaction: Interaction): Promise<void>;
|
|
36
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import Discord, { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder, } from 'discord.js';
|
|
2
|
-
import { s } from '@sapphire/shapeshift';
|
|
3
|
-
import XernerxError from '../tools/XernerxError.js';
|
|
4
|
-
import XernerxClient from '../client/XernerxClient.js';
|
|
5
|
-
/**
|
|
6
|
-
* @description - The command builder for slash commands.
|
|
7
|
-
* @param {String} id - The unique ID of the command.
|
|
8
|
-
* @param {SlashCommandOptions} options - The command options.
|
|
9
|
-
*/
|
|
10
|
-
export default class SlashCommandBuilder {
|
|
11
|
-
id;
|
|
12
|
-
data;
|
|
13
|
-
info;
|
|
14
|
-
category;
|
|
15
|
-
owner;
|
|
16
|
-
channelType;
|
|
17
|
-
separator;
|
|
18
|
-
cooldown;
|
|
19
|
-
ignoreOwner;
|
|
20
|
-
channels;
|
|
21
|
-
guilds;
|
|
22
|
-
userPermissions;
|
|
23
|
-
clientPermissions;
|
|
24
|
-
args;
|
|
25
|
-
subcommands;
|
|
26
|
-
groups;
|
|
27
|
-
defer;
|
|
28
|
-
client;
|
|
29
|
-
constructor(id, options) {
|
|
30
|
-
this.id = id;
|
|
31
|
-
this.data = new Discord.SlashCommandBuilder().setName(options.name).setDescription(options.description);
|
|
32
|
-
if (options.args && options?.args?.length > 0) {
|
|
33
|
-
this.#addArgs(this.data, options.args);
|
|
34
|
-
}
|
|
35
|
-
if (options.subcommands && options?.subcommands?.length > 0) {
|
|
36
|
-
this.#addSubcommands(this.data, options.subcommands);
|
|
37
|
-
}
|
|
38
|
-
if (options.groups && options?.groups?.length > 0) {
|
|
39
|
-
this.#addSubcommandGroups(options.groups);
|
|
40
|
-
}
|
|
41
|
-
s.object({
|
|
42
|
-
info: s.string.optional,
|
|
43
|
-
category: s.string.optional,
|
|
44
|
-
owner: s.boolean.optional,
|
|
45
|
-
channelType: s.union(s.number, s.array(s.number)).optional,
|
|
46
|
-
separator: s.string.optional,
|
|
47
|
-
cooldown: s.number.optional,
|
|
48
|
-
ignoreOwner: s.boolean.optional,
|
|
49
|
-
channels: s.array(s.string).optional,
|
|
50
|
-
guilds: s.array(s.string).optional,
|
|
51
|
-
userPermissions: s.array(s.bigint).optional,
|
|
52
|
-
clientPermissions: s.array(s.bigint).optional,
|
|
53
|
-
defer: s.object({
|
|
54
|
-
reply: s.boolean.optional,
|
|
55
|
-
ephemeral: s.boolean.optional,
|
|
56
|
-
fetchReply: s.boolean.optional,
|
|
57
|
-
}).optional,
|
|
58
|
-
});
|
|
59
|
-
this.info = options.info;
|
|
60
|
-
this.category = options.category;
|
|
61
|
-
this.owner = options.owner;
|
|
62
|
-
this.channelType = options.channelType;
|
|
63
|
-
this.separator = options.separator;
|
|
64
|
-
this.cooldown = options.cooldown;
|
|
65
|
-
this.ignoreOwner = options.ignoreOwner;
|
|
66
|
-
this.channels = options.channels;
|
|
67
|
-
this.guilds = options.guilds;
|
|
68
|
-
this.userPermissions = options.userPermissions;
|
|
69
|
-
this.clientPermissions = options.clientPermissions;
|
|
70
|
-
this.defer = options.defer;
|
|
71
|
-
this.client = XernerxClient;
|
|
72
|
-
this.conditions = this.conditions;
|
|
73
|
-
this.exec = this.exec;
|
|
74
|
-
}
|
|
75
|
-
async conditions(interaction) { }
|
|
76
|
-
async exec(interaction) { }
|
|
77
|
-
#addArgs(command, args) {
|
|
78
|
-
const types = ['boolean', 'integer', 'number', 'string', 'user', 'role', 'channel', 'mentionable'];
|
|
79
|
-
for (const argument of args) {
|
|
80
|
-
if (!types.includes(argument.type.toLowerCase()))
|
|
81
|
-
throw new XernerxError(`Expected one of ${types.join(', ')}, received ${argument.type} instead.`);
|
|
82
|
-
let slashArgumentType = `${argument.type.slice(0, 1).toUpperCase()}${argument.type
|
|
83
|
-
.slice(1)
|
|
84
|
-
.toLowerCase()}`;
|
|
85
|
-
command[`add${slashArgumentType}Option`]((option) => {
|
|
86
|
-
option
|
|
87
|
-
.setName(argument.name)
|
|
88
|
-
.setDescription(argument.description)
|
|
89
|
-
.setRequired(argument.required || false);
|
|
90
|
-
if (argument.choices)
|
|
91
|
-
option.setChoices(...argument?.choices);
|
|
92
|
-
return option;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
#addSubcommands(method, subcommands) {
|
|
97
|
-
for (const subcommand of subcommands) {
|
|
98
|
-
let sub = new SlashCommandSubcommandBuilder().setName(subcommand.name).setDescription(subcommand.description);
|
|
99
|
-
if (subcommand.args?.length > 0)
|
|
100
|
-
this.#addArgs(sub, subcommand.args);
|
|
101
|
-
method.addSubcommand(sub);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
#addSubcommandGroups(groups) {
|
|
105
|
-
for (const group of groups) {
|
|
106
|
-
let subcommandGroup = new SlashCommandSubcommandGroupBuilder()
|
|
107
|
-
.setName(group.name)
|
|
108
|
-
.setDescription(group.description);
|
|
109
|
-
if (group.subcommands?.length > 0)
|
|
110
|
-
this.#addSubcommands(subcommandGroup, group.subcommands);
|
|
111
|
-
this.data.addSubcommandGroup(subcommandGroup);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Interaction } from 'discord.js';
|
|
2
|
-
import { ContextCommandBuilder, MessageCommandBuilder, SlashCommandBuilder, XernerxClient } from '../main.js';
|
|
3
|
-
import { XernerxMessage } from '../types/types.js';
|
|
4
|
-
export default function commandValidation(action: XernerxMessage | Interaction, command: SlashCommandBuilder | MessageCommandBuilder | ContextCommandBuilder | any, client: XernerxClient, res?: boolean): boolean;
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { Message } from 'discord.js';
|
|
2
|
-
import { CommandType } from '../types/enums.js';
|
|
3
|
-
function getUser(from) {
|
|
4
|
-
if (from instanceof Message)
|
|
5
|
-
return from.author;
|
|
6
|
-
else
|
|
7
|
-
return from.user;
|
|
8
|
-
}
|
|
9
|
-
export default function commandValidation(action, command, client, res = false) {
|
|
10
|
-
let user = getUser(action);
|
|
11
|
-
if ((command.ignoreOwner || client.settings.ignoreOwner) && client.util.isOwner(user.id))
|
|
12
|
-
return res;
|
|
13
|
-
else if (inCooldown(user, client, command, action))
|
|
14
|
-
return true;
|
|
15
|
-
else if (command.owner && !client.util.isOwner(user.id)) {
|
|
16
|
-
res = true;
|
|
17
|
-
emit(client, action, command, 'Not an owner', client.settings.ownerId);
|
|
18
|
-
}
|
|
19
|
-
else if (command.channelType?.length > 0 || command.channelType) {
|
|
20
|
-
if (!Array.isArray(command.channelType))
|
|
21
|
-
command.channelType = [command.channelType];
|
|
22
|
-
if (!command?.channelType?.includes(action.channel?.type)) {
|
|
23
|
-
res = true;
|
|
24
|
-
emit(client, action, command, 'Not the correct channel', command.channelType);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else if (command.channels?.length > 0 && !command.channels.includes(action.channel?.id)) {
|
|
28
|
-
res = true;
|
|
29
|
-
emit(client, action, command, 'Not a whitelisted channel', command.channels);
|
|
30
|
-
}
|
|
31
|
-
else if (command.guilds?.length > 0 && !command.guilds.includes(action.guild?.id)) {
|
|
32
|
-
res = true;
|
|
33
|
-
emit(client, action, command, 'Not a whitelisted guild', command.guilds);
|
|
34
|
-
}
|
|
35
|
-
else if (command.channelType && command.channelType !== action.channel?.type) {
|
|
36
|
-
res = true;
|
|
37
|
-
emit(client, action, command, 'Not the correct type of channel', command.channelType);
|
|
38
|
-
}
|
|
39
|
-
else if (action?.guild && (command.userPermissions || client.settings.userPermissions)) {
|
|
40
|
-
const permissions = command.userPermissions || client?.settings?.userPermissions?.push(...handlerPermissions(client, command.commandType, 'user')), missing = [];
|
|
41
|
-
if (Array.isArray(permissions))
|
|
42
|
-
permissions.map((permission) => {
|
|
43
|
-
if (!(action.member?.permissions).has(permission)) {
|
|
44
|
-
missing.push(permission);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
if (missing.length > 0) {
|
|
48
|
-
res = true;
|
|
49
|
-
emit(client, action, command, 'Missing User Permissions', missing);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else if (action?.guild && (command.clientPermissions || client.settings.clientPermissions)) {
|
|
53
|
-
const permissions = command.clientPermissions || client?.settings?.clientPermissions?.push(...handlerPermissions(client, command.commandType, 'client')), missing = [];
|
|
54
|
-
if (Array.isArray(permissions))
|
|
55
|
-
permissions.map((permission) => {
|
|
56
|
-
if (!(action.member?.permissions).has(permission)) {
|
|
57
|
-
missing.push(permission);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
if (missing.length > 0) {
|
|
61
|
-
res = true;
|
|
62
|
-
emit(client, action, command, 'Missing Client Permissions', missing);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return res;
|
|
66
|
-
}
|
|
67
|
-
function emit(client, action, command, reason, extra) {
|
|
68
|
-
return client.emit('commandBlock', action, command, reason, extra);
|
|
69
|
-
}
|
|
70
|
-
function inCooldown(user, client, command, action) {
|
|
71
|
-
let res = false, downs = {};
|
|
72
|
-
const { cooldowns, messageCommands, slashCommands, contextCommands, commands } = client.cache;
|
|
73
|
-
if (command.commandType === CommandType.MessageCommand && client.handlerOptions.message.cooldown) {
|
|
74
|
-
if (messageCommands.has(user.id)) {
|
|
75
|
-
const usr = messageCommands.get(user.id);
|
|
76
|
-
usr.timeRemaining = usr.endsAt - Date.now();
|
|
77
|
-
downs.message = usr;
|
|
78
|
-
res = true;
|
|
79
|
-
}
|
|
80
|
-
if (!messageCommands.has(user.id)) {
|
|
81
|
-
messageCommands.set(user.id, toCooldown(action, command, client.handlerOptions.message.cooldown, user.id));
|
|
82
|
-
setInterval(() => {
|
|
83
|
-
messageCommands.delete(user.id);
|
|
84
|
-
}, client.handlerOptions.message.cooldown);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (command.commandType === CommandType.SlashCommand && client.handlerOptions.slash.cooldown) {
|
|
88
|
-
if (slashCommands.has(user.id)) {
|
|
89
|
-
const usr = slashCommands.get(user.id);
|
|
90
|
-
usr.timeRemaining = usr.endsAt - Date.now();
|
|
91
|
-
downs.slash = usr;
|
|
92
|
-
res = true;
|
|
93
|
-
}
|
|
94
|
-
if (!slashCommands.has(user.id)) {
|
|
95
|
-
slashCommands.set(user.id, toCooldown(action, command, client.handlerOptions.slash.cooldown, user.id));
|
|
96
|
-
setInterval(() => {
|
|
97
|
-
slashCommands.delete(user.id);
|
|
98
|
-
}, client.handlerOptions.slash.cooldown);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (command.commandType === CommandType.ContextCommand && client.handlerOptions.context.cooldown) {
|
|
102
|
-
if (contextCommands.has(user.id)) {
|
|
103
|
-
const usr = contextCommands.get(user.id);
|
|
104
|
-
usr.timeRemaining = usr.endsAt - Date.now();
|
|
105
|
-
downs.context = usr;
|
|
106
|
-
res = true;
|
|
107
|
-
}
|
|
108
|
-
if (!contextCommands.has(user.id)) {
|
|
109
|
-
contextCommands.set(user.id, toCooldown(action, command, client.handlerOptions.context.cooldown, user.id));
|
|
110
|
-
setInterval(() => {
|
|
111
|
-
contextCommands.delete(user.id);
|
|
112
|
-
}, client.handlerOptions.context.cooldown);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if (client.settings?.cooldown?.default) {
|
|
116
|
-
if (cooldowns.has(user.id)) {
|
|
117
|
-
const usr = cooldowns.get(user.id);
|
|
118
|
-
usr.timeRemaining = usr.endsAt - Date.now();
|
|
119
|
-
downs.default = usr;
|
|
120
|
-
res = true;
|
|
121
|
-
}
|
|
122
|
-
if (!cooldowns.has(user.id)) {
|
|
123
|
-
cooldowns.set(user.id, toCooldown(action, command, client.settings.cooldown.default, user.id));
|
|
124
|
-
setInterval(() => {
|
|
125
|
-
cooldowns.delete(user.id);
|
|
126
|
-
}, client.settings.cooldown.default);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if (command.cooldown) {
|
|
130
|
-
const name = user.id + '-' + (command.data?.name || command?.name) + '-' + command.commandType;
|
|
131
|
-
if (commands.has(name)) {
|
|
132
|
-
const usr = commands.get(name);
|
|
133
|
-
usr.timeRemaining = usr.endsAt - Date.now();
|
|
134
|
-
downs.command = usr;
|
|
135
|
-
res = true;
|
|
136
|
-
}
|
|
137
|
-
if (!commands.has(name)) {
|
|
138
|
-
commands.set(name, toCooldown(action, command, command.cooldown, name));
|
|
139
|
-
setInterval(() => {
|
|
140
|
-
commands.delete(name);
|
|
141
|
-
}, command.cooldown);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (Object.keys(downs).length > 0)
|
|
145
|
-
client.emit('commandCooldown', action, command, downs);
|
|
146
|
-
return res;
|
|
147
|
-
}
|
|
148
|
-
function toCooldown(action, command, cooldown, name) {
|
|
149
|
-
let user = getUser(action);
|
|
150
|
-
return {
|
|
151
|
-
name,
|
|
152
|
-
id: user.id,
|
|
153
|
-
tag: user.tag,
|
|
154
|
-
commandType: command.commandType,
|
|
155
|
-
commandName: command?.data?.name || command?.name,
|
|
156
|
-
guildId: action?.guild?.id,
|
|
157
|
-
channelId: action?.channel?.id,
|
|
158
|
-
startsAt: Number(Date.now()),
|
|
159
|
-
endsAt: Number(Date.now()) + cooldown,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function handlerPermissions(client, commandType, type) {
|
|
163
|
-
let permissions = [];
|
|
164
|
-
if (commandType === CommandType.MessageCommand) {
|
|
165
|
-
if (type === 'user')
|
|
166
|
-
permissions = client.handlerOptions.message?.userPermissions || [];
|
|
167
|
-
else if (type === 'client')
|
|
168
|
-
permissions = client.handlerOptions.message?.clientPermissions || [];
|
|
169
|
-
}
|
|
170
|
-
else if (commandType === CommandType.SlashCommand) {
|
|
171
|
-
if (type === 'user')
|
|
172
|
-
permissions = client.handlerOptions.slash?.userPermissions || [];
|
|
173
|
-
else if (type === 'client')
|
|
174
|
-
permissions = client.handlerOptions.slash?.clientPermissions || [];
|
|
175
|
-
}
|
|
176
|
-
else if (commandType === CommandType.ContextCommand) {
|
|
177
|
-
if (type === 'user')
|
|
178
|
-
permissions = client.handlerOptions.context?.userPermissions || [];
|
|
179
|
-
else if (type === 'client')
|
|
180
|
-
permissions = client.handlerOptions.context?.clientPermissions || [];
|
|
181
|
-
}
|
|
182
|
-
return permissions;
|
|
183
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InhibitorType } from "../types/enums.js";
|
|
2
|
-
import XernerxClient from "../client/XernerxClient.js";
|
|
3
|
-
import { XernerxInteraction, XernerxMessage } from "../types/types.js";
|
|
4
|
-
export declare class InhibitorValidation {
|
|
5
|
-
client: XernerxClient;
|
|
6
|
-
action: XernerxMessage | XernerxInteraction;
|
|
7
|
-
command: string;
|
|
8
|
-
inhibited: Record<string, string | void>;
|
|
9
|
-
constructor(client: XernerxClient, action: XernerxMessage | XernerxInteraction, command: string);
|
|
10
|
-
inhibit(): Promise<Record<string, string | void> | undefined>;
|
|
11
|
-
args(action: XernerxInteraction | XernerxMessage | any, type: InhibitorType): any;
|
|
12
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { InhibitorType } from "../types/enums.js";
|
|
2
|
-
export class InhibitorValidation {
|
|
3
|
-
client;
|
|
4
|
-
action;
|
|
5
|
-
command;
|
|
6
|
-
inhibited;
|
|
7
|
-
constructor(client, action, command) {
|
|
8
|
-
this.client = client;
|
|
9
|
-
this.action = action;
|
|
10
|
-
this.command = command;
|
|
11
|
-
this.inhibited = {};
|
|
12
|
-
}
|
|
13
|
-
async inhibit() {
|
|
14
|
-
for (const inhibitor of this.client.inhibitors) {
|
|
15
|
-
const inhibit = inhibitor[1];
|
|
16
|
-
if (inhibit)
|
|
17
|
-
this.inhibited[inhibit.name] = await inhibit.check(this.action, this.args(this.action, inhibit.type));
|
|
18
|
-
}
|
|
19
|
-
for (const inhibit of Object.values(this.inhibited)) {
|
|
20
|
-
if (inhibit)
|
|
21
|
-
return this.inhibited;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
args(action, type) {
|
|
25
|
-
if (type === InhibitorType.Channel)
|
|
26
|
-
return action.channel;
|
|
27
|
-
if (type === InhibitorType.User)
|
|
28
|
-
return action.author || action.user;
|
|
29
|
-
if (type === InhibitorType.Guild)
|
|
30
|
-
return action.guild;
|
|
31
|
-
if (type === InhibitorType.Member)
|
|
32
|
-
return action.member;
|
|
33
|
-
// if (type === InhibitorType.Command)
|
|
34
|
-
// return this.client.util.getAllCommands().filter(this.command.name);
|
|
35
|
-
// if (type === InhibitorType.MessageCommand)
|
|
36
|
-
// return this.client.util.getAllMessageCommands().find(this.command.name);
|
|
37
|
-
// if (type === InhibitorType.SlashCommand)
|
|
38
|
-
// return this.client.util.getAllSlashCommands().find(this.command.name);
|
|
39
|
-
// if (type === InhibitorType.ContextCommand)
|
|
40
|
-
// return this.client.util.getAllContextCommands().find(this.command.name);
|
|
41
|
-
}
|
|
42
|
-
}
|
package/dist/types/enums.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { SlashCommandStringOption, SlashCommandNumberOption, SlashCommandIntegerOption, SlashCommandBooleanOption, SlashCommandUserOption, SlashCommandChannelOption, SlashCommandRoleOption, SlashCommandMentionableOption } from 'discord.js';
|
|
2
|
-
export declare enum InhibitorType {
|
|
3
|
-
Member = "Member",
|
|
4
|
-
User = "User",
|
|
5
|
-
Guild = "Guild",
|
|
6
|
-
SlashCommand = "SlashCommand",
|
|
7
|
-
MessageCommand = "MessageCommand",
|
|
8
|
-
ContextCommand = "ContextCommand",
|
|
9
|
-
Command = "Command",
|
|
10
|
-
Message = "Message",
|
|
11
|
-
Interaction = "Interaction",
|
|
12
|
-
Channel = "Channel"
|
|
13
|
-
}
|
|
14
|
-
export declare enum CommandType {
|
|
15
|
-
Message = "MessageCommand",
|
|
16
|
-
Slash = "SlashCommand",
|
|
17
|
-
Context = "ContextCommand",
|
|
18
|
-
Event = "Event",
|
|
19
|
-
Inhibitor = "Inhibitor",
|
|
20
|
-
MessageCommand = "MessageCommand",
|
|
21
|
-
SlashCommand = "SlashCommand",
|
|
22
|
-
ContextCommand = "ContextCommand"
|
|
23
|
-
}
|
|
24
|
-
export declare enum ContextCommandType {
|
|
25
|
-
Message = 3,
|
|
26
|
-
User = 2
|
|
27
|
-
}
|
|
28
|
-
export declare enum EventEmitterType {
|
|
29
|
-
Client = "client",
|
|
30
|
-
Rest = "rest",
|
|
31
|
-
Process = "process"
|
|
32
|
-
}
|
|
33
|
-
export type SlashCommandOptionChoices = SlashCommandStringOption | SlashCommandNumberOption | SlashCommandIntegerOption;
|
|
34
|
-
export type SlashCommandOption = SlashCommandOptionChoices | SlashCommandBooleanOption | SlashCommandUserOption | SlashCommandChannelOption | SlashCommandRoleOption | SlashCommandMentionableOption;
|
|
35
|
-
export type SlashArgumentTypes = 'String' | 'Number' | 'Boolean' | 'User' | 'Channel' | 'Role' | 'Mentionable' | 'Integer';
|