xernerx 3.2.6 → 3.3.1
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 +1 -1
- package/dist/build/ContextCommand.d.ts +1 -1
- package/dist/build/ContextCommand.js +1 -1
- package/dist/build/ContextCommandBuilder.d.ts +40 -0
- package/dist/build/ContextCommandBuilder.js +84 -0
- package/dist/build/Event.d.ts +1 -1
- package/dist/build/Event.js +1 -1
- package/dist/build/EventBuilder.d.ts +17 -0
- package/dist/build/EventBuilder.js +35 -0
- package/dist/build/ExtensionBuilder.d.ts +7 -0
- package/dist/build/ExtensionBuilder.js +9 -0
- package/dist/build/Inhibitor.d.ts +3 -0
- package/dist/build/Inhibitor.js +3 -0
- package/dist/build/InhibitorBuilder.d.ts +19 -0
- package/dist/build/InhibitorBuilder.js +28 -0
- package/dist/build/MessageCommand.d.ts +2 -2
- package/dist/build/MessageCommand.js +1 -1
- package/dist/build/MessageCommandBuilder.d.ts +42 -0
- package/dist/build/MessageCommandBuilder.js +80 -0
- package/dist/build/SlashCommand.d.ts +3 -3
- package/dist/build/SlashCommand.js +3 -3
- package/dist/build/SlashCommandBuilder.d.ts +36 -0
- package/dist/build/SlashCommandBuilder.js +110 -0
- package/dist/build/XernerxExtension.d.ts +7 -0
- package/dist/build/XernerxExtension.js +9 -0
- package/dist/client/XernerxClient.d.ts +13 -9
- package/dist/client/XernerxClient.js +12 -12
- package/dist/handlers/CommandHandler.d.ts +4 -4
- package/dist/handlers/EventHandler.d.ts +2 -2
- package/dist/handlers/Handler.d.ts +6 -6
- package/dist/handlers/Handler.js +1 -1
- package/dist/handlers/InhibitorHandler.d.ts +4 -4
- package/dist/handlers/InhibitorHandler.js +1 -1
- package/dist/interfaces/ClientInterfaces.d.ts +8 -7
- package/dist/interfaces/CommandInterfaces.d.ts +1 -1
- package/dist/interfaces/HandlerInterfaces.d.ts +2 -11
- package/dist/main.d.ts +19 -16
- package/dist/main.js +22 -19
- package/dist/models/CommandArguments.d.ts +15 -7
- package/dist/models/CommandArguments.js +42 -49
- package/dist/models/CommandValidations.d.ts +4 -3
- package/dist/models/CommandValidations.js +9 -17
- package/dist/models/Events.d.ts +1 -0
- package/dist/models/Events.js +61 -140
- package/dist/models/Extensions.d.ts +2 -2
- package/dist/models/InhibitorValidations.d.ts +8 -13
- package/dist/models/InhibitorValidations.js +1 -1
- package/dist/tools/XernerxError.js +2 -2
- package/dist/types/Types.d.ts +29 -25
- package/dist/types/Types.js +1 -26
- package/dist/types/enums.d.ts +35 -0
- package/dist/types/enums.js +35 -0
- package/dist/types/interfaces.d.ts +25 -0
- package/dist/types/interfaces.js +1 -0
- package/dist/types/objects.d.ts +18 -0
- package/dist/types/objects.js +1 -0
- package/dist/types/options.d.ts +204 -0
- package/dist/types/options.js +1 -0
- package/dist/utils/ClientUtil.d.ts +2 -2
- package/dist/utils/ClientUtil.js +12 -27
- package/dist/utils/CommandUtil.d.ts +5 -5
- package/dist/utils/CommandUtil.js +24 -45
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TextChannel, Message, User, Guild, GuildMember } from "discord.js";
|
|
2
|
+
import { InteractionCommandUtil, MessageCommandUtil } from "../utils/CommandUtil.js";
|
|
3
|
+
export interface XernerxMessage extends Message {
|
|
4
|
+
util?: MessageCommandUtil;
|
|
5
|
+
response?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface XernerxInteraction extends Message {
|
|
8
|
+
util: InteractionCommandUtil;
|
|
9
|
+
}
|
|
10
|
+
export interface XernerxUser extends User {
|
|
11
|
+
isOwner: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface XernerxTextChannel extends TextChannel {
|
|
14
|
+
}
|
|
15
|
+
export interface XernerxGuild extends Guild {
|
|
16
|
+
}
|
|
17
|
+
export interface XernerxMember extends GuildMember {
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { CacheFactory, ChannelType, ContextMenuCommandType, MessageMentionOptions, Partials, PresenceData, RESTOptions, SweeperOptions, WebSocketOptions } from 'discord.js';
|
|
2
|
+
import { ContextCommandType, EventEmitterType, ExtensionBuilder, InhibitorType } from '../main.js';
|
|
3
|
+
import { MessageCommandArgsTypes } from './types.js';
|
|
4
|
+
export interface DiscordOptions {
|
|
5
|
+
shards?: number | number[] | 'auto';
|
|
6
|
+
closeTimeout?: number;
|
|
7
|
+
shardCount?: number;
|
|
8
|
+
makeCache?: CacheFactory;
|
|
9
|
+
allowedMentions?: MessageMentionOptions;
|
|
10
|
+
partials?: Array<Partials>;
|
|
11
|
+
failIfNotExists?: boolean;
|
|
12
|
+
presence?: PresenceData;
|
|
13
|
+
intents: number[];
|
|
14
|
+
waitGuildTimeout?: number;
|
|
15
|
+
sweepers?: SweeperOptions;
|
|
16
|
+
ws?: WebSocketOptions;
|
|
17
|
+
rest?: RESTOptions;
|
|
18
|
+
jsonTransformer?: (obj: unknown) => unknown;
|
|
19
|
+
}
|
|
20
|
+
export interface ClientOptions {
|
|
21
|
+
ownerId?: string | string[];
|
|
22
|
+
clientPermissions?: bigint[];
|
|
23
|
+
userPermissions?: bigint[];
|
|
24
|
+
ignoreOwner?: boolean;
|
|
25
|
+
logging?: boolean;
|
|
26
|
+
cooldown?: {
|
|
27
|
+
default?: number;
|
|
28
|
+
cache?: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface HandlerOptions {
|
|
32
|
+
message?: MessageCommandHandlerOptions;
|
|
33
|
+
slash?: SlashCommandHandlerOptions;
|
|
34
|
+
context?: ContextCommandHandlerOptions;
|
|
35
|
+
events?: EventHandlerOptions;
|
|
36
|
+
inhibitors?: InhibitorHandlerOptions;
|
|
37
|
+
}
|
|
38
|
+
export interface ExtensionOptions {
|
|
39
|
+
extensions: Array<ExtensionBuilder>;
|
|
40
|
+
logging?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface MessageCommandOptions {
|
|
43
|
+
name: string;
|
|
44
|
+
regex?: string;
|
|
45
|
+
aliases?: string[];
|
|
46
|
+
description?: string;
|
|
47
|
+
prefix?: string | string[];
|
|
48
|
+
info?: string;
|
|
49
|
+
category?: string;
|
|
50
|
+
owner?: boolean;
|
|
51
|
+
channelType?: ChannelType | ChannelType[];
|
|
52
|
+
separator?: string;
|
|
53
|
+
cooldown?: number;
|
|
54
|
+
ignoreOwner?: boolean;
|
|
55
|
+
channels?: string[];
|
|
56
|
+
guilds?: string[];
|
|
57
|
+
userPermissions?: bigint[];
|
|
58
|
+
clientPermissions?: bigint[];
|
|
59
|
+
commandType?: string;
|
|
60
|
+
args: Array<MessageArgOptions>;
|
|
61
|
+
}
|
|
62
|
+
export interface ContextCommandOptions {
|
|
63
|
+
name: string;
|
|
64
|
+
type: ContextMenuCommandType | ContextCommandType | number;
|
|
65
|
+
description?: string;
|
|
66
|
+
info?: string;
|
|
67
|
+
category?: string;
|
|
68
|
+
owner?: boolean;
|
|
69
|
+
channelType?: ChannelType;
|
|
70
|
+
cooldown?: number;
|
|
71
|
+
ignoreOwner?: boolean;
|
|
72
|
+
channels?: string[];
|
|
73
|
+
guilds?: string[];
|
|
74
|
+
userPermissions?: bigint[];
|
|
75
|
+
clientPermissions?: bigint[];
|
|
76
|
+
defaultMemberPermissions?: bigint | number | bigint | null | undefined;
|
|
77
|
+
DMPermission?: undefined | null | boolean;
|
|
78
|
+
nameLocalization?: {
|
|
79
|
+
locale: 'en-US' | 'en-GB' | 'bg' | 'zh-CN' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi';
|
|
80
|
+
localizedName: null | string;
|
|
81
|
+
};
|
|
82
|
+
nameLocalizations?: null | Partial<Record<'en-US' | 'en-GB' | 'bg' | 'zh-CN' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'nl' | 'fi' | 'fr' | 'de' | 'el' | 'hi' | 'hu' | 'it' | 'ja' | 'ko' | 'lt' | 'no' | 'pl' | 'pt-BR' | 'ro' | 'ru' | 'es-ES' | 'sv-SE' | 'th' | 'tr' | 'uk' | 'vi', null | string>>;
|
|
83
|
+
commandType?: string;
|
|
84
|
+
defer?: {
|
|
85
|
+
reply?: boolean;
|
|
86
|
+
ephemeral?: boolean;
|
|
87
|
+
fetchReply?: boolean;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface MessageArgOptions {
|
|
91
|
+
type: MessageCommandArgsTypes;
|
|
92
|
+
content?: string;
|
|
93
|
+
name: string;
|
|
94
|
+
prompt: {
|
|
95
|
+
reply: string;
|
|
96
|
+
send: string;
|
|
97
|
+
};
|
|
98
|
+
default: string | Function;
|
|
99
|
+
}
|
|
100
|
+
export interface SlashArgOptions {
|
|
101
|
+
type: 'string' | 'number' | 'boolean' | 'user' | 'channel' | 'role' | 'mentionable' | 'integer';
|
|
102
|
+
name: string;
|
|
103
|
+
choices: Array<{
|
|
104
|
+
name: string;
|
|
105
|
+
value: string;
|
|
106
|
+
}>;
|
|
107
|
+
required: boolean;
|
|
108
|
+
description: string;
|
|
109
|
+
}
|
|
110
|
+
export interface SlashSubcommandOptions {
|
|
111
|
+
name: string;
|
|
112
|
+
description: string;
|
|
113
|
+
args: Array<SlashArgOptions>;
|
|
114
|
+
}
|
|
115
|
+
export interface SlashGroupOptions {
|
|
116
|
+
name: string;
|
|
117
|
+
description: string;
|
|
118
|
+
subcommands: Array<SlashSubcommandOptions>;
|
|
119
|
+
}
|
|
120
|
+
export interface SlashCommandOptions {
|
|
121
|
+
name: string;
|
|
122
|
+
description: string;
|
|
123
|
+
info?: string;
|
|
124
|
+
category?: string;
|
|
125
|
+
owner?: boolean;
|
|
126
|
+
channelType?: ChannelType;
|
|
127
|
+
separator?: string;
|
|
128
|
+
cooldown?: number;
|
|
129
|
+
ignoreOwner?: boolean;
|
|
130
|
+
channels?: string[];
|
|
131
|
+
guilds?: string[];
|
|
132
|
+
userPermissions?: bigint[];
|
|
133
|
+
clientPermissions?: bigint[];
|
|
134
|
+
args?: Array<SlashArgOptions>;
|
|
135
|
+
subcommands?: Array<SlashSubcommandOptions>;
|
|
136
|
+
groups?: Array<SlashGroupOptions>;
|
|
137
|
+
commandType?: string;
|
|
138
|
+
defer?: {
|
|
139
|
+
reply?: boolean;
|
|
140
|
+
ephemeral?: boolean;
|
|
141
|
+
fetchReply?: boolean;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export interface MessageCommandHandlerOptions {
|
|
145
|
+
directory: string;
|
|
146
|
+
prefix: string[] | string;
|
|
147
|
+
allowMention?: boolean;
|
|
148
|
+
cooldown?: number;
|
|
149
|
+
userPermissions?: bigint[];
|
|
150
|
+
clientPermissions?: bigint[];
|
|
151
|
+
handleEdits?: boolean;
|
|
152
|
+
handleDeletes?: boolean;
|
|
153
|
+
handleTyping?: boolean;
|
|
154
|
+
util?: boolean;
|
|
155
|
+
logging?: boolean;
|
|
156
|
+
}
|
|
157
|
+
export interface SlashCommandHandlerOptions {
|
|
158
|
+
directory: string;
|
|
159
|
+
guildId: string;
|
|
160
|
+
global: boolean;
|
|
161
|
+
cooldown?: number;
|
|
162
|
+
userPermissions?: bigint[];
|
|
163
|
+
clientPermissions?: bigint[];
|
|
164
|
+
util?: boolean;
|
|
165
|
+
logging?: boolean;
|
|
166
|
+
defer?: {
|
|
167
|
+
reply?: boolean;
|
|
168
|
+
ephemeral?: boolean;
|
|
169
|
+
fetchReply?: boolean;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export interface ContextCommandHandlerOptions {
|
|
173
|
+
directory: string;
|
|
174
|
+
guildId: string;
|
|
175
|
+
global: boolean;
|
|
176
|
+
cooldown?: number;
|
|
177
|
+
userPermissions?: bigint[];
|
|
178
|
+
clientPermissions?: bigint[];
|
|
179
|
+
util?: boolean;
|
|
180
|
+
logging?: boolean;
|
|
181
|
+
defer?: {
|
|
182
|
+
reply?: boolean;
|
|
183
|
+
ephemeral?: boolean;
|
|
184
|
+
fetchReply?: boolean;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export interface EventHandlerOptions {
|
|
188
|
+
directory: string;
|
|
189
|
+
logging?: boolean;
|
|
190
|
+
}
|
|
191
|
+
export interface EventOptions {
|
|
192
|
+
name: string;
|
|
193
|
+
emitter?: EventEmitterType;
|
|
194
|
+
type?: string;
|
|
195
|
+
once?: boolean;
|
|
196
|
+
}
|
|
197
|
+
export interface InhibitorHandlerOptions {
|
|
198
|
+
directory: string;
|
|
199
|
+
logging?: boolean;
|
|
200
|
+
}
|
|
201
|
+
export interface InhibitorOptions {
|
|
202
|
+
name: string;
|
|
203
|
+
type: InhibitorType;
|
|
204
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActivityType, ClientPresenceStatus } from
|
|
2
|
-
import XernerxClient from
|
|
1
|
+
import { ActivityType, ClientPresenceStatus } from 'discord.js';
|
|
2
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
3
3
|
interface Presence {
|
|
4
4
|
text?: string;
|
|
5
5
|
type?: ActivityType.Playing | ActivityType.Streaming | ActivityType.Listening | ActivityType.Watching | ActivityType.Competing;
|
package/dist/utils/ClientUtil.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import XernerxError from
|
|
1
|
+
import XernerxError from '../tools/XernerxError.js';
|
|
2
2
|
export class ClientUtil {
|
|
3
3
|
client;
|
|
4
4
|
constructor(client) {
|
|
@@ -39,12 +39,11 @@ export class ClientUtil {
|
|
|
39
39
|
return `${seconds}s`;
|
|
40
40
|
}
|
|
41
41
|
getSubcommands(name) {
|
|
42
|
-
if (!name || typeof name !==
|
|
42
|
+
if (!name || typeof name !== 'string')
|
|
43
43
|
throw new XernerxError(`Expected name to be of type string, received ${typeof name} instead!`);
|
|
44
44
|
const commands = [];
|
|
45
45
|
this.getAllCommands()
|
|
46
|
-
.filter((c) => (c.data?.name?.toLowerCase() || c.name?.toLowerCase()) ==
|
|
47
|
-
name?.toLowerCase())
|
|
46
|
+
.filter((c) => (c.data?.name?.toLowerCase() || c.name?.toLowerCase()) == name?.toLowerCase())
|
|
48
47
|
.map((c) => {
|
|
49
48
|
if (c?.data?.options?.length > 0) {
|
|
50
49
|
c?.data?.options?.map((option) => {
|
|
@@ -106,11 +105,11 @@ export class ClientUtil {
|
|
|
106
105
|
}
|
|
107
106
|
isOwner(userId) {
|
|
108
107
|
if (!userId)
|
|
109
|
-
throw new XernerxError(
|
|
108
|
+
throw new XernerxError('No ID specified');
|
|
110
109
|
let owners = this.client.settings.ownerId;
|
|
111
110
|
if (!owners)
|
|
112
111
|
return false;
|
|
113
|
-
if (typeof owners ===
|
|
112
|
+
if (typeof owners === 'string')
|
|
114
113
|
owners = [owners];
|
|
115
114
|
return owners.includes(userId);
|
|
116
115
|
}
|
|
@@ -160,20 +159,14 @@ export class ClientUtil {
|
|
|
160
159
|
getCooldowns(id, command) {
|
|
161
160
|
let cooldowns = [];
|
|
162
161
|
for (const [key, value] of Object.entries(this.client.cache)) {
|
|
163
|
-
if (![
|
|
164
|
-
"cooldowns",
|
|
165
|
-
"messageCommands",
|
|
166
|
-
"slashCommands",
|
|
167
|
-
"contextCommands",
|
|
168
|
-
"commands",
|
|
169
|
-
].includes(key))
|
|
162
|
+
if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key))
|
|
170
163
|
continue;
|
|
171
|
-
if (key ===
|
|
164
|
+
if (key === 'commands') {
|
|
172
165
|
if (command) {
|
|
173
166
|
value.map((x) => {
|
|
174
167
|
const name = x.name.split(/-/);
|
|
175
168
|
name.pop();
|
|
176
|
-
if (name.join(
|
|
169
|
+
if (name.join('-') === id + '-' + command) {
|
|
177
170
|
cooldowns.push(x);
|
|
178
171
|
}
|
|
179
172
|
});
|
|
@@ -198,20 +191,14 @@ export class ClientUtil {
|
|
|
198
191
|
getCooldownTimers(id, command) {
|
|
199
192
|
let cooldowns = [];
|
|
200
193
|
for (const [key, value] of Object.entries(this.client.cache)) {
|
|
201
|
-
if (![
|
|
202
|
-
"cooldowns",
|
|
203
|
-
"messageCommands",
|
|
204
|
-
"slashCommands",
|
|
205
|
-
"contextCommands",
|
|
206
|
-
"commands",
|
|
207
|
-
].includes(key))
|
|
194
|
+
if (!['cooldowns', 'messageCommands', 'slashCommands', 'contextCommands', 'commands'].includes(key))
|
|
208
195
|
continue;
|
|
209
|
-
if (key ===
|
|
196
|
+
if (key === 'commands') {
|
|
210
197
|
if (command) {
|
|
211
198
|
value.map((x) => {
|
|
212
199
|
const name = x.name.split(/-/);
|
|
213
200
|
name.pop();
|
|
214
|
-
if (name.join(
|
|
201
|
+
if (name.join('-') === id + '-' + command) {
|
|
215
202
|
cooldowns.push({ [x.commandName]: x.endsAt - Date.now() });
|
|
216
203
|
}
|
|
217
204
|
});
|
|
@@ -231,9 +218,7 @@ export class ClientUtil {
|
|
|
231
218
|
}
|
|
232
219
|
}
|
|
233
220
|
}
|
|
234
|
-
const sort = cooldowns
|
|
235
|
-
.map((x) => Object.entries(x).shift())
|
|
236
|
-
.sort((a, b) => b[1] - a[1]);
|
|
221
|
+
const sort = cooldowns.map((x) => Object.entries(x).shift()).sort((a, b) => b[1] - a[1]);
|
|
237
222
|
cooldowns = [];
|
|
238
223
|
sort.map(([key, value]) => cooldowns.push({ [key]: value }));
|
|
239
224
|
return cooldowns;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, Interaction, Message, MessagePayload, StringSelectMenuBuilder } from
|
|
2
|
-
import XernerxClient from
|
|
3
|
-
import { XernerxMessage } from
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, EmbedBuilder, Interaction, Message, MessagePayload, StringSelectMenuBuilder } from 'discord.js';
|
|
2
|
+
import XernerxClient from '../client/XernerxClient.js';
|
|
3
|
+
import { XernerxMessage } from '../types/types.js';
|
|
4
4
|
interface SelectMenuOptions {
|
|
5
5
|
index?: EmbedBuilder;
|
|
6
6
|
row?: ActionRowBuilder;
|
|
@@ -32,7 +32,7 @@ export declare class MessageCommandUtil {
|
|
|
32
32
|
reply(content: MessagePayload | string): Promise<Message<boolean> | undefined>;
|
|
33
33
|
send(content: MessagePayload | string): Promise<Message<true> | Message<false> | undefined>;
|
|
34
34
|
defer(time: number): Promise<unknown>;
|
|
35
|
-
getCommands(): import("@discordjs/collection").Collection<string, import("../main.js").
|
|
35
|
+
getCommands(): import("@discordjs/collection").Collection<string, import("../main.js").MessageCommandBuilder>;
|
|
36
36
|
isOwner(): boolean;
|
|
37
37
|
}
|
|
38
38
|
export declare class InteractionCommandUtil {
|
|
@@ -42,7 +42,7 @@ export declare class InteractionCommandUtil {
|
|
|
42
42
|
constructor(client: XernerxClient, interaction: Interaction);
|
|
43
43
|
reply(content: MessagePayload | string): any;
|
|
44
44
|
defer(time: number): Promise<unknown>;
|
|
45
|
-
getCommands(): import("@discordjs/collection").Collection<string,
|
|
45
|
+
getCommands(): import("@discordjs/collection").Collection<string, import("../main.js").SlashCommandBuilder> | import("@discordjs/collection").Collection<string, import("../main.js").ContextCommandBuilder>;
|
|
46
46
|
selectMenuPaginator(embeds: Array<EmbedBuilder>, options?: SelectMenuOptions): void;
|
|
47
47
|
buttonPaginator(embeds: Array<EmbedBuilder>, options: ButtonOptions): void;
|
|
48
48
|
isOwner(): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, StringSelectMenuBuilder
|
|
2
|
-
import XernerxError from
|
|
1
|
+
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, StringSelectMenuBuilder } from 'discord.js';
|
|
2
|
+
import XernerxError from '../tools/XernerxError.js';
|
|
3
3
|
export class MessageCommandUtil {
|
|
4
4
|
client;
|
|
5
5
|
message;
|
|
@@ -13,8 +13,7 @@ export class MessageCommandUtil {
|
|
|
13
13
|
if (!existingMessage) {
|
|
14
14
|
const msg = await this.message.reply(content);
|
|
15
15
|
this.message.response = msg.id;
|
|
16
|
-
if (this.client.handlerOptions.message?.handleEdits ||
|
|
17
|
-
this.client.handlerOptions.message?.handleDeletes) {
|
|
16
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
18
17
|
this.client.cache.messages.set(this.message.id, this.message);
|
|
19
18
|
setInterval(() => {
|
|
20
19
|
this.client.cache.messages.delete(this.message.id);
|
|
@@ -31,8 +30,7 @@ export class MessageCommandUtil {
|
|
|
31
30
|
catch {
|
|
32
31
|
const msg = await this.message.reply(content);
|
|
33
32
|
this.message.response = msg.id;
|
|
34
|
-
if (this.client.handlerOptions.message?.handleEdits ||
|
|
35
|
-
this.client.handlerOptions.message?.handleDeletes) {
|
|
33
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
36
34
|
this.client.cache.messages.set(this.message.id, this.message);
|
|
37
35
|
setInterval(() => {
|
|
38
36
|
this.client.cache.messages.delete(this.message.id);
|
|
@@ -47,8 +45,7 @@ export class MessageCommandUtil {
|
|
|
47
45
|
if (!existingMessage) {
|
|
48
46
|
const msg = await this.message.channel.send(content);
|
|
49
47
|
this.message.response = msg.id;
|
|
50
|
-
if (this.client.handlerOptions.message?.handleEdits ||
|
|
51
|
-
this.client.handlerOptions.message?.handleDeletes) {
|
|
48
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
52
49
|
this.client.cache.messages.set(this.message.id, this.message);
|
|
53
50
|
setInterval(() => {
|
|
54
51
|
this.client.cache.messages.delete(this.message.id);
|
|
@@ -65,8 +62,7 @@ export class MessageCommandUtil {
|
|
|
65
62
|
catch {
|
|
66
63
|
const msg = await this.message.channel.send(content);
|
|
67
64
|
this.message.response = msg.id;
|
|
68
|
-
if (this.client.handlerOptions.message?.handleEdits ||
|
|
69
|
-
this.client.handlerOptions.message?.handleDeletes) {
|
|
65
|
+
if (this.client.handlerOptions.message?.handleEdits || this.client.handlerOptions.message?.handleDeletes) {
|
|
70
66
|
this.client.cache.messages.set(this.message.id, this.message);
|
|
71
67
|
setInterval(() => {
|
|
72
68
|
this.client.cache.messages.delete(this.message.id);
|
|
@@ -98,9 +94,7 @@ export class InteractionCommandUtil {
|
|
|
98
94
|
this.interaction = interaction;
|
|
99
95
|
}
|
|
100
96
|
reply(content) {
|
|
101
|
-
return this.interaction.replied || this.interaction.deferred
|
|
102
|
-
? this.interaction.editReply(content)
|
|
103
|
-
: this.interaction.reply(content);
|
|
97
|
+
return this.interaction.replied || this.interaction.deferred ? this.interaction.editReply(content) : this.interaction.reply(content);
|
|
104
98
|
}
|
|
105
99
|
async defer(time) {
|
|
106
100
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
@@ -117,17 +111,17 @@ export class InteractionCommandUtil {
|
|
|
117
111
|
throw new XernerxError(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
|
|
118
112
|
if (embeds.length > 25)
|
|
119
113
|
throw new XernerxError(`Max select menu length is 25.`);
|
|
120
|
-
if (typeof options !==
|
|
114
|
+
if (typeof options !== 'object')
|
|
121
115
|
options = {};
|
|
122
116
|
if (!Array.isArray(options.components))
|
|
123
117
|
options.components = [];
|
|
124
118
|
if (!options.index) {
|
|
125
|
-
options.index = new EmbedBuilder().setTitle(
|
|
119
|
+
options.index = new EmbedBuilder().setTitle('Index').setColor('Random');
|
|
126
120
|
for (const embed of embeds) {
|
|
127
121
|
options.index.addFields([
|
|
128
122
|
{
|
|
129
|
-
name: embed.data.title ||
|
|
130
|
-
value: embed.data.description ||
|
|
123
|
+
name: embed.data.title || 'No Name',
|
|
124
|
+
value: embed.data.description || 'Page',
|
|
131
125
|
inline: embeds.length > 25 / 2 ? true : false,
|
|
132
126
|
},
|
|
133
127
|
]);
|
|
@@ -137,15 +131,10 @@ export class InteractionCommandUtil {
|
|
|
137
131
|
options.row = new ActionRowBuilder();
|
|
138
132
|
if (!options.id)
|
|
139
133
|
options.id = `${this.interaction.id}-menu`;
|
|
140
|
-
options.component = new StringSelectMenuBuilder()
|
|
141
|
-
.setCustomId(options.id)
|
|
142
|
-
.setMaxValues(1)
|
|
143
|
-
.setMinValues(1)
|
|
144
|
-
.setPlaceholder("Select a page.")
|
|
145
|
-
.addOptions({ label: "index", value: "0" });
|
|
134
|
+
options.component = new StringSelectMenuBuilder().setCustomId(options.id).setMaxValues(1).setMinValues(1).setPlaceholder('Select a page.').addOptions({ label: 'index', value: '0' });
|
|
146
135
|
embeds.map((embed, i = 0) => {
|
|
147
136
|
options?.component?.addOptions({
|
|
148
|
-
label: embed.data.title ||
|
|
137
|
+
label: embed.data.title || 'No Name',
|
|
149
138
|
description: embed.data.description || `Page ${i}`,
|
|
150
139
|
value: String(i + 1),
|
|
151
140
|
});
|
|
@@ -158,24 +147,20 @@ export class InteractionCommandUtil {
|
|
|
158
147
|
components: [options.row, ...options.components],
|
|
159
148
|
ephemeral: !!options.ephemeral,
|
|
160
149
|
};
|
|
161
|
-
(options.reply === undefined || options.reply === true
|
|
162
|
-
? this.interaction.util.reply(content)
|
|
163
|
-
: this.interaction.channel.send(content)).then(() => {
|
|
150
|
+
(options.reply === undefined || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then(() => {
|
|
164
151
|
const collector = this.interaction.channel
|
|
165
152
|
.createMessageComponentCollector({
|
|
166
153
|
filter: options?.filter,
|
|
167
154
|
time: options?.time || 60000,
|
|
168
155
|
})
|
|
169
|
-
.on(
|
|
156
|
+
.on('collect', (interaction) => {
|
|
170
157
|
if (!interaction.customId.startsWith(this.interaction.id))
|
|
171
158
|
return;
|
|
172
159
|
interaction.update({
|
|
173
|
-
embeds: [
|
|
174
|
-
embeds[parseInt(interaction.values[0])],
|
|
175
|
-
],
|
|
160
|
+
embeds: [embeds[parseInt(interaction.values[0])]],
|
|
176
161
|
});
|
|
177
162
|
})
|
|
178
|
-
.on(
|
|
163
|
+
.on('end', () => {
|
|
179
164
|
this.interaction.editReply({ components: [] });
|
|
180
165
|
});
|
|
181
166
|
});
|
|
@@ -185,7 +170,7 @@ export class InteractionCommandUtil {
|
|
|
185
170
|
throw new XernerxError(`Expected embeds to be of type array, received ${typeof embeds} instead.`);
|
|
186
171
|
if (embeds.length <= 0)
|
|
187
172
|
throw new XernerxError(`The minimum embeds is 1.`);
|
|
188
|
-
if (typeof options !==
|
|
173
|
+
if (typeof options !== 'object')
|
|
189
174
|
options = {};
|
|
190
175
|
if (!Array.isArray(options.components))
|
|
191
176
|
options.components = [];
|
|
@@ -195,7 +180,7 @@ export class InteractionCommandUtil {
|
|
|
195
180
|
options.id = `${this.interaction.id}-menu`;
|
|
196
181
|
}
|
|
197
182
|
if (!options.buttons)
|
|
198
|
-
options.buttons = [
|
|
183
|
+
options.buttons = ['⏮️', '◀️', '⏹️', '▶️', '⏭️'];
|
|
199
184
|
for (const button of options.buttons) {
|
|
200
185
|
options.row.addComponents(new ButtonBuilder()
|
|
201
186
|
.setCustomId(`${this.interaction.id}-${options.buttons.indexOf(button)}`)
|
|
@@ -208,15 +193,13 @@ export class InteractionCommandUtil {
|
|
|
208
193
|
components: [options.row, ...options.components],
|
|
209
194
|
ephemeral: !!options.ephemeral,
|
|
210
195
|
};
|
|
211
|
-
(options.reply === undefined || options.reply === true
|
|
212
|
-
? this.interaction.util.reply(content)
|
|
213
|
-
: this.interaction.channel.send(content)).then((message) => {
|
|
196
|
+
(options.reply === undefined || options.reply === true ? this.interaction.util.reply(content) : this.interaction.channel.send(content)).then((message) => {
|
|
214
197
|
const collector = message.channel
|
|
215
198
|
.createMessageComponentCollector({
|
|
216
199
|
filter: options.filter,
|
|
217
200
|
time: options?.time || 60000,
|
|
218
201
|
})
|
|
219
|
-
.on(
|
|
202
|
+
.on('collect', (interaction) => {
|
|
220
203
|
let stop = false;
|
|
221
204
|
if (interaction.customId.startsWith(this.interaction.id)) {
|
|
222
205
|
switch (Number(interaction.customId.split(/-/).pop())) {
|
|
@@ -225,8 +208,7 @@ export class InteractionCommandUtil {
|
|
|
225
208
|
break;
|
|
226
209
|
}
|
|
227
210
|
case 1: {
|
|
228
|
-
embed =
|
|
229
|
-
embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
|
|
211
|
+
embed = embeds[embeds.indexOf(embed) >= 1 ? embeds.indexOf(embed) - 1 : 0];
|
|
230
212
|
break;
|
|
231
213
|
}
|
|
232
214
|
case 2: {
|
|
@@ -235,10 +217,7 @@ export class InteractionCommandUtil {
|
|
|
235
217
|
break;
|
|
236
218
|
}
|
|
237
219
|
case 3: {
|
|
238
|
-
embed =
|
|
239
|
-
embeds[embeds.indexOf(embed) < embeds.length - 1
|
|
240
|
-
? embeds.indexOf(embed) + 1
|
|
241
|
-
: embeds.length - 1];
|
|
220
|
+
embed = embeds[embeds.indexOf(embed) < embeds.length - 1 ? embeds.indexOf(embed) + 1 : embeds.length - 1];
|
|
242
221
|
break;
|
|
243
222
|
}
|
|
244
223
|
case 4: {
|
|
@@ -256,7 +235,7 @@ export class InteractionCommandUtil {
|
|
|
256
235
|
});
|
|
257
236
|
}
|
|
258
237
|
})
|
|
259
|
-
.on(
|
|
238
|
+
.on('end', () => {
|
|
260
239
|
this.interaction.editReply({ components: [] });
|
|
261
240
|
});
|
|
262
241
|
});
|