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.
Files changed (62) hide show
  1. package/dist/build/XernerxContextCommand.d.ts +75 -47
  2. package/dist/build/XernerxContextCommand.js +119 -115
  3. package/dist/build/XernerxEvent.d.ts +10 -10
  4. package/dist/build/XernerxEvent.js +17 -17
  5. package/dist/build/XernerxInhibitor.d.ts +39 -15
  6. package/dist/build/XernerxInhibitor.js +18 -18
  7. package/dist/build/XernerxMessageCommand.d.ts +78 -52
  8. package/dist/build/XernerxMessageCommand.js +118 -114
  9. package/dist/build/XernerxSlashCommand.d.ts +97 -63
  10. package/dist/build/XernerxSlashCommand.js +176 -172
  11. package/dist/client/XernerxClient.d.ts +61 -47
  12. package/dist/client/XernerxClient.js +92 -88
  13. package/dist/client/XernerxShardClient.d.ts +14 -14
  14. package/dist/client/XernerxShardClient.js +61 -47
  15. package/dist/functions/deploy.js +45 -52
  16. package/dist/functions/load.js +28 -29
  17. package/dist/functions/reload.js +23 -24
  18. package/dist/functions/setPresence.d.ts +1 -1
  19. package/dist/functions/setPresence.js +17 -16
  20. package/dist/functions/xernerxUser.js +5 -6
  21. package/dist/handlers/CommandHandler.d.ts +10 -10
  22. package/dist/handlers/CommandHandler.js +311 -336
  23. package/dist/handlers/EventHandler.d.ts +3 -3
  24. package/dist/handlers/EventHandler.js +48 -21
  25. package/dist/handlers/ExtensionHandler.d.ts +3 -3
  26. package/dist/handlers/ExtensionHandler.js +23 -23
  27. package/dist/handlers/Handler.d.ts +22 -14
  28. package/dist/handlers/Handler.js +46 -50
  29. package/dist/handlers/InhibitorHandler.d.ts +3 -3
  30. package/dist/handlers/InhibitorHandler.js +25 -23
  31. package/dist/handlers/IntegrationHandler.d.ts +6 -6
  32. package/dist/handlers/IntegrationHandler.js +20 -20
  33. package/dist/main.d.ts +28 -21
  34. package/dist/main.js +28 -21
  35. package/dist/models/Arguments.d.ts +4 -1
  36. package/dist/models/Arguments.js +134 -149
  37. package/dist/models/Cooldowns.d.ts +6 -6
  38. package/dist/models/Cooldowns.js +25 -29
  39. package/dist/tools/XernerxError.d.ts +4 -4
  40. package/dist/tools/XernerxError.js +8 -8
  41. package/dist/tools/XernerxIntents.d.ts +2 -2
  42. package/dist/tools/XernerxIntents.js +21 -21
  43. package/dist/tools/XernerxLog.d.ts +25 -23
  44. package/dist/tools/XernerxLog.js +139 -110
  45. package/dist/tools/XernerxText.d.ts +23 -23
  46. package/dist/tools/XernerxText.js +79 -89
  47. package/dist/types/extenders.d.ts +55 -47
  48. package/dist/types/interfaces.d.ts +195 -189
  49. package/dist/types/types.d.ts +104 -5
  50. package/dist/utils/ClientUtil.d.ts +12 -9
  51. package/dist/utils/ClientUtil.js +96 -79
  52. package/dist/utils/InteractionUtil.d.ts +13 -13
  53. package/dist/utils/InteractionUtil.js +148 -147
  54. package/dist/utils/MessageUtil.d.ts +14 -14
  55. package/dist/utils/MessageUtil.js +162 -161
  56. package/dist/utils/Util.d.ts +7 -4
  57. package/dist/utils/Util.js +7 -7
  58. package/dist/validators/commandValidation.d.ts +4 -1
  59. package/dist/validators/commandValidation.js +157 -114
  60. package/dist/validators/inhibitorValidations.d.ts +21 -2
  61. package/dist/validators/inhibitorValidations.js +39 -39
  62. 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
- CommandTypes["SlashCommand"] = "slash";
7
- CommandTypes["MessageCommand"] = "message";
8
- CommandTypes["ContextCommand"] = "context";
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
- const client = event.client;
12
- if (command.ignore?.owner && client.settings.ownerId?.includes(event.user.id))
13
- return false;
14
- const cooldownTime = command.cooldown || client.modules.options?.[CommandTypes[command.filetype]]?.cooldown || client.cooldown?.default || 0;
15
- const cooldown = {
16
- id: event.user.id,
17
- command: command.name,
18
- createdTimestamp: Number(Date.now()) + cooldownTime,
19
- };
20
- const clientPermissions = command.permissions?.client || client.modules.options?.[CommandTypes[command.filetype]]?.permissions?.client || client.settings.permissions?.client || [];
21
- const userPermissions = command.permissions?.user || client.modules.options?.[CommandTypes[command.filetype]]?.permissions?.user || client.settings.permissions?.user || [];
22
- if (!client.cooldowns.collections.commands.has(`${event.user.id}-${command.name}`)) {
23
- client.cooldowns.collections.commands.set(`${event.user.id}-${command.name}`, cooldown);
24
- setTimeout(() => {
25
- client.cooldowns.collections.commands.delete(`${event.user.id}-${command.name}`);
26
- }, cooldownTime);
27
- }
28
- else {
29
- const user = client.cooldowns.collections.commands.get(`${event.user.id}-${command.name}`);
30
- const time = (user?.createdTimestamp || 0) - Number(Date.now());
31
- return emit(event, {
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
- }, command);
38
- }
39
- if (command.channel && event.channel?.type !== undefined && event.channel?.type >= 0) {
40
- if (!command.channel.includes(ChannelType[event.channel?.type]))
41
- return await emit(event, {
42
- reason: 'invalidChannel',
43
- message: `\`${command.name}\` can only be used in ${command.channel.join(', ')} channels`,
44
- channels: command.channel,
45
- }, command);
46
- }
47
- if ((command.ignore?.channels?.length || 0) > 0 && command.ignore?.channels?.includes(event.channel?.id))
48
- return true;
49
- if ((command.ignore?.guilds?.length || 0) > 0 && command.ignore?.guilds?.includes(event.guild?.id))
50
- return true;
51
- if ((command.ignore?.users?.length || 0) > 0 && command.ignore?.users?.includes(event.user.id))
52
- return true;
53
- if (command.ignore?.voice && event.member?.voice?.channel)
54
- return await emit(event, {
55
- reason: 'inVoice',
56
- message: `\`${command.name}\` cannot be ran while in voice chat`,
57
- }, command);
58
- if (command.strict?.owner && !client.settings.ownerId.includes(event.user.id))
59
- return await emit(event, {
60
- reason: 'notADeveloper',
61
- message: `\`${command.name}\` is a developer command`,
62
- owners: client.settings.ownerId,
63
- }, command);
64
- if ((command.strict?.channels?.length || 0) > 0 && !command.strict?.channels?.includes(event.channel?.id))
65
- return await emit(event, {
66
- reason: 'channelRestricted',
67
- message: `\`${command.name}\` cannot be ran in this channel`,
68
- channels: command.strict?.channels,
69
- }, command);
70
- if ((command.strict?.guilds?.length || 0) > 0 && !command.strict?.guilds?.includes(event.guild?.id))
71
- return await emit(event, {
72
- reason: 'guildRestricted',
73
- message: `\`${command.name}\` cannot be ran in this guild`,
74
- guilds: command.strict?.guilds,
75
- }, command);
76
- if ((command.strict?.users?.length || 0) > 0 && !command.strict?.users?.includes(event.user.id))
77
- return await emit(event, {
78
- reason: 'userRestricted',
79
- message: `\`${command.name}\` cannot be ran by you`,
80
- users: command.strict?.users,
81
- }, command);
82
- if (command.strict?.voice && !event.member?.voice?.channel)
83
- return await emit(event, {
84
- reason: 'voiceRestricted',
85
- message: `\`${command.name}\` cannot be ran while not in voice chat`,
86
- }, command);
87
- if (command.permissions?.dm == false && event.channel?.type === ChannelType.DM)
88
- return await emit(event, {
89
- reason: 'DMRestricted',
90
- message: `\`${command.name}\` can't be used in a DM Channel`,
91
- }, command);
92
- if (userPermissions.length) {
93
- const missing = [];
94
- userPermissions.map((permission) => event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission));
95
- if (missing.length)
96
- return await emit(event, {
97
- reason: 'missingUserPermissions',
98
- message: `You are missing the following permissions to run \`${command.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
99
- required: userPermissions,
100
- missing,
101
- }, command);
102
- }
103
- if (clientPermissions.length) {
104
- const missing = [];
105
- clientPermissions.map((permission) => event.guild?.members.me?.permissionsIn(event.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission));
106
- if (missing.length)
107
- return await emit(event, {
108
- reason: 'missingClientPermissions',
109
- message: `I am missing the following permissions to run \`${command.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
110
- required: clientPermissions,
111
- missing,
112
- }, command);
113
- }
114
- if ((!command.global || !client.settings.global) && client.settings.local !== event.guild?.id)
115
- return await emit(event, {
116
- reason: 'local',
117
- message: `\`${command.name}\` is not globally deployed`,
118
- }, command);
119
- return false;
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
- event.client.emit('commandBlock', event, info, command);
123
- return true;
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(event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, args?: SlashCommandArguments | MessageCommandArguments | ContextCommandArguments<'user' | 'message'> | null, cmd?: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand, type?: 'pre' | 'check' | 'post'): Promise<boolean>;
9
- export declare function inhibitorArguments(event: XernerxMessage | XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>, cmd: XernerxContextCommand | XernerxMessageCommand | XernerxSlashCommand | null, type: InhibitorType): import("../types/extenders.js").XernerxUser | import("discord.js").GuildMember | import("discord.js").Guild | import("discord.js").TextBasedChannel | XernerxSlashCommand | XernerxContextCommand | XernerxMessageCommand | import("discord.js").APIInteractionGuildMember | null | undefined;
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
- 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;
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
- 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
- }
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.4",
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
- "readline": "1.3.0",
54
- "typescript": "5.1.6"
56
+ "ts-node": "^10.9.2",
57
+ "typescript": "^5.5.2"
55
58
  }
56
59
  }