gralonium 0.3.0 → 0.4.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/lib/classes/Client.d.ts +9 -3
- package/lib/classes/Client.js +2 -2
- package/lib/classes/Context.d.ts +42 -1
- package/lib/classes/Context.js +276 -13
- package/lib/classes/Cooldowns.d.ts +2 -0
- package/lib/classes/Cooldowns.js +28 -0
- package/lib/classes/HelpCommand.d.ts +55 -13
- package/lib/classes/HelpCommand.js +319 -1
- package/lib/classes/Loader.d.ts +10 -1
- package/lib/classes/Loader.js +143 -58
- package/lib/classes/Plugins.js +3 -2
- package/lib/classes/Utils.d.ts +1 -1
- package/lib/classes/Utils.js +103 -24
- package/lib/classes/builders/CommandBuilder.d.ts +24 -0
- package/lib/classes/builders/CommandBuilder.js +66 -2
- package/lib/classes/builders/ComponentsV2Builder.d.ts +288 -113
- package/lib/classes/builders/ComponentsV2Builder.js +1071 -180
- package/lib/classes/builders/GroupBuilder.d.ts +20 -0
- package/lib/classes/builders/GroupBuilder.js +37 -1
- package/lib/classes/builders/InteractionBuilder.d.ts +86 -25
- package/lib/classes/builders/InteractionBuilder.js +212 -1
- package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
- package/lib/classes/builders/ParamsBuilder.js +167 -1
- package/lib/classes/builders/components/StyleMapper.d.ts +14 -2
- package/lib/classes/builders/components/StyleMapper.js +35 -9
- package/lib/classes/builders/components/helpers.d.ts +68 -4
- package/lib/classes/builders/components/helpers.js +366 -7
- package/lib/classes/builders/components/templates.d.ts +151 -9
- package/lib/classes/builders/components/templates.js +376 -17
- package/lib/classes/builders/components/text.d.ts +24 -0
- package/lib/classes/builders/components/text.js +91 -0
- package/lib/classes/experiments/Confirmator.d.ts +44 -26
- package/lib/classes/experiments/Confirmator.js +37 -21
- package/lib/classes/experiments/Paginator.d.ts +48 -29
- package/lib/classes/experiments/Paginator.js +48 -19
- package/lib/classes/views/V2Paginator.d.ts +91 -0
- package/lib/classes/views/V2Paginator.js +268 -0
- package/lib/classes/views/V2View.d.ts +113 -0
- package/lib/classes/views/V2View.js +438 -0
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +9 -1
- package/lib/main.d.ts +3 -0
- package/lib/main.js +3 -0
- package/package.json +3 -1
package/lib/classes/Client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client, ClientOptions, CommandInteraction, Message, Snowflake } from "discord.js";
|
|
2
2
|
import { Context } from "./Context.js";
|
|
3
|
-
import { Loader, Plugin } from "./Loader.js";
|
|
4
|
-
import { HelpCommand } from "./HelpCommand.js";
|
|
3
|
+
import { CommandLocalizer, Loader, Plugin } from "./Loader.js";
|
|
4
|
+
import { HelpCommand, HelpCommandOptions } from "./HelpCommand.js";
|
|
5
5
|
import { Cooldowns } from "./Cooldowns.js";
|
|
6
6
|
|
|
7
7
|
export interface GraloniumRestrictions {
|
|
@@ -18,11 +18,17 @@ export interface GraloniumOptions extends ClientOptions {
|
|
|
18
18
|
owners?: Snowflake[];
|
|
19
19
|
prefix: string | string[] | ((ctx: Context) => MaybePromise<string | string[]>);
|
|
20
20
|
replyOnEdit?: boolean;
|
|
21
|
+
replyOnPrefix?: boolean;
|
|
21
22
|
helpCommand?: typeof HelpCommand;
|
|
23
|
+
helpCommandOptions?: HelpCommandOptions;
|
|
22
24
|
restrictions?: GraloniumRestrictions;
|
|
23
25
|
debug?: boolean;
|
|
24
26
|
bindProcessHandlers?: boolean;
|
|
25
27
|
retryOnRateLimit?: boolean;
|
|
28
|
+
defaultLocale?: string;
|
|
29
|
+
localizeCommand?: CommandLocalizer;
|
|
30
|
+
beforeExecute?: (ctx: Context, command: any, options: any) => boolean | void | Promise<boolean | void>;
|
|
31
|
+
afterExecute?: (ctx: Context, command: any, options: any) => void | Promise<void>;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
export declare class Gralonium extends Client {
|
|
@@ -33,7 +39,7 @@ export declare class Gralonium extends Client {
|
|
|
33
39
|
addGlobalPlugins(plugins: Plugin[]): this;
|
|
34
40
|
getContext(data: CommandInteraction | Message): Context;
|
|
35
41
|
load(dir: string, reload?: boolean): Promise<import("./Loader.js").ModuleData<import("./builders/InteractionBuilder.js").InteractionBuilder | import("./builders/CommandBuilder.js").CommandBuilder | import("./builders/EventBuilder.js").EventBuilder | import("./builders/GroupBuilder.js").GroupBuilder, any[]>[]>;
|
|
36
|
-
sync(guildIDs?: string[]): Promise<
|
|
42
|
+
sync(guildIDs?: string[]): Promise<Record<string, any>[]>;
|
|
37
43
|
handleFrameworkError(error: unknown, ctx?: Context | null): void;
|
|
38
44
|
login(token: string): Promise<string>;
|
|
39
45
|
destroy(): this;
|
package/lib/classes/Client.js
CHANGED
|
@@ -52,7 +52,7 @@ class Gralonium extends discord_js_1.Client {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
async sync(guildIDs) {
|
|
55
|
-
|
|
55
|
+
return this.loader.sync(guildIDs);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
#debug(message) {
|
|
@@ -121,7 +121,7 @@ class Gralonium extends discord_js_1.Client {
|
|
|
121
121
|
#registerHelpCommand() {
|
|
122
122
|
if (!this.ops.helpCommand) return;
|
|
123
123
|
|
|
124
|
-
const help = new this.ops.helpCommand();
|
|
124
|
+
const help = new this.ops.helpCommand(this.ops.helpCommandOptions);
|
|
125
125
|
if (!this.loader.commands.normal) this.loader.commands.normal = new discord_js_1.Collection();
|
|
126
126
|
|
|
127
127
|
this.loader.commands.normal.set("help", {
|
package/lib/classes/Context.d.ts
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
import { Command, Types } from "../classes/Loader.js";
|
|
2
2
|
import * as P from "./builders/ParamsBuilder.js";
|
|
3
|
+
import type { ColorResolvable, ComponentsV2Builder, V2BuiltPayload } from "./builders/ComponentsV2Builder.js";
|
|
3
4
|
import { Gralonium } from "./Client.js";
|
|
4
5
|
import * as DJS from "discord.js";
|
|
5
6
|
|
|
7
|
+
export type ContextPayload =
|
|
8
|
+
| string
|
|
9
|
+
| ComponentsV2Builder
|
|
10
|
+
| V2BuiltPayload
|
|
11
|
+
| DJS.MessagePayload
|
|
12
|
+
| DJS.MessageCreateOptions
|
|
13
|
+
| DJS.InteractionReplyOptions
|
|
14
|
+
| DJS.InteractionEditReplyOptions;
|
|
15
|
+
|
|
16
|
+
export interface ContextDeferOptions {
|
|
17
|
+
ephemeral?: boolean;
|
|
18
|
+
thinking?: boolean;
|
|
19
|
+
thinkingText?: string;
|
|
20
|
+
color?: ColorResolvable;
|
|
21
|
+
reply?: boolean;
|
|
22
|
+
typing?: boolean;
|
|
23
|
+
flags?: number;
|
|
24
|
+
allowedMentions?: DJS.MessageMentionOptions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ContextSendOptions {
|
|
28
|
+
ephemeral?: boolean;
|
|
29
|
+
suppressNotifications?: boolean;
|
|
30
|
+
safeMentions?: boolean;
|
|
31
|
+
allowedMentions?: DJS.MessageMentionOptions;
|
|
32
|
+
files?: DJS.BaseMessageOptions["files"];
|
|
33
|
+
reply?: boolean;
|
|
34
|
+
followUp?: boolean;
|
|
35
|
+
forceChannelSend?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
6
38
|
export declare class Context {
|
|
7
39
|
bot: Gralonium;
|
|
8
40
|
args: string[] | null;
|
|
@@ -16,10 +48,19 @@ export declare class Context {
|
|
|
16
48
|
get message(): DJS.Message | null;
|
|
17
49
|
get interaction(): DJS.CommandInteraction | null;
|
|
18
50
|
get author(): DJS.User;
|
|
51
|
+
get user(): DJS.User;
|
|
52
|
+
get isPrefix(): boolean;
|
|
53
|
+
get isInteraction(): boolean;
|
|
54
|
+
get isSlash(): boolean;
|
|
19
55
|
get channel(): DJS.TextBasedChannel | null;
|
|
20
56
|
get member(): DJS.GuildMember | DJS.APIInteractionGuildMember | null;
|
|
21
57
|
get guild(): DJS.Guild | null;
|
|
22
|
-
|
|
58
|
+
get locale(): DJS.Locale | string | null;
|
|
59
|
+
get guildLocale(): DJS.Locale | string | null;
|
|
60
|
+
defer(options?: ContextDeferOptions): Promise<DJS.Message<boolean> | DJS.InteractionResponse<boolean> | null>;
|
|
61
|
+
send(payload: ContextPayload, options?: ContextSendOptions): Promise<DJS.Message<boolean>>;
|
|
62
|
+
reply(payload: ContextPayload, options?: ContextSendOptions): Promise<DJS.Message<boolean>>;
|
|
63
|
+
ephemeral(payload: ContextPayload, options?: ContextSendOptions): Promise<DJS.Message<boolean>>;
|
|
23
64
|
react(...emojis: string[]): Promise<DJS.MessageReaction | undefined>;
|
|
24
65
|
get<T>(param: string): T | null;
|
|
25
66
|
}
|
package/lib/classes/Context.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.Context = void 0;
|
|
|
4
4
|
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const DJS = tslib_1.__importStar(require("discord.js"));
|
|
7
|
+
const ComponentsV2Builder_js_1 = require("./builders/ComponentsV2Builder.js");
|
|
8
|
+
const helpers_js_1 = require("./builders/components/helpers.js");
|
|
7
9
|
|
|
8
10
|
class Context {
|
|
9
11
|
bot;
|
|
@@ -14,6 +16,9 @@ class Context {
|
|
|
14
16
|
command;
|
|
15
17
|
parent = null;
|
|
16
18
|
params;
|
|
19
|
+
#prefixThinkingMessage = null;
|
|
20
|
+
#prefixThinkingIsV2 = false;
|
|
21
|
+
#deferredEphemeral = false;
|
|
17
22
|
|
|
18
23
|
constructor(bot, data) {
|
|
19
24
|
this.bot = bot;
|
|
@@ -35,6 +40,25 @@ class Context {
|
|
|
35
40
|
return this.data instanceof DJS.Message ? this.data.author : this.data.user;
|
|
36
41
|
}
|
|
37
42
|
|
|
43
|
+
get user() {
|
|
44
|
+
return this.author;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
get isPrefix() {
|
|
48
|
+
return this.data instanceof DJS.Message;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get isInteraction() {
|
|
52
|
+
return !(this.data instanceof DJS.Message);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get isSlash() {
|
|
56
|
+
return (
|
|
57
|
+
!(this.data instanceof DJS.Message) &&
|
|
58
|
+
(typeof this.data.isChatInputCommand !== "function" || this.data.isChatInputCommand())
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
38
62
|
get channel() {
|
|
39
63
|
return this.data.channel || null;
|
|
40
64
|
}
|
|
@@ -47,6 +71,14 @@ class Context {
|
|
|
47
71
|
return this.data.guild || null;
|
|
48
72
|
}
|
|
49
73
|
|
|
74
|
+
get locale() {
|
|
75
|
+
return this.data?.locale ?? null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get guildLocale() {
|
|
79
|
+
return this.data?.guildLocale ?? this.guild?.preferredLocale ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
50
82
|
static #isRateLimitError(error) {
|
|
51
83
|
if (!error) return false;
|
|
52
84
|
if (error?.code === 429) return true;
|
|
@@ -87,27 +119,242 @@ class Context {
|
|
|
87
119
|
}
|
|
88
120
|
}
|
|
89
121
|
|
|
90
|
-
|
|
122
|
+
static #detectV2Payload(payload) {
|
|
123
|
+
if (!payload || typeof payload !== "object") return false;
|
|
124
|
+
const v2Flag = DJS.MessageFlags?.IsComponentsV2;
|
|
125
|
+
if (v2Flag !== undefined) {
|
|
126
|
+
if (typeof payload.flags === "number" && (payload.flags & v2Flag) === v2Flag) return true;
|
|
127
|
+
if (typeof payload.flags?.has === "function" && payload.flags.has(v2Flag)) return true;
|
|
128
|
+
}
|
|
129
|
+
if (Array.isArray(payload.components)) {
|
|
130
|
+
return payload.components.some((c) => helpers_js_1.isV2ComponentType((c?.data ?? c)?.type));
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static #assertV2Compatibility(payload) {
|
|
136
|
+
const hasContent = payload.content !== undefined && payload.content !== null && payload.content !== "";
|
|
137
|
+
const hasEmbeds = Array.isArray(payload.embeds) && payload.embeds.length > 0;
|
|
138
|
+
const hasStickers = Array.isArray(payload.stickers) && payload.stickers.length > 0;
|
|
139
|
+
const hasPoll = payload.poll !== undefined && payload.poll !== null;
|
|
140
|
+
|
|
141
|
+
if (hasContent || hasEmbeds || hasStickers || hasPoll) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
"[Context] Payloads using MessageFlags.IsComponentsV2 cannot include content, embeds, stickers, or poll."
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
static #hasEphemeralFlag(payload) {
|
|
149
|
+
const eph = DJS.MessageFlags?.Ephemeral;
|
|
150
|
+
if (payload?.ephemeral) return true;
|
|
151
|
+
if (eph === undefined) return false;
|
|
152
|
+
if (typeof payload?.flags === "number" && (payload.flags & eph) === eph) return true;
|
|
153
|
+
if (typeof payload?.flags?.has === "function" && payload.flags.has(eph)) return true;
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static #stripEphemeralForMessage(payload) {
|
|
158
|
+
if (!payload || typeof payload !== "object" || payload instanceof DJS.MessagePayload) return;
|
|
159
|
+
if ("ephemeral" in payload) {
|
|
160
|
+
delete payload.ephemeral;
|
|
161
|
+
}
|
|
162
|
+
const eph = DJS.MessageFlags?.Ephemeral;
|
|
163
|
+
if (eph === undefined || payload.flags === undefined || payload.flags === null) return;
|
|
164
|
+
|
|
165
|
+
if (typeof payload.flags === "number") {
|
|
166
|
+
payload.flags = payload.flags & ~eph;
|
|
167
|
+
if (payload.flags === 0) delete payload.flags;
|
|
168
|
+
} else if (Array.isArray(payload.flags)) {
|
|
169
|
+
payload.flags = payload.flags.filter((f) => f !== eph && f !== "Ephemeral");
|
|
170
|
+
if (payload.flags.length === 0) delete payload.flags;
|
|
171
|
+
} else if (typeof payload.flags?.remove === "function") {
|
|
172
|
+
payload.flags = payload.flags.remove(eph);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
#normalizePayload(payload, options = {}) {
|
|
177
|
+
if (payload instanceof DJS.MessagePayload) {
|
|
178
|
+
return { normalized: payload, isV2: Context.#detectV2Payload(payload.options), wantsEphemeral: Boolean(options.ephemeral) };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let normalized;
|
|
182
|
+
if (ComponentsV2Builder_js_1.ComponentsV2Builder.isBuilder(payload)) {
|
|
183
|
+
normalized = payload.toPayload({
|
|
184
|
+
ephemeral: options.ephemeral,
|
|
185
|
+
suppressNotifications: options.suppressNotifications,
|
|
186
|
+
safeMentions: options.safeMentions,
|
|
187
|
+
allowedMentions: options.allowedMentions,
|
|
188
|
+
files: options.files,
|
|
189
|
+
});
|
|
190
|
+
} else if (typeof payload === "string") {
|
|
191
|
+
normalized = { content: payload };
|
|
192
|
+
} else if (payload && typeof payload === "object") {
|
|
193
|
+
normalized = { ...payload };
|
|
194
|
+
} else {
|
|
195
|
+
normalized = { content: String(payload ?? "") };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (options.allowedMentions !== undefined && normalized.allowedMentions === undefined) {
|
|
199
|
+
normalized.allowedMentions = options.allowedMentions;
|
|
200
|
+
}
|
|
201
|
+
if (options.files !== undefined && normalized.files === undefined) {
|
|
202
|
+
normalized.files = options.files;
|
|
203
|
+
}
|
|
204
|
+
if (options.ephemeral === true && DJS.MessageFlags?.Ephemeral !== undefined) {
|
|
205
|
+
if (typeof normalized.flags === "number") {
|
|
206
|
+
normalized.flags |= DJS.MessageFlags.Ephemeral;
|
|
207
|
+
} else if (normalized.flags === undefined) {
|
|
208
|
+
normalized.flags = DJS.MessageFlags.Ephemeral;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const isV2 = Context.#detectV2Payload(normalized);
|
|
213
|
+
if (isV2) {
|
|
214
|
+
if (typeof normalized.flags === "number") {
|
|
215
|
+
normalized.flags |= DJS.MessageFlags.IsComponentsV2;
|
|
216
|
+
} else if (normalized.flags === undefined) {
|
|
217
|
+
normalized.flags = DJS.MessageFlags.IsComponentsV2;
|
|
218
|
+
}
|
|
219
|
+
Context.#assertV2Compatibility(normalized);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const wantsEphemeral = Boolean(options.ephemeral || Context.#hasEphemeralFlag(normalized));
|
|
223
|
+
return { normalized, isV2, wantsEphemeral };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Defers the interaction reply (respecting `ephemeral`) or optionally sends a
|
|
228
|
+
* thinking placeholder in prefix command mode.
|
|
229
|
+
*/
|
|
230
|
+
async defer(options = {}) {
|
|
91
231
|
if (this.data instanceof DJS.Message) {
|
|
92
|
-
|
|
232
|
+
if (options.thinking) {
|
|
233
|
+
const placeholder = new ComponentsV2Builder_js_1.ComponentsV2Builder({
|
|
234
|
+
color: options.color ?? null,
|
|
235
|
+
}).addText(options.thinkingText || "⏳ Procesando...");
|
|
236
|
+
|
|
237
|
+
const sent = await this.send(placeholder, {
|
|
238
|
+
reply: options.reply,
|
|
239
|
+
allowedMentions: options.allowedMentions,
|
|
240
|
+
});
|
|
241
|
+
this.#prefixThinkingMessage = sent || null;
|
|
242
|
+
this.#prefixThinkingIsV2 = true;
|
|
243
|
+
return this.#prefixThinkingMessage;
|
|
244
|
+
}
|
|
245
|
+
if (options.typing !== false) {
|
|
246
|
+
await this.data.channel?.sendTyping?.().catch(() => null);
|
|
247
|
+
}
|
|
248
|
+
return null;
|
|
93
249
|
}
|
|
94
250
|
|
|
95
251
|
if (this.data.isAutocomplete?.()) {
|
|
96
|
-
throw new Error("Autocomplete interactions cannot
|
|
252
|
+
throw new Error("Autocomplete interactions cannot be deferred.");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (this.data.deferred || this.data.replied) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
let flags = typeof options.flags === "number" ? options.flags : 0;
|
|
260
|
+
if (options.ephemeral && DJS.MessageFlags?.Ephemeral !== undefined) {
|
|
261
|
+
flags |= DJS.MessageFlags.Ephemeral;
|
|
97
262
|
}
|
|
98
263
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
264
|
+
this.#deferredEphemeral = Boolean(
|
|
265
|
+
options.ephemeral || (DJS.MessageFlags?.Ephemeral !== undefined && (flags & DJS.MessageFlags.Ephemeral) !== 0)
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
const deferOptions = flags ? { flags } : {};
|
|
269
|
+
return this.#sendWithOptionalRetry(() => this.data.deferReply(deferOptions));
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Sends a reply in both prefix (`Message`) and slash/interaction modes.
|
|
274
|
+
* Accepts strings, message option objects, or `ComponentsV2Builder` instances.
|
|
275
|
+
*/
|
|
276
|
+
async send(payload, options = {}) {
|
|
277
|
+
const { normalized, isV2, wantsEphemeral } = this.#normalizePayload(payload, options);
|
|
278
|
+
|
|
279
|
+
if (this.data instanceof DJS.Message) {
|
|
280
|
+
Context.#stripEphemeralForMessage(normalized);
|
|
281
|
+
|
|
282
|
+
if (this.#prefixThinkingMessage) {
|
|
283
|
+
const thinkingMsg = this.#prefixThinkingMessage;
|
|
284
|
+
const thinkingWasV2 = this.#prefixThinkingIsV2;
|
|
285
|
+
this.#prefixThinkingMessage = null;
|
|
286
|
+
this.#prefixThinkingIsV2 = false;
|
|
287
|
+
|
|
288
|
+
const hasPoll = Boolean(normalized && typeof normalized === "object" && normalized.poll !== undefined);
|
|
289
|
+
if (thinkingWasV2 === isV2 && !hasPoll && typeof thinkingMsg.edit === "function") {
|
|
290
|
+
const editData = normalized instanceof DJS.MessagePayload ? normalized : { ...normalized };
|
|
291
|
+
if (editData && typeof editData === "object" && "reply" in editData) {
|
|
292
|
+
delete editData.reply;
|
|
293
|
+
}
|
|
294
|
+
try {
|
|
295
|
+
return await this.#sendWithOptionalRetry(() => thinkingMsg.edit(editData));
|
|
296
|
+
} catch {
|
|
297
|
+
// Fall through to sending a fresh message if placeholder can no longer be edited.
|
|
298
|
+
}
|
|
299
|
+
} else if (typeof thinkingMsg.delete === "function") {
|
|
300
|
+
await thinkingMsg.delete().catch(() => null);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const shouldReply = Boolean(options.reply ?? normalized?.reply ?? this.bot?.ops?.replyOnPrefix);
|
|
305
|
+
if (shouldReply && !(normalized instanceof DJS.MessagePayload)) {
|
|
306
|
+
if (!normalized.reply && this.data.id) {
|
|
307
|
+
normalized.reply = { messageReference: this.data.id, failIfNotExists: false };
|
|
308
|
+
}
|
|
309
|
+
if (normalized.allowedMentions === undefined) {
|
|
310
|
+
normalized.allowedMentions = { parse: [], repliedUser: false };
|
|
311
|
+
}
|
|
312
|
+
if (typeof this.data.reply === "function" && !options.forceChannelSend) {
|
|
313
|
+
const replyObj = { ...normalized };
|
|
314
|
+
delete replyObj.reply;
|
|
315
|
+
return this.#sendWithOptionalRetry(() => this.data.reply(replyObj));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return this.#sendWithOptionalRetry(() => this.data.channel.send(normalized));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (this.data.isAutocomplete?.()) {
|
|
323
|
+
throw new Error("Autocomplete interactions cannot send message replies. Use interaction.respond() instead.");
|
|
324
|
+
}
|
|
105
325
|
|
|
106
326
|
if (this.data.deferred || this.data.replied) {
|
|
107
|
-
|
|
327
|
+
const wasPublicDefer = !this.#deferredEphemeral && !this.data.ephemeral;
|
|
328
|
+
if (wantsEphemeral && wasPublicDefer) {
|
|
329
|
+
if (this.data.deferred && !this.data.replied && typeof this.data.deleteReply === "function") {
|
|
330
|
+
await this.data.deleteReply().catch(() => null);
|
|
331
|
+
}
|
|
332
|
+
return this.#sendWithOptionalRetry(() => this.data.followUp(normalized));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (options.followUp) {
|
|
336
|
+
return this.#sendWithOptionalRetry(() => this.data.followUp(normalized));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
return this.#sendWithOptionalRetry(() => this.data.editReply(normalized));
|
|
108
340
|
}
|
|
109
341
|
|
|
110
|
-
return this.#sendWithOptionalRetry(() => this.data.reply(
|
|
342
|
+
return this.#sendWithOptionalRetry(() => this.data.reply(normalized));
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Sends a message quoting the invoking message when in prefix mode.
|
|
347
|
+
*/
|
|
348
|
+
async reply(payload, options = {}) {
|
|
349
|
+
return this.send(payload, { ...options, reply: true });
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Sends an ephemeral message on interactions, automatically stripping the
|
|
354
|
+
* Ephemeral flag when executed from a prefix message command.
|
|
355
|
+
*/
|
|
356
|
+
async ephemeral(payload, options = {}) {
|
|
357
|
+
return this.send(payload, { ...options, ephemeral: true });
|
|
111
358
|
}
|
|
112
359
|
|
|
113
360
|
async react(...emojis) {
|
|
@@ -125,12 +372,28 @@ class Context {
|
|
|
125
372
|
const lowered = param.toLowerCase();
|
|
126
373
|
|
|
127
374
|
if (this.params?.length) {
|
|
128
|
-
|
|
375
|
+
const match = this.params.find((entry) => entry?.name?.toLowerCase() === lowered);
|
|
376
|
+
if (match) return match.value ?? null;
|
|
129
377
|
}
|
|
130
378
|
|
|
131
379
|
if (this.data instanceof DJS.Message) return null;
|
|
132
380
|
|
|
133
|
-
const
|
|
381
|
+
const findOption = (entries) => {
|
|
382
|
+
if (!Array.isArray(entries)) return null;
|
|
383
|
+
for (const entry of entries) {
|
|
384
|
+
if ((entry?.type === 1 || entry?.type === 2) && Array.isArray(entry.options)) {
|
|
385
|
+
const nested = findOption(entry.options);
|
|
386
|
+
if (nested) return nested;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (typeof entry?.name === "string" && entry.name.toLowerCase() === lowered) {
|
|
390
|
+
return entry;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return null;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const option = findOption(this.data.options?.data) ?? this.data.options?.get?.(param) ?? null;
|
|
134
397
|
if (!option) return null;
|
|
135
398
|
|
|
136
399
|
return option.attachment ?? option.member ?? option.channel ?? option.role ?? option.user ?? option.value ?? null;
|
|
@@ -13,6 +13,8 @@ export declare class Cooldowns {
|
|
|
13
13
|
expiresAt: number;
|
|
14
14
|
}>;
|
|
15
15
|
constructor(bot: Gralonium);
|
|
16
|
+
static resolveKey(command: unknown, group?: unknown): string;
|
|
17
|
+
sweep(now?: number): number;
|
|
16
18
|
getCooldownSource(command: string, id: string, bucket: Bucket): Promise<number | undefined>;
|
|
17
19
|
setCooldownSource(command: string, id: string, bucket: Bucket, time: number): Promise<void>;
|
|
18
20
|
check(command: string, id: string, cooldown: number, bucket: Bucket): Promise<{
|
package/lib/classes/Cooldowns.js
CHANGED
|
@@ -23,6 +23,30 @@ class Cooldowns {
|
|
|
23
23
|
return `${command}#${bucket}#${id}`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
static resolveKey(command, group = null) {
|
|
27
|
+
const commandName =
|
|
28
|
+
typeof command === "string"
|
|
29
|
+
? command
|
|
30
|
+
: command?.data?.name || command?.name || "unknown";
|
|
31
|
+
const groupName =
|
|
32
|
+
typeof group === "string"
|
|
33
|
+
? group
|
|
34
|
+
: group?.data?.name || group?.name || "";
|
|
35
|
+
|
|
36
|
+
return groupName ? `${groupName}:${commandName}` : commandName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
sweep(now = Date.now()) {
|
|
40
|
+
let cleared = 0;
|
|
41
|
+
for (const [key, entry] of this.track.entries()) {
|
|
42
|
+
if (!entry || now >= entry.expiresAt) {
|
|
43
|
+
this.track.delete(key);
|
|
44
|
+
cleared += 1;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return cleared;
|
|
48
|
+
}
|
|
49
|
+
|
|
26
50
|
async getCooldownSource(command, id, bucket) {
|
|
27
51
|
const key = this.#key(command, id, bucket);
|
|
28
52
|
const tracked = this.track.get(key);
|
|
@@ -38,6 +62,10 @@ class Cooldowns {
|
|
|
38
62
|
|
|
39
63
|
async setCooldownSource(command, id, bucket, time) {
|
|
40
64
|
const now = Date.now();
|
|
65
|
+
if (this.track.size >= 500) {
|
|
66
|
+
this.sweep(now);
|
|
67
|
+
}
|
|
68
|
+
|
|
41
69
|
this.track.set(this.#key(command, id, bucket), {
|
|
42
70
|
startedAt: now,
|
|
43
71
|
expiresAt: now + time,
|
|
@@ -1,15 +1,57 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EmbedBuilder } from "discord.js";
|
|
2
|
+
import type { ColorResolvable } from "./builders/ComponentsV2Builder.js";
|
|
3
|
+
import type { CommandBuilder } from "./builders/CommandBuilder.js";
|
|
4
|
+
import type { ParamsBuilder } from "./builders/ParamsBuilder.js";
|
|
5
|
+
import type { Context } from "./Context.js";
|
|
6
|
+
import type { CommandHelpingObject, GroupHelpingObject, Plugin } from "./Loader.js";
|
|
7
|
+
import type { V2ViewThirdPartyMode } from "./views/V2View.js";
|
|
8
|
+
|
|
9
|
+
export interface HelpCommandLabels {
|
|
10
|
+
welcomeTitle?: string;
|
|
11
|
+
welcomeDescription?: string;
|
|
12
|
+
notFound?: string;
|
|
13
|
+
usage?: string;
|
|
14
|
+
arguments?: string;
|
|
15
|
+
noArguments?: string;
|
|
16
|
+
subcommands?: string;
|
|
17
|
+
noSubcommands?: string;
|
|
18
|
+
commandsHeader?: string;
|
|
19
|
+
footerSuffix?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface HelpCommandOptions {
|
|
23
|
+
useV2?: boolean;
|
|
24
|
+
color?: ColorResolvable;
|
|
25
|
+
errorColor?: ColorResolvable;
|
|
26
|
+
ephemeral?: boolean;
|
|
27
|
+
paginated?: boolean;
|
|
28
|
+
perPage?: number;
|
|
29
|
+
thirdPartyMode?: V2ViewThirdPartyMode;
|
|
30
|
+
closeButton?: boolean | { label?: string; style?: any };
|
|
31
|
+
name?: string;
|
|
32
|
+
aliases?: string[];
|
|
33
|
+
description?: string;
|
|
34
|
+
queryDescription?: string;
|
|
35
|
+
plugins?: Plugin[];
|
|
36
|
+
hiddenCommands?: string[];
|
|
37
|
+
filterCommand?: (command: CommandHelpingObject, ctx: Context) => boolean;
|
|
38
|
+
labels?: HelpCommandLabels;
|
|
39
|
+
}
|
|
40
|
+
|
|
2
41
|
export declare class HelpCommand {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
42
|
+
options: HelpCommandOptions;
|
|
43
|
+
labels: Required<HelpCommandLabels>;
|
|
44
|
+
data: CommandBuilder;
|
|
45
|
+
plugins: Plugin[];
|
|
46
|
+
params: ParamsBuilder;
|
|
47
|
+
constructor(options?: HelpCommandOptions);
|
|
48
|
+
code(ctx: Context): Promise<void>;
|
|
49
|
+
sendEmpty(ctx: Context): Promise<void>;
|
|
50
|
+
sendNotFound(ctx: Context): Promise<void>;
|
|
51
|
+
sendCommand(ctx: Context, command: CommandHelpingObject): Promise<void>;
|
|
52
|
+
sendGroup(ctx: Context, group: GroupHelpingObject): Promise<void>;
|
|
53
|
+
getCommand(ctx: Context, q: string): CommandHelpingObject | null;
|
|
54
|
+
getGroup(ctx: Context, q: string): GroupHelpingObject | null;
|
|
55
|
+
protected doEmbed(ctx: Context): EmbedBuilder;
|
|
56
|
+
protected c(str: string): string;
|
|
15
57
|
}
|