gralonium 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/classes/Client.d.ts +9 -11
- package/lib/classes/Client.js +10 -13
- package/lib/classes/Context.d.ts +43 -4
- package/lib/classes/Context.js +251 -12
- package/lib/classes/Cooldowns.d.ts +3 -3
- package/lib/classes/Cooldowns.js +3 -8
- package/lib/classes/HelpCommand.d.ts +55 -13
- package/lib/classes/HelpCommand.js +319 -1
- package/lib/classes/Loader.d.ts +17 -11
- package/lib/classes/Loader.js +43 -42
- package/lib/classes/Utils.d.ts +4 -5
- package/lib/classes/Utils.js +32 -21
- package/lib/classes/builders/CommandBuilder.d.ts +10 -0
- package/lib/classes/builders/CommandBuilder.js +16 -0
- package/lib/classes/builders/ComponentsV2Builder.d.ts +285 -113
- package/lib/classes/builders/ComponentsV2Builder.js +1069 -182
- package/lib/classes/builders/GroupBuilder.d.ts +9 -0
- package/lib/classes/builders/GroupBuilder.js +16 -0
- package/lib/classes/builders/InteractionBuilder.d.ts +40 -25
- package/lib/classes/builders/InteractionBuilder.js +102 -1
- package/lib/classes/builders/components/StyleMapper.d.ts +1 -1
- package/lib/classes/builders/components/StyleMapper.js +2 -1
- 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 +45 -50
- package/lib/classes/experiments/Confirmator.js +37 -21
- package/lib/classes/experiments/Paginator.d.ts +49 -56
- 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 -3
- package/lib/main.js +5 -5
- package/package.json +6 -15
- package/lib/events/interactionCreate.d.ts +0 -4
- package/lib/events/interactionCreate.js +0 -17
- package/lib/events/messageCreate.d.ts +0 -4
- package/lib/events/messageCreate.js +0 -17
- package/lib/events/messageUpdate.d.ts +0 -4
- package/lib/events/messageUpdate.js +0 -17
package/lib/classes/Client.d.ts
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import { Client, ClientOptions, CommandInteraction, Message, Snowflake } from "discord.js";
|
|
2
2
|
import { Context } from "./Context.js";
|
|
3
3
|
import { Loader, Plugin } from "./Loader.js";
|
|
4
|
-
import { HelpCommand } from "./HelpCommand.js";
|
|
4
|
+
import { HelpCommand, HelpCommandOptions } from "./HelpCommand.js";
|
|
5
5
|
import { Cooldowns } from "./Cooldowns.js";
|
|
6
6
|
|
|
7
|
-
export interface
|
|
7
|
+
export interface GraloniumRestrictions {
|
|
8
8
|
userIDs: Set<Snowflake>;
|
|
9
9
|
guildIDs: Set<Snowflake>;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
type MaybePromise<T> = T | Promise<T>;
|
|
13
13
|
|
|
14
|
-
export interface
|
|
14
|
+
export interface GraloniumOptions extends ClientOptions {
|
|
15
15
|
autoSync?: boolean;
|
|
16
16
|
context?: typeof Context;
|
|
17
17
|
guildOnly?: boolean;
|
|
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;
|
|
22
|
-
|
|
23
|
+
helpCommandOptions?: HelpCommandOptions;
|
|
24
|
+
restrictions?: GraloniumRestrictions;
|
|
23
25
|
debug?: boolean;
|
|
24
26
|
bindProcessHandlers?: boolean;
|
|
25
27
|
retryOnRateLimit?: boolean;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export declare class
|
|
30
|
+
export declare class Gralonium extends Client {
|
|
29
31
|
cooldowns: Cooldowns;
|
|
30
32
|
loader: Loader;
|
|
31
|
-
ops:
|
|
32
|
-
constructor(options:
|
|
33
|
+
ops: GraloniumOptions;
|
|
34
|
+
constructor(options: GraloniumOptions);
|
|
33
35
|
addGlobalPlugins(plugins: Plugin[]): this;
|
|
34
36
|
getContext(data: CommandInteraction | Message): Context;
|
|
35
37
|
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[]>[]>;
|
|
@@ -38,7 +40,3 @@ export declare class RedBot extends Client {
|
|
|
38
40
|
login(token: string): Promise<string>;
|
|
39
41
|
destroy(): this;
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
export { RedBot as Enire };
|
|
43
|
-
export { RedBot as Erine };
|
|
44
|
-
export { RedBot as Gralonium };
|
package/lib/classes/Client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Gralonium =
|
|
3
|
+
exports.Gralonium = void 0;
|
|
4
4
|
|
|
5
5
|
const discord_js_1 = require("discord.js");
|
|
6
6
|
const Context_js_1 = require("./Context.js");
|
|
@@ -8,7 +8,7 @@ const Loader_js_1 = require("./Loader.js");
|
|
|
8
8
|
const Cooldowns_js_1 = require("./Cooldowns.js");
|
|
9
9
|
const Utils_js_1 = require("./Utils.js");
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class Gralonium extends discord_js_1.Client {
|
|
12
12
|
static #processHandlersBound = false;
|
|
13
13
|
static #boundClients = new Set();
|
|
14
14
|
|
|
@@ -104,10 +104,10 @@ class RedBot extends discord_js_1.Client {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
static #bindProcessHandlers() {
|
|
107
|
-
if (
|
|
107
|
+
if (Gralonium.#processHandlersBound) return;
|
|
108
108
|
|
|
109
109
|
const dispatch = (error) => {
|
|
110
|
-
for (const client of
|
|
110
|
+
for (const client of Gralonium.#boundClients) {
|
|
111
111
|
client.handleFrameworkError(error);
|
|
112
112
|
}
|
|
113
113
|
};
|
|
@@ -115,13 +115,13 @@ class RedBot extends discord_js_1.Client {
|
|
|
115
115
|
process.on("uncaughtException", dispatch);
|
|
116
116
|
process.on("unhandledRejection", dispatch);
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
Gralonium.#processHandlersBound = true;
|
|
119
119
|
}
|
|
120
120
|
|
|
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", {
|
|
@@ -134,8 +134,8 @@ class RedBot extends discord_js_1.Client {
|
|
|
134
134
|
|
|
135
135
|
async login(token) {
|
|
136
136
|
if (this.ops.bindProcessHandlers !== false) {
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
Gralonium.#bindProcessHandlers();
|
|
138
|
+
Gralonium.#boundClients.add(this);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
this.#bindCoreListeners();
|
|
@@ -151,12 +151,9 @@ class RedBot extends discord_js_1.Client {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
destroy() {
|
|
154
|
-
|
|
154
|
+
Gralonium.#boundClients.delete(this);
|
|
155
155
|
return super.destroy();
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
exports.
|
|
160
|
-
exports.Enire = RedBot;
|
|
161
|
-
exports.Erine = RedBot;
|
|
162
|
-
exports.Gralonium = RedBot;
|
|
159
|
+
exports.Gralonium = Gralonium;
|
package/lib/classes/Context.d.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
import { Command, Types } from "../classes/Loader.js";
|
|
2
2
|
import * as P from "./builders/ParamsBuilder.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { ColorResolvable, ComponentsV2Builder, V2BuiltPayload } from "./builders/ComponentsV2Builder.js";
|
|
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
|
-
bot:
|
|
39
|
+
bot: Gralonium;
|
|
8
40
|
args: string[] | null;
|
|
9
41
|
data: DJS.Message | DJS.CommandInteraction;
|
|
10
42
|
prefix: string;
|
|
@@ -12,14 +44,21 @@ export declare class Context {
|
|
|
12
44
|
command: Command<Types.Normal> | null;
|
|
13
45
|
parent: Command<Types.Group> | null;
|
|
14
46
|
params: P.BaseParam[] | null;
|
|
15
|
-
constructor(bot:
|
|
47
|
+
constructor(bot: Gralonium, data: DJS.Message | DJS.CommandInteraction);
|
|
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
|
+
defer(options?: ContextDeferOptions): Promise<DJS.Message<boolean> | DJS.InteractionResponse<boolean> | null>;
|
|
59
|
+
send(payload: ContextPayload, options?: ContextSendOptions): Promise<DJS.Message<boolean>>;
|
|
60
|
+
reply(payload: ContextPayload, options?: ContextSendOptions): Promise<DJS.Message<boolean>>;
|
|
61
|
+
ephemeral(payload: ContextPayload, options?: ContextSendOptions): Promise<DJS.Message<boolean>>;
|
|
23
62
|
react(...emojis: string[]): Promise<DJS.MessageReaction | undefined>;
|
|
24
63
|
get<T>(param: string): T | null;
|
|
25
64
|
}
|
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,12 +16,15 @@ 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;
|
|
20
25
|
this.data = data;
|
|
21
26
|
this.command = null;
|
|
22
|
-
this.params =
|
|
27
|
+
this.params = [];
|
|
23
28
|
this.args = this.data instanceof DJS.Message ? [] : null;
|
|
24
29
|
}
|
|
25
30
|
|
|
@@ -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
|
}
|
|
@@ -87,27 +111,242 @@ class Context {
|
|
|
87
111
|
}
|
|
88
112
|
}
|
|
89
113
|
|
|
90
|
-
|
|
114
|
+
static #detectV2Payload(payload) {
|
|
115
|
+
if (!payload || typeof payload !== "object") return false;
|
|
116
|
+
const v2Flag = DJS.MessageFlags?.IsComponentsV2;
|
|
117
|
+
if (v2Flag !== undefined) {
|
|
118
|
+
if (typeof payload.flags === "number" && (payload.flags & v2Flag) === v2Flag) return true;
|
|
119
|
+
if (typeof payload.flags?.has === "function" && payload.flags.has(v2Flag)) return true;
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(payload.components)) {
|
|
122
|
+
return payload.components.some((c) => helpers_js_1.isV2ComponentType((c?.data ?? c)?.type));
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static #assertV2Compatibility(payload) {
|
|
128
|
+
const hasContent = payload.content !== undefined && payload.content !== null && payload.content !== "";
|
|
129
|
+
const hasEmbeds = Array.isArray(payload.embeds) && payload.embeds.length > 0;
|
|
130
|
+
const hasStickers = Array.isArray(payload.stickers) && payload.stickers.length > 0;
|
|
131
|
+
const hasPoll = payload.poll !== undefined && payload.poll !== null;
|
|
132
|
+
|
|
133
|
+
if (hasContent || hasEmbeds || hasStickers || hasPoll) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
"[Context] Payloads using MessageFlags.IsComponentsV2 cannot include content, embeds, stickers, or poll."
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static #hasEphemeralFlag(payload) {
|
|
141
|
+
const eph = DJS.MessageFlags?.Ephemeral;
|
|
142
|
+
if (payload?.ephemeral) return true;
|
|
143
|
+
if (eph === undefined) return false;
|
|
144
|
+
if (typeof payload?.flags === "number" && (payload.flags & eph) === eph) return true;
|
|
145
|
+
if (typeof payload?.flags?.has === "function" && payload.flags.has(eph)) return true;
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
static #stripEphemeralForMessage(payload) {
|
|
150
|
+
if (!payload || typeof payload !== "object" || payload instanceof DJS.MessagePayload) return;
|
|
151
|
+
if ("ephemeral" in payload) {
|
|
152
|
+
delete payload.ephemeral;
|
|
153
|
+
}
|
|
154
|
+
const eph = DJS.MessageFlags?.Ephemeral;
|
|
155
|
+
if (eph === undefined || payload.flags === undefined || payload.flags === null) return;
|
|
156
|
+
|
|
157
|
+
if (typeof payload.flags === "number") {
|
|
158
|
+
payload.flags = payload.flags & ~eph;
|
|
159
|
+
if (payload.flags === 0) delete payload.flags;
|
|
160
|
+
} else if (Array.isArray(payload.flags)) {
|
|
161
|
+
payload.flags = payload.flags.filter((f) => f !== eph && f !== "Ephemeral");
|
|
162
|
+
if (payload.flags.length === 0) delete payload.flags;
|
|
163
|
+
} else if (typeof payload.flags?.remove === "function") {
|
|
164
|
+
payload.flags = payload.flags.remove(eph);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
#normalizePayload(payload, options = {}) {
|
|
169
|
+
if (payload instanceof DJS.MessagePayload) {
|
|
170
|
+
return { normalized: payload, isV2: Context.#detectV2Payload(payload.options), wantsEphemeral: Boolean(options.ephemeral) };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
let normalized;
|
|
174
|
+
if (ComponentsV2Builder_js_1.ComponentsV2Builder.isBuilder(payload)) {
|
|
175
|
+
normalized = payload.toPayload({
|
|
176
|
+
ephemeral: options.ephemeral,
|
|
177
|
+
suppressNotifications: options.suppressNotifications,
|
|
178
|
+
safeMentions: options.safeMentions,
|
|
179
|
+
allowedMentions: options.allowedMentions,
|
|
180
|
+
files: options.files,
|
|
181
|
+
});
|
|
182
|
+
} else if (typeof payload === "string") {
|
|
183
|
+
normalized = { content: payload };
|
|
184
|
+
} else if (payload && typeof payload === "object") {
|
|
185
|
+
normalized = { ...payload };
|
|
186
|
+
} else {
|
|
187
|
+
normalized = { content: String(payload ?? "") };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (options.allowedMentions !== undefined && normalized.allowedMentions === undefined) {
|
|
191
|
+
normalized.allowedMentions = options.allowedMentions;
|
|
192
|
+
}
|
|
193
|
+
if (options.files !== undefined && normalized.files === undefined) {
|
|
194
|
+
normalized.files = options.files;
|
|
195
|
+
}
|
|
196
|
+
if (options.ephemeral === true && DJS.MessageFlags?.Ephemeral !== undefined) {
|
|
197
|
+
if (typeof normalized.flags === "number") {
|
|
198
|
+
normalized.flags |= DJS.MessageFlags.Ephemeral;
|
|
199
|
+
} else if (normalized.flags === undefined) {
|
|
200
|
+
normalized.flags = DJS.MessageFlags.Ephemeral;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const isV2 = Context.#detectV2Payload(normalized);
|
|
205
|
+
if (isV2) {
|
|
206
|
+
if (typeof normalized.flags === "number") {
|
|
207
|
+
normalized.flags |= DJS.MessageFlags.IsComponentsV2;
|
|
208
|
+
} else if (normalized.flags === undefined) {
|
|
209
|
+
normalized.flags = DJS.MessageFlags.IsComponentsV2;
|
|
210
|
+
}
|
|
211
|
+
Context.#assertV2Compatibility(normalized);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const wantsEphemeral = Boolean(options.ephemeral || Context.#hasEphemeralFlag(normalized));
|
|
215
|
+
return { normalized, isV2, wantsEphemeral };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Defers the interaction reply (respecting `ephemeral`) or optionally sends a
|
|
220
|
+
* thinking placeholder in prefix command mode.
|
|
221
|
+
*/
|
|
222
|
+
async defer(options = {}) {
|
|
91
223
|
if (this.data instanceof DJS.Message) {
|
|
92
|
-
|
|
224
|
+
if (options.thinking) {
|
|
225
|
+
const placeholder = new ComponentsV2Builder_js_1.ComponentsV2Builder({
|
|
226
|
+
color: options.color ?? null,
|
|
227
|
+
}).addText(options.thinkingText || "⏳ Procesando...");
|
|
228
|
+
|
|
229
|
+
const sent = await this.send(placeholder, {
|
|
230
|
+
reply: options.reply,
|
|
231
|
+
allowedMentions: options.allowedMentions,
|
|
232
|
+
});
|
|
233
|
+
this.#prefixThinkingMessage = sent || null;
|
|
234
|
+
this.#prefixThinkingIsV2 = true;
|
|
235
|
+
return this.#prefixThinkingMessage;
|
|
236
|
+
}
|
|
237
|
+
if (options.typing !== false) {
|
|
238
|
+
await this.data.channel?.sendTyping?.().catch(() => null);
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
93
241
|
}
|
|
94
242
|
|
|
95
243
|
if (this.data.isAutocomplete?.()) {
|
|
96
|
-
throw new Error("Autocomplete interactions cannot
|
|
244
|
+
throw new Error("Autocomplete interactions cannot be deferred.");
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (this.data.deferred || this.data.replied) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let flags = typeof options.flags === "number" ? options.flags : 0;
|
|
252
|
+
if (options.ephemeral && DJS.MessageFlags?.Ephemeral !== undefined) {
|
|
253
|
+
flags |= DJS.MessageFlags.Ephemeral;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
this.#deferredEphemeral = Boolean(
|
|
257
|
+
options.ephemeral || (DJS.MessageFlags?.Ephemeral !== undefined && (flags & DJS.MessageFlags.Ephemeral) !== 0)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const deferOptions = flags ? { flags } : {};
|
|
261
|
+
return this.#sendWithOptionalRetry(() => this.data.deferReply(deferOptions));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Sends a reply in both prefix (`Message`) and slash/interaction modes.
|
|
266
|
+
* Accepts strings, message option objects, or `ComponentsV2Builder` instances.
|
|
267
|
+
*/
|
|
268
|
+
async send(payload, options = {}) {
|
|
269
|
+
const { normalized, isV2, wantsEphemeral } = this.#normalizePayload(payload, options);
|
|
270
|
+
|
|
271
|
+
if (this.data instanceof DJS.Message) {
|
|
272
|
+
Context.#stripEphemeralForMessage(normalized);
|
|
273
|
+
|
|
274
|
+
if (this.#prefixThinkingMessage) {
|
|
275
|
+
const thinkingMsg = this.#prefixThinkingMessage;
|
|
276
|
+
const thinkingWasV2 = this.#prefixThinkingIsV2;
|
|
277
|
+
this.#prefixThinkingMessage = null;
|
|
278
|
+
this.#prefixThinkingIsV2 = false;
|
|
279
|
+
|
|
280
|
+
const hasPoll = Boolean(normalized && typeof normalized === "object" && normalized.poll !== undefined);
|
|
281
|
+
if (thinkingWasV2 === isV2 && !hasPoll && typeof thinkingMsg.edit === "function") {
|
|
282
|
+
const editData = normalized instanceof DJS.MessagePayload ? normalized : { ...normalized };
|
|
283
|
+
if (editData && typeof editData === "object" && "reply" in editData) {
|
|
284
|
+
delete editData.reply;
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
return await this.#sendWithOptionalRetry(() => thinkingMsg.edit(editData));
|
|
288
|
+
} catch {
|
|
289
|
+
// Fall through to sending a fresh message if placeholder can no longer be edited.
|
|
290
|
+
}
|
|
291
|
+
} else if (typeof thinkingMsg.delete === "function") {
|
|
292
|
+
await thinkingMsg.delete().catch(() => null);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const shouldReply = Boolean(options.reply ?? normalized?.reply ?? this.bot?.ops?.replyOnPrefix);
|
|
297
|
+
if (shouldReply && !(normalized instanceof DJS.MessagePayload)) {
|
|
298
|
+
if (!normalized.reply && this.data.id) {
|
|
299
|
+
normalized.reply = { messageReference: this.data.id, failIfNotExists: false };
|
|
300
|
+
}
|
|
301
|
+
if (normalized.allowedMentions === undefined) {
|
|
302
|
+
normalized.allowedMentions = { parse: [], repliedUser: false };
|
|
303
|
+
}
|
|
304
|
+
if (typeof this.data.reply === "function" && !options.forceChannelSend) {
|
|
305
|
+
const replyObj = { ...normalized };
|
|
306
|
+
delete replyObj.reply;
|
|
307
|
+
return this.#sendWithOptionalRetry(() => this.data.reply(replyObj));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return this.#sendWithOptionalRetry(() => this.data.channel.send(normalized));
|
|
97
312
|
}
|
|
98
313
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
: payload && typeof payload === "object"
|
|
103
|
-
? payload
|
|
104
|
-
: { content: String(payload ?? "") };
|
|
314
|
+
if (this.data.isAutocomplete?.()) {
|
|
315
|
+
throw new Error("Autocomplete interactions cannot send message replies. Use interaction.respond() instead.");
|
|
316
|
+
}
|
|
105
317
|
|
|
106
318
|
if (this.data.deferred || this.data.replied) {
|
|
107
|
-
|
|
319
|
+
const wasPublicDefer = !this.#deferredEphemeral && !this.data.ephemeral;
|
|
320
|
+
if (wantsEphemeral && wasPublicDefer) {
|
|
321
|
+
if (this.data.deferred && !this.data.replied && typeof this.data.deleteReply === "function") {
|
|
322
|
+
await this.data.deleteReply().catch(() => null);
|
|
323
|
+
}
|
|
324
|
+
return this.#sendWithOptionalRetry(() => this.data.followUp(normalized));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if (options.followUp) {
|
|
328
|
+
return this.#sendWithOptionalRetry(() => this.data.followUp(normalized));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return this.#sendWithOptionalRetry(() => this.data.editReply(normalized));
|
|
108
332
|
}
|
|
109
333
|
|
|
110
|
-
return this.#sendWithOptionalRetry(() => this.data.reply(
|
|
334
|
+
return this.#sendWithOptionalRetry(() => this.data.reply(normalized));
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Sends a message quoting the invoking message when in prefix mode.
|
|
339
|
+
*/
|
|
340
|
+
async reply(payload, options = {}) {
|
|
341
|
+
return this.send(payload, { ...options, reply: true });
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Sends an ephemeral message on interactions, automatically stripping the
|
|
346
|
+
* Ephemeral flag when executed from a prefix message command.
|
|
347
|
+
*/
|
|
348
|
+
async ephemeral(payload, options = {}) {
|
|
349
|
+
return this.send(payload, { ...options, ephemeral: true });
|
|
111
350
|
}
|
|
112
351
|
|
|
113
352
|
async react(...emojis) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Gralonium } from "./Client.js";
|
|
2
2
|
import { Collection } from "discord.js";
|
|
3
3
|
export declare enum Bucket {
|
|
4
4
|
Member = "MEMBER",
|
|
@@ -7,12 +7,12 @@ export declare enum Bucket {
|
|
|
7
7
|
Channel = "CHANNEL"
|
|
8
8
|
}
|
|
9
9
|
export declare class Cooldowns {
|
|
10
|
-
bot:
|
|
10
|
+
bot: Gralonium;
|
|
11
11
|
track: Collection<string, {
|
|
12
12
|
startedAt: number;
|
|
13
13
|
expiresAt: number;
|
|
14
14
|
}>;
|
|
15
|
-
constructor(bot:
|
|
15
|
+
constructor(bot: Gralonium);
|
|
16
16
|
getCooldownSource(command: string, id: string, bucket: Bucket): Promise<number | undefined>;
|
|
17
17
|
setCooldownSource(command: string, id: string, bucket: Bucket, time: number): Promise<void>;
|
|
18
18
|
check(command: string, id: string, cooldown: number, bucket: Bucket): Promise<{
|
package/lib/classes/Cooldowns.js
CHANGED
|
@@ -49,13 +49,8 @@ class Cooldowns {
|
|
|
49
49
|
const tracked = this.track.get(key);
|
|
50
50
|
if (!tracked) return null;
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const elapsed = Date.now() - tracked.startedAt;
|
|
58
|
-
if (elapsed >= cooldown) {
|
|
52
|
+
const now = Date.now();
|
|
53
|
+
if (now >= tracked.expiresAt) {
|
|
59
54
|
this.track.delete(key);
|
|
60
55
|
return null;
|
|
61
56
|
}
|
|
@@ -65,7 +60,7 @@ class Cooldowns {
|
|
|
65
60
|
id,
|
|
66
61
|
time: cooldown,
|
|
67
62
|
bucket,
|
|
68
|
-
left:
|
|
63
|
+
left: tracked.expiresAt - now,
|
|
69
64
|
};
|
|
70
65
|
}
|
|
71
66
|
}
|
|
@@ -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
|
}
|