xernerx 4.17.7 → 5.0.2

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 (75) hide show
  1. package/README.md +14 -67
  2. package/dist/main.cjs +63 -0
  3. package/dist/main.cjs.map +1 -0
  4. package/dist/main.d.cts +21 -0
  5. package/dist/main.d.ts +20 -46
  6. package/dist/main.js +23 -49
  7. package/dist/main.js.map +1 -0
  8. package/package.json +63 -47
  9. package/src/main.ts +26 -0
  10. package/dist/build/XernerxContextCommand.d.ts +0 -82
  11. package/dist/build/XernerxContextCommand.js +0 -125
  12. package/dist/build/XernerxEvent.d.ts +0 -21
  13. package/dist/build/XernerxEvent.js +0 -27
  14. package/dist/build/XernerxInhibitor.d.ts +0 -53
  15. package/dist/build/XernerxInhibitor.js +0 -27
  16. package/dist/build/XernerxMessageCommand.d.ts +0 -84
  17. package/dist/build/XernerxMessageCommand.js +0 -123
  18. package/dist/build/XernerxSlashCommand.d.ts +0 -104
  19. package/dist/build/XernerxSlashCommand.js +0 -182
  20. package/dist/client/XernerxClient.d.ts +0 -70
  21. package/dist/client/XernerxClient.js +0 -106
  22. package/dist/client/XernerxShardClient.d.ts +0 -21
  23. package/dist/client/XernerxShardClient.js +0 -67
  24. package/dist/functions/deploy.d.ts +0 -3
  25. package/dist/functions/deploy.js +0 -56
  26. package/dist/functions/load.d.ts +0 -4
  27. package/dist/functions/load.js +0 -34
  28. package/dist/functions/reload.d.ts +0 -3
  29. package/dist/functions/reload.js +0 -29
  30. package/dist/functions/setPresence.d.ts +0 -4
  31. package/dist/functions/setPresence.js +0 -22
  32. package/dist/functions/xernerxUser.d.ts +0 -4
  33. package/dist/functions/xernerxUser.js +0 -10
  34. package/dist/handlers/CommandHandler.d.ts +0 -16
  35. package/dist/handlers/CommandHandler.js +0 -326
  36. package/dist/handlers/EventHandler.d.ts +0 -9
  37. package/dist/handlers/EventHandler.js +0 -56
  38. package/dist/handlers/ExtensionHandler.d.ts +0 -9
  39. package/dist/handlers/ExtensionHandler.js +0 -29
  40. package/dist/handlers/Handler.d.ts +0 -31
  41. package/dist/handlers/Handler.js +0 -52
  42. package/dist/handlers/InhibitorHandler.d.ts +0 -9
  43. package/dist/handlers/InhibitorHandler.js +0 -33
  44. package/dist/handlers/IntegrationHandler.d.ts +0 -15
  45. package/dist/handlers/IntegrationHandler.js +0 -26
  46. package/dist/models/Arguments.d.ts +0 -12
  47. package/dist/models/Arguments.js +0 -139
  48. package/dist/models/Cooldowns.d.ts +0 -11
  49. package/dist/models/Cooldowns.js +0 -29
  50. package/dist/tools/XernerxError.d.ts +0 -7
  51. package/dist/tools/XernerxError.js +0 -11
  52. package/dist/tools/XernerxIntents.d.ts +0 -6
  53. package/dist/tools/XernerxIntents.js +0 -26
  54. package/dist/tools/XernerxLog.d.ts +0 -31
  55. package/dist/tools/XernerxLog.js +0 -148
  56. package/dist/tools/XernerxText.d.ts +0 -31
  57. package/dist/tools/XernerxText.js +0 -84
  58. package/dist/types/extenders.d.ts +0 -84
  59. package/dist/types/extenders.js +0 -2
  60. package/dist/types/interfaces.d.ts +0 -263
  61. package/dist/types/interfaces.js +0 -2
  62. package/dist/types/types.d.ts +0 -111
  63. package/dist/types/types.js +0 -2
  64. package/dist/utils/ClientUtil.d.ts +0 -22
  65. package/dist/utils/ClientUtil.js +0 -102
  66. package/dist/utils/InteractionUtil.d.ts +0 -25
  67. package/dist/utils/InteractionUtil.js +0 -154
  68. package/dist/utils/MessageUtil.d.ts +0 -26
  69. package/dist/utils/MessageUtil.js +0 -168
  70. package/dist/utils/Util.d.ts +0 -12
  71. package/dist/utils/Util.js +0 -11
  72. package/dist/validators/commandValidation.d.ts +0 -10
  73. package/dist/validators/commandValidation.js +0 -167
  74. package/dist/validators/inhibitorValidations.d.ts +0 -28
  75. package/dist/validators/inhibitorValidations.js +0 -44
@@ -1,263 +0,0 @@
1
- /** @format */
2
- import { ActivityType, ChannelType, Collection, PresenceStatusData } from 'discord.js';
3
- import CommandHandler from '../handlers/CommandHandler.js';
4
- import EventHandler from '../handlers/EventHandler.js';
5
- import InhibitorHandler from '../handlers/InhibitorHandler.js';
6
- import IntegrationHandler from '../handlers/IntegrationHandler.js';
7
- import XernerxContextCommand from '../build/XernerxContextCommand.js';
8
- import MessageCommandBuilder from '../build/XernerxMessageCommand.js';
9
- import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
10
- import { Locales, MessageCommandArgumentType, PermissionNames, SlashCommandArgumentType, InhibitorType } from './types.js';
11
- import ExtensionHandler from '../handlers/ExtensionHandler.js';
12
- import { XernerxClientEvents, XernerxMessage, XernerxUser } from './extenders.js';
13
- export interface XernerxOptions {
14
- local: string;
15
- global?: boolean;
16
- debug?: boolean;
17
- ownerId?: string | Array<string>;
18
- ceaseless?: boolean;
19
- permissions?: {
20
- user?: Array<PermissionNames> | Array<string> | null;
21
- client?: Array<PermissionNames> | Array<string> | null;
22
- dm?: boolean;
23
- };
24
- ignore?: {
25
- owner?: boolean;
26
- self?: boolean;
27
- bots?: boolean;
28
- system?: boolean;
29
- users?: Array<string>;
30
- channels?: Array<string>;
31
- guilds?: Array<string>;
32
- };
33
- log?:
34
- | {
35
- ready?: boolean;
36
- info?: boolean;
37
- warn?: boolean;
38
- error?: boolean;
39
- table?: Array<'name' | 'aliases' | 'description' | 'filetype' | 'category'>;
40
- format?: Array<'name' | 'node' | 'xernerx' | 'discordjs' | 'platform' | 'time' | 'date' | 'ram' | 'version' | 'author' | 'shard' | 'index'>;
41
- }
42
- | boolean;
43
- cooldown?: {
44
- command?: number;
45
- cache?: number;
46
- collections?: Array<string>;
47
- };
48
- }
49
- export interface ModuleOptions {
50
- options: {
51
- message?: MessageHandlerOptions;
52
- slash?: SlashHandlerOptions;
53
- context?: ContextHandlerOptions;
54
- events?: EventHandlerOptions;
55
- inhibitors?: InhibitorHandlerOptions;
56
- };
57
- commandHandler: CommandHandler;
58
- eventHandler: EventHandler;
59
- inhibitorHandler: InhibitorHandler;
60
- integrationHandler: IntegrationHandler;
61
- extensionHandler: ExtensionHandler;
62
- }
63
- export interface XernerxCommands {
64
- message: Collection<string, MessageCommandBuilder>;
65
- slash: Collection<string, XernerxSlashCommand>;
66
- context: Collection<string, XernerxContextCommand>;
67
- }
68
- export interface DBLOptions {
69
- topgg: {
70
- token: string;
71
- };
72
- dbl: {
73
- token: string;
74
- };
75
- config: {
76
- emits: boolean;
77
- logs: boolean;
78
- };
79
- }
80
- export interface XernerxCache {
81
- messages: Collection<string, string>;
82
- cooldowns: Collection<
83
- string,
84
- {
85
- id: string;
86
- command: string;
87
- createdTimestamp: number;
88
- }
89
- >;
90
- }
91
- interface CommandHandlerOptions {
92
- directory: string;
93
- cooldown?: number;
94
- permissions?: {
95
- user?: Array<PermissionNames> | Array<string> | null;
96
- client?: Array<PermissionNames> | Array<string> | null;
97
- dm?: boolean;
98
- };
99
- }
100
- export interface MessageHandlerOptions extends CommandHandlerOptions {
101
- prefix: string | Array<string>;
102
- allowMention?: boolean;
103
- handleEdits?: boolean;
104
- handleDeletes?: boolean;
105
- handleTyping?: boolean;
106
- }
107
- export interface SlashHandlerOptions extends CommandHandlerOptions {
108
- defer?: {
109
- reply?: boolean;
110
- ephemeral?: boolean;
111
- fetchReply?: boolean;
112
- };
113
- }
114
- export interface ContextHandlerOptions extends CommandHandlerOptions {
115
- defer?: {
116
- reply?: boolean;
117
- ephemeral?: boolean;
118
- fetchReply?: boolean;
119
- };
120
- }
121
- export interface EventHandlerOptions {
122
- directory: string;
123
- }
124
- export interface InhibitorHandlerOptions {
125
- directory: string;
126
- }
127
- interface CommandOptions {
128
- name: string;
129
- description?: string | null;
130
- usage?: string | null;
131
- info?: string | null;
132
- category?: string | null;
133
- cooldown?: number | null;
134
- global?: boolean;
135
- channel?: Array<keyof typeof ChannelType> | keyof typeof ChannelType | null;
136
- ignore?: {
137
- owner?: boolean;
138
- users?: Array<string>;
139
- channels?: Array<string>;
140
- guilds?: Array<string>;
141
- voice?: boolean;
142
- };
143
- strict?: {
144
- owner?: boolean;
145
- users?: Array<string>;
146
- channels?: Array<string>;
147
- guilds?: Array<string>;
148
- voice?: boolean;
149
- };
150
- permissions?: {
151
- user?: Array<PermissionNames> | Array<string> | null;
152
- client?: Array<PermissionNames> | Array<string> | null;
153
- dm?: boolean;
154
- };
155
- }
156
- export interface MessageCommandOptions extends CommandOptions {
157
- aliases?: Array<string>;
158
- separator?: string;
159
- prefix?: Array<string> | string;
160
- regex?: RegExp;
161
- channelType?: Array<ChannelType>;
162
- args?: Array<MessageCommandArgumentOptions>;
163
- flags?: Array<MessageCommandFlagOptions>;
164
- }
165
- export interface MessageCommandArgumentOptions {
166
- type: MessageCommandArgumentType;
167
- name: string;
168
- content?: Array<string>;
169
- match?: string | Array<string>;
170
- description?: string;
171
- default?: string | Function;
172
- separator?: string | RegExp;
173
- prompt?: {
174
- reply?: string;
175
- send?: string;
176
- };
177
- }
178
- export interface MessageCommandFlagOptions {
179
- name: string;
180
- match: string;
181
- }
182
- export interface MessageCommandArguments {
183
- args: Record<string, unknown> | null;
184
- flags: Record<string, boolean> | null;
185
- }
186
- export interface SlashCommandOptions extends CommandOptions {
187
- description: string;
188
- nameLocalizations?: Record<Locales, string | null> | null;
189
- descriptionLocalizations?: Record<Locales, string | null> | null;
190
- defer?: {
191
- reply?: boolean;
192
- ephemeral?: boolean;
193
- fetchReply?: boolean;
194
- };
195
- args?: Array<SlashCommandArgumentOptions>;
196
- subcommands?: Array<SlashCommandSubcommandOptions>;
197
- groups?: Array<SlashCommandGroupOptions>;
198
- }
199
- export interface ContextCommandOptions extends CommandOptions {
200
- type: 'user' | 'message';
201
- nameLocalizations?: Record<Locales, string | null> | null;
202
- defer?: {
203
- reply?: boolean;
204
- ephemeral?: boolean;
205
- fetchReply?: boolean;
206
- };
207
- }
208
- export interface SlashCommandArgumentOptions {
209
- type: SlashCommandArgumentType;
210
- name: string;
211
- description: string;
212
- required?: boolean;
213
- autocomplete?: boolean;
214
- choices?: Array<Record<string, string>>;
215
- }
216
- export interface SlashCommandSubcommandOptions {
217
- name: string;
218
- description: string;
219
- args?: Array<SlashCommandArgumentOptions>;
220
- }
221
- export interface SlashCommandGroupOptions {
222
- name: string;
223
- description: string;
224
- subcommands: Array<SlashCommandSubcommandOptions>;
225
- }
226
- export interface SlashCommandArguments<T = SlashCommandArgumentType> {
227
- args: Record<string, any>;
228
- subcommand: string;
229
- group: string;
230
- }
231
- export interface XernerxEventOptions {
232
- name: keyof XernerxClientEvents;
233
- emitter?: 'client' | 'process';
234
- type?: 'discord' | 'node';
235
- once?: boolean;
236
- }
237
- export interface XernerxInhibitorOptions {
238
- name: string;
239
- type: InhibitorType;
240
- }
241
- export interface PresenceOptions {
242
- text: string;
243
- type?: keyof typeof ActivityType;
244
- url?: string;
245
- status?: PresenceStatusData;
246
- interval?: number;
247
- }
248
- export type ContextCommandArguments<T extends 'user' | 'message'> = T extends 'user' ? XernerxUser : XernerxMessage;
249
- export interface PaginatorOptions {
250
- type?: 'button' | 'select-menu' | 'combined';
251
- buttons?: Array<string>;
252
- description?: boolean;
253
- placeholder?: string;
254
- index?: number;
255
- send?: boolean;
256
- filter?: Function;
257
- time?: number;
258
- }
259
- export interface ResolveCommandOptions {
260
- type?: 'MessageCommand' | 'SlashCommand' | 'ContextCommand' | 'Interaction';
261
- name?: string;
262
- }
263
- export {};
@@ -1,2 +0,0 @@
1
- /** @format */
2
- export {};
@@ -1,111 +0,0 @@
1
- /** @format */
2
- import {
3
- SlashCommandBooleanOption,
4
- SlashCommandChannelOption,
5
- SlashCommandIntegerOption,
6
- SlashCommandMentionableOption,
7
- SlashCommandNumberOption,
8
- SlashCommandRoleOption,
9
- SlashCommandStringOption,
10
- SlashCommandUserOption,
11
- } from 'discord.js';
12
- import { XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUserContextInteraction } from './extenders.js';
13
- export type filetype = 'MessageCommand' | 'SlashCommand' | 'ContextCommand' | 'Event' | 'Inhibitor';
14
- export type Locales =
15
- | 'en-US'
16
- | 'en-GB'
17
- | 'bg'
18
- | 'zh-CN'
19
- | 'zh-TW'
20
- | 'hr'
21
- | 'cs'
22
- | 'da'
23
- | 'nl'
24
- | 'fi'
25
- | 'fr'
26
- | 'de'
27
- | 'el'
28
- | 'hi'
29
- | 'hu'
30
- | 'it'
31
- | 'ja'
32
- | 'ko'
33
- | 'lt'
34
- | 'no'
35
- | 'pl'
36
- | 'pt-BR'
37
- | 'ro'
38
- | 'ru'
39
- | 'es-ES'
40
- | 'sv-SE'
41
- | 'th'
42
- | 'tr'
43
- | 'uk'
44
- | 'vi';
45
- export type SlashCommandArgumentType = 'attachment' | 'boolean' | 'channel' | 'integer' | 'mentionable' | 'number' | 'role' | 'string' | 'user';
46
- export type SlashCommandOptionChoices = SlashCommandStringOption | SlashCommandNumberOption | SlashCommandIntegerOption;
47
- export type SlashCommandOption = SlashCommandOptionChoices | SlashCommandBooleanOption | SlashCommandUserOption | SlashCommandChannelOption | SlashCommandRoleOption | SlashCommandMentionableOption;
48
- export type MessageCommandArgumentType =
49
- | 'string'
50
- | 'number'
51
- | 'boolean'
52
- | 'confirm'
53
- | 'channel'
54
- | 'guild'
55
- | 'integer'
56
- | 'mentionable'
57
- | 'role'
58
- | 'user'
59
- | 'message'
60
- | 'member'
61
- | 'list'
62
- | 'option'
63
- | 'rest';
64
- export type XernerxInteraction<T extends XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction> = T extends XernerxSlashInteraction
65
- ? XernerxSlashInteraction
66
- : T extends XernerxUserContextInteraction
67
- ? XernerxUserContextInteraction
68
- : XernerxMessageContextInteraction;
69
- export type PermissionNames =
70
- | 'create instant invite'
71
- | 'kick members'
72
- | 'ban members'
73
- | 'administrator'
74
- | 'manage channels'
75
- | 'manage guild'
76
- | 'add reactions'
77
- | 'view audit log'
78
- | 'priority speaker'
79
- | 'stream'
80
- | 'view channel'
81
- | 'send messages'
82
- | 'send tts messages'
83
- | 'manage messages'
84
- | 'embed links'
85
- | 'attach files'
86
- | 'read message history'
87
- | 'mention everyone'
88
- | 'use external emojis'
89
- | 'view guild insights'
90
- | 'connect'
91
- | 'speak'
92
- | 'mute members'
93
- | 'deafen members'
94
- | 'move members'
95
- | 'use vad'
96
- | 'change nickname'
97
- | 'manage nicknames'
98
- | 'manage roles'
99
- | 'manage webhooks'
100
- | 'manage emojis and stickers'
101
- | 'use application commands'
102
- | 'request to speak'
103
- | 'manage events'
104
- | 'manage threads'
105
- | 'create public threads'
106
- | 'create private threads'
107
- | 'use external stickers'
108
- | 'send messages in threads'
109
- | 'start embedded activities'
110
- | 'moderate members';
111
- export type InhibitorType = '*' | 'message' | 'interaction' | 'command' | 'channel' | 'user' | 'member' | 'guild' | 'contextCommand' | 'messageCommand' | 'slashCommand';
@@ -1,2 +0,0 @@
1
- /** @format */
2
- export {};
@@ -1,22 +0,0 @@
1
- /** @format */
2
- import { Collection } from 'discord.js';
3
- import XernerxClient from '../client/XernerxClient.js';
4
- import { PresenceOptions, ResolveCommandOptions } from '../types/interfaces.js';
5
- import Util from './Util.js';
6
- import XernerxContextCommand from '../build/XernerxContextCommand.js';
7
- import XernerxMessageCommand from '../build/XernerxMessageCommand.js';
8
- import XernerxSlashCommand from '../build/XernerxSlashCommand.js';
9
- export default class ClientUtil extends Util {
10
- hasVoted: Function;
11
- constructor(client: XernerxClient);
12
- setPresence(options: PresenceOptions): import('discord.js').ClientPresence | undefined;
13
- private resolveCooldown;
14
- resolveCommand(
15
- options: ResolveCommandOptions
16
- ): Promise<XernerxSlashCommand | XernerxContextCommand | XernerxMessageCommand | Collection<string, XernerxSlashCommand | XernerxContextCommand | XernerxMessageCommand>>;
17
- resolveChannel(query: string | Record<string, string>): Promise<import('discord.js').Channel | null>;
18
- resolveGuild(query: string | Record<string, string>): Promise<import('discord.js').Guild | null>;
19
- uptime(timestamp?: number | null): string;
20
- commands(): (XernerxSlashCommand | XernerxContextCommand | XernerxMessageCommand)[];
21
- commandsList(): Collection<string, object>;
22
- }
@@ -1,102 +0,0 @@
1
- /** @format */
2
- import { Collection } from 'discord.js';
3
- import setPresence from '../functions/setPresence.js';
4
- import Util from './Util.js';
5
- export default class ClientUtil extends Util {
6
- constructor(client) {
7
- super(client);
8
- this.setPresence = this.setPresence;
9
- this.resolveCooldown = this.resolveCooldown;
10
- this.resolveChannel = this.resolveChannel;
11
- this.commands = this.commands;
12
- this.resolveGuild = this.resolveGuild;
13
- this.uptime = this.uptime;
14
- }
15
- setPresence(options) {
16
- return setPresence(this.client, options);
17
- }
18
- // @ts-ignore
19
- resolveCooldown() {}
20
- async resolveCommand(options) {
21
- const interCommands = await this.client.application?.commands.fetch();
22
- const commands = [],
23
- collection = new Collection();
24
- if (options?.type == 'MessageCommand' || !options?.type) commands.push(...this.client.commands.message);
25
- if (options?.type == 'Interaction' || options?.type == 'SlashCommand' || !options?.type) commands.push(...this.client.commands.slash);
26
- if (options?.type == 'Interaction' || options?.type == 'ContextCommand' || !options?.type) commands.push(...this.client.commands.context);
27
- commands.map(([name, command]) => {
28
- command.snowflake = interCommands?.find((cmd) => command.name === cmd.name)?.id || null;
29
- collection.set(name, command);
30
- });
31
- if (options?.name) {
32
- return collection.get(options.name) || null;
33
- } else return collection;
34
- }
35
- async resolveChannel(query) {
36
- if (typeof query == 'object') query = query.id;
37
- try {
38
- let channel = this.client.channels.cache.find((channel) => (channel.name == query.toLowerCase() || channel.id == query.toLowerCase() ? channel : null)) || null;
39
- if (!channel) channel = (await this.client.channels.fetch(query)) || null;
40
- return channel;
41
- } catch {
42
- return null;
43
- }
44
- }
45
- async resolveGuild(query) {
46
- if (typeof query == 'object') query = query.id;
47
- try {
48
- let guild = this.client.guilds.cache.find((guild) => guild.name.toLowerCase() == query.toLowerCase()) || null;
49
- if (!guild) guild = (await this.client.guilds.fetch(query)) || null;
50
- return guild;
51
- } catch {
52
- return null;
53
- }
54
- }
55
- uptime(timestamp) {
56
- if (!timestamp) timestamp = this.client.uptime || 0;
57
- let totalSeconds = timestamp / 1000;
58
- let years = Math.floor(totalSeconds / 31536000);
59
- totalSeconds %= 31536000;
60
- let days = Math.floor(totalSeconds / 86400);
61
- totalSeconds %= 86400;
62
- let hours = Math.floor(totalSeconds / 3600);
63
- totalSeconds %= 3600;
64
- let minutes = Math.floor(totalSeconds / 60);
65
- let seconds = Math.floor(totalSeconds % 60);
66
- if (years >= 1) return `${years}y ${days}d ${hours}h ${minutes}m`;
67
- else if (days >= 1) return `${days}d ${hours}h ${minutes}m`;
68
- else if (hours >= 1) return `${hours}h ${minutes}m`;
69
- else if (minutes >= 1) return `${minutes}m ${seconds}s`;
70
- else return `${seconds}s`;
71
- }
72
- commands() {
73
- return [...this.client.commands.context.toJSON(), ...this.client.commands.slash.toJSON(), ...this.client.commands.message.toJSON()];
74
- }
75
- commandsList() {
76
- function set(name, type, description, usage) {
77
- return collection.set(name, { name, type, description, usage });
78
- }
79
- const commands = this.commands();
80
- const collection = new Collection();
81
- commands.map((command) => {
82
- if (command.filetype == 'MessageCommand' || command.filetype == 'ContextCommand') return set(command.name, command.filetype, command.description, command.usage);
83
- else if (command.data.options.length) {
84
- command.data.options.map((option) => {
85
- if (!option.type) {
86
- if (option.options.length) {
87
- option.options.map((o) => {
88
- if (!o.type) set(`${command.name} ${option.name} ${o.name}`, command.filetype, o.description, command.usage);
89
- else set(`${command.name} ${option.name}`, command.filetype, option.description, command.usage);
90
- });
91
- } else {
92
- set(`${command.name} ${option.name}`, command.filetype, option.description, command.usage);
93
- }
94
- }
95
- });
96
- } else {
97
- set(command.name, command.filetype, command.description, command.usage);
98
- }
99
- });
100
- return collection;
101
- }
102
- }
@@ -1,25 +0,0 @@
1
- /** @format */
2
- import { EmbedBuilder, InteractionEditReplyOptions, InteractionReplyOptions, MessageCreateOptions, MessagePayload } from 'discord.js';
3
- import XernerxClient from '../client/XernerxClient.js';
4
- import { ContextCommandArguments, PaginatorOptions, SlashCommandArguments } from '../types/interfaces.js';
5
- import { PermissionNames, XernerxInteraction } from '../types/types.js';
6
- import Util from './Util.js';
7
- import { XernerxMessageContextInteraction, XernerxSlashInteraction, XernerxUser, XernerxUserContextInteraction } from '../types/extenders.js';
8
- type MimicOptions = {
9
- timeout: number;
10
- };
11
- export default class InteractionUtil extends Util {
12
- private readonly interaction;
13
- parsed: {
14
- alias: string | null;
15
- args: (SlashCommandArguments | ContextCommandArguments<'message' | 'user'>) | null;
16
- };
17
- constructor(client: XernerxClient, interaction: XernerxInteraction<XernerxSlashInteraction | XernerxUserContextInteraction | XernerxMessageContextInteraction>);
18
- send(content: any): Promise<import('discord.js').Message<false> | import('discord.js').Message<true> | undefined>;
19
- reply(content: string | MessagePayload | InteractionReplyOptions | InteractionEditReplyOptions): Promise<import('discord.js').InteractionResponse<boolean> | import('discord.js').Message<boolean>>;
20
- mimic(user: XernerxUser | string, interaction: MessageCreateOptions, options: MimicOptions): Promise<void>;
21
- paginator(embeds: Array<EmbedBuilder>, options?: PaginatorOptions): Promise<void | import('discord.js').Message<false> | import('discord.js').Message<true>>;
22
- commands(): import('discord.js').Collection<string, import('../main.js').XernerxSlashCommand> | import('discord.js').Collection<string, import('../main.js').XernerxContextCommand>;
23
- permissionCheck(type: 'user' | 'client', permissions: Array<PermissionNames>, emit?: boolean): boolean | string[];
24
- }
25
- export {};
@@ -1,154 +0,0 @@
1
- /** @format */
2
- import { ActionRowBuilder, ButtonBuilder, ButtonStyle, InteractionType, StringSelectMenuBuilder } from 'discord.js';
3
- import Util from './Util.js';
4
- import XernerxError from '../tools/XernerxError.js';
5
- import { Style } from 'dumfunctions';
6
- export default class InteractionUtil extends Util {
7
- constructor(client, interaction) {
8
- super(client);
9
- this.interaction = interaction;
10
- this.parsed = {
11
- alias: null,
12
- args: null,
13
- };
14
- }
15
- async send(content) {
16
- if (!content) throw new XernerxError(`Can't send a message without content.`);
17
- return await this.interaction.channel?.send(content);
18
- }
19
- async reply(content) {
20
- if (!content) throw new XernerxError(`Can't send a message without content.`);
21
- return await (this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content));
22
- }
23
- async mimic(user, interaction, options) {
24
- user = typeof user == 'string' ? await this.client.users.fetch(user) : user;
25
- const webhooks = await this.interaction.channel.fetchWebhooks();
26
- const webhook =
27
- webhooks.find((wh) => wh.token) ||
28
- (await this.interaction.channel.createWebhook({
29
- name: `${this.client.user?.username}'s mimic webhook.`,
30
- avatar: user.displayAvatarURL() || this.client.user?.displayAvatarURL(),
31
- }));
32
- await webhook.send({
33
- content: interaction.content,
34
- username: user.username,
35
- avatarURL: user.displayAvatarURL(),
36
- });
37
- setTimeout(() => {
38
- webhook.delete().catch(() => true);
39
- }, options.timeout);
40
- }
41
- async paginator(embeds, options = {}) {
42
- let buttonRow, menuRow;
43
- if (embeds.length <= 0) throw new XernerxError(`Can't make a paginator without embeds`);
44
- options = {
45
- type: options.type ?? 'combined',
46
- buttons: options.buttons ?? ['⏪', '◀️', '⏹️', '▶️', '⏩'],
47
- description: options.description ?? false,
48
- placeholder: options.placeholder ?? 'Change page',
49
- index: options.index ?? 0,
50
- send: options.send ?? false,
51
- filter: options.filter ?? (() => true),
52
- time: options.time ?? 300000,
53
- };
54
- if (options.type == 'button' || options.type == 'combined') {
55
- if (!options.buttons) throw new XernerxError(`¯\\_(ツ)_/¯ Somehow there are no buttons? ¯\\_(ツ)_/¯`);
56
- buttonRow = new ActionRowBuilder().addComponents(
57
- ...options.buttons.map((button, i) => new ButtonBuilder().setCustomId(`${this.interaction.id}-${i}`).setEmoji(button).setStyle(ButtonStyle.Primary))
58
- );
59
- }
60
- if (options.type == 'select-menu' || options.type == 'combined') {
61
- menuRow = new ActionRowBuilder().addComponents(
62
- new StringSelectMenuBuilder()
63
- .setCustomId(`${this.interaction.id}-select-menu`)
64
- .setPlaceholder(options.placeholder)
65
- .addOptions(...embeds.map((embed, i) => ({ label: embed.data.title || 'No Title', description: (options.description ? embed.data.description : undefined) || undefined, value: `${i}` })))
66
- );
67
- }
68
- let index = options.index || 0;
69
- return options.send
70
- ? await this.interaction.util.send({
71
- embeds: [embeds[index]],
72
- components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
73
- })
74
- : await this.interaction.util
75
- .reply({
76
- embeds: [embeds[index]],
77
- components: [options.type == 'combined' || options.type == 'button' ? buttonRow : null, options.type == 'combined' || options.type == 'select-menu' ? menuRow : null].filter((x) => x),
78
- })
79
- .then(async (msg) => {
80
- const collector = this.interaction.channel
81
- ?.createMessageComponentCollector({ time: options.time })
82
- .on('collect', (collect) => {
83
- if (!collect.customId.startsWith(this.interaction.id)) return;
84
- if (collect.customId.endsWith('select-menu')) {
85
- index = Number(collect.values[0]);
86
- collect.update({ embeds: [embeds[index]] });
87
- } else {
88
- const option = Number(collect.customId.split(/-/)[1]);
89
- let embed = embeds[index];
90
- if (option == 0) {
91
- index = 0;
92
- embed = embeds[index];
93
- collect.update({ embeds: [embed] });
94
- }
95
- if (option == 1) {
96
- index = embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0;
97
- embed = embeds[index];
98
- collect.update({ embeds: [embed] });
99
- }
100
- if (option == 2) {
101
- collect.update({ components: [] });
102
- collector?.stop();
103
- }
104
- if (option == 3) {
105
- index = embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1;
106
- embed = embeds[index];
107
- collect.update({ embeds: [embed] });
108
- }
109
- if (option == 4) {
110
- index = embeds.length - 1;
111
- embed = embeds[index];
112
- collect.update({ embeds: [embed] });
113
- }
114
- }
115
- })
116
- .on('end', async () => {
117
- this.interaction.editReply({ components: [] });
118
- });
119
- });
120
- }
121
- commands() {
122
- if (this.interaction.type == InteractionType.ApplicationCommand) return this.client.commands.slash;
123
- else return this.client.commands.context;
124
- }
125
- permissionCheck(type, permissions, emit = true) {
126
- const missing = [];
127
- for (const permission of permissions) {
128
- if (type == 'user') {
129
- this.interaction.memberPermissions?.has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
130
- }
131
- if (type == 'client') {
132
- this.interaction.guild?.members.me?.permissionsIn(this.interaction.channel?.id).has(Style.pascalCase(permission, true)) ? null : missing.push(permission);
133
- }
134
- }
135
- const command = this.commands()
136
- .toJSON()
137
- .find((cmd) => cmd.name == this.parsed.alias?.split(/ +/)[0]);
138
- if (missing.length && emit) {
139
- this.client.emit(
140
- `commandBlock`,
141
- this.interaction,
142
- {
143
- reason: `missing${Style.pascalCase(type)}Permissions`,
144
- message: `${type == 'user' ? 'You are' : 'I am'} missing the following permissions to run \`${command?.name}\`:\n${missing.map((permission) => `> - ${permission}`).join('\n')}`,
145
- required: permissions,
146
- missing,
147
- },
148
- command || null
149
- );
150
- return false;
151
- } else if (missing.length && !emit) return missing;
152
- else return true;
153
- }
154
- }