@seedcord/core 0.1.0-next.4 → 0.1.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CustomId--QizzBOn.d.mts → AutocompleteOptions-eKhIe6Qt.d.mts} +496 -163
- package/dist/Plugin-C2-VHrsX.cjs +114 -0
- package/dist/Plugin-C2-VHrsX.cjs.map +1 -0
- package/dist/Plugin-CNyRKDHT.d.mts +226 -0
- package/dist/Plugin-PcdPjAzc.mjs +97 -0
- package/dist/Plugin-PcdPjAzc.mjs.map +1 -0
- package/dist/devChannel-CQU7hq7Q.mjs +14 -0
- package/dist/devChannel-CQU7hq7Q.mjs.map +1 -0
- package/dist/devChannel-CoCmAVDx.cjs +26 -0
- package/dist/devChannel-CoCmAVDx.cjs.map +1 -0
- package/dist/index.cjs +239 -105
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +182 -25
- package/dist/index.mjs +199 -79
- package/dist/index.mjs.map +1 -1
- package/dist/internal.index.cjs +463 -57
- package/dist/internal.index.cjs.map +1 -1
- package/dist/internal.index.d.mts +146 -28
- package/dist/internal.index.mjs +415 -29
- package/dist/internal.index.mjs.map +1 -1
- package/dist/is-never-Ddaba1Su.d.mts +58 -0
- package/dist/node-internal.index.cjs +645 -0
- package/dist/node-internal.index.cjs.map +1 -0
- package/dist/node-internal.index.d.cts +1 -0
- package/dist/node-internal.index.d.mts +2352 -0
- package/dist/node-internal.index.mjs +636 -0
- package/dist/node-internal.index.mjs.map +1 -0
- package/dist/{CustomId-DV7daU7r.cjs → permissions-DSW_EZfN.cjs} +448 -89
- package/dist/permissions-DSW_EZfN.cjs.map +1 -0
- package/dist/{CustomId-epJayEGO.mjs → permissions-RVCBhL2n.mjs} +341 -90
- package/dist/permissions-RVCBhL2n.mjs.map +1 -0
- package/dist/phases-BfpAG6w3.mjs +31 -0
- package/dist/phases-BfpAG6w3.mjs.map +1 -0
- package/dist/phases-C_BGNyVo.cjs +43 -0
- package/dist/phases-C_BGNyVo.cjs.map +1 -0
- package/dist/plugin.index.cjs +4 -0
- package/dist/plugin.index.d.cts +1 -0
- package/dist/plugin.index.d.mts +3 -0
- package/dist/plugin.index.mjs +3 -0
- package/package.json +32 -10
- package/dist/CustomId-DV7daU7r.cjs.map +0 -1
- package/dist/CustomId-epJayEGO.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_permissions = require('./permissions-DSW_EZfN.cjs');
|
|
3
|
+
const require_phases = require('./phases-C_BGNyVo.cjs');
|
|
3
4
|
require("reflect-metadata");
|
|
4
5
|
let _seedcord_errors = require("@seedcord/errors");
|
|
5
6
|
let _seedcord_errors_internal = require("@seedcord/errors/internal");
|
|
7
|
+
let _seedcord_logger = require("@seedcord/logger");
|
|
6
8
|
let _seedcord_utils = require("@seedcord/utils");
|
|
7
9
|
|
|
8
10
|
//#region src/decorators/Command.ts
|
|
9
11
|
function RegisterCommand(scope, guilds = []) {
|
|
10
12
|
return (ctor) => {
|
|
11
|
-
const existingMeta = Reflect.getOwnMetadata(
|
|
13
|
+
const existingMeta = Reflect.getOwnMetadata(require_permissions.CommandMetadataKey, ctor);
|
|
12
14
|
if (existingMeta) throw new _seedcord_errors_internal.SeedcordError(_seedcord_errors.SeedcordErrorCode.DecoratorCommandAlreadyRegistered, [
|
|
13
15
|
ctor.name,
|
|
14
16
|
existingMeta.scope,
|
|
@@ -20,7 +22,138 @@ function RegisterCommand(scope, guilds = []) {
|
|
|
20
22
|
scope,
|
|
21
23
|
guilds
|
|
22
24
|
};
|
|
23
|
-
Reflect.defineMetadata(
|
|
25
|
+
Reflect.defineMetadata(require_permissions.CommandMetadataKey, meta, ctor);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/decorators/routes.ts
|
|
31
|
+
/**
|
|
32
|
+
* Routes one or more slash commands to a `SlashHandler`.
|
|
33
|
+
*
|
|
34
|
+
* Pass the same route string(s) as the handler's generic. A single command reads `this.options`, several
|
|
35
|
+
* commands branch with `this.match`. The decorator routes and the generic must match exactly, so listing
|
|
36
|
+
* fewer or more than the handler declares is a compile error. Subcommands use a slash path.
|
|
37
|
+
*
|
|
38
|
+
* @param routes - The route string(s) this handler serves, e.g. `'ban'`, `'ban', 'kick'`, or `'demo/setup'`.
|
|
39
|
+
* @decorator
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* \@SlashRoute('ban')
|
|
43
|
+
* class BanHandler extends SlashHandler<'ban'> {
|
|
44
|
+
* async execute() {
|
|
45
|
+
* const target = this.options.getUser('target');
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function SlashRoute(...routes) {
|
|
51
|
+
return function(constructor) {
|
|
52
|
+
require_permissions.storeInteractionRoute("slash", routes, constructor);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Routes one or more commands' autocomplete to an `AutocompleteHandler`.
|
|
57
|
+
*
|
|
58
|
+
* Pass the same command route string(s) as the handler's generic. One command branches with `this.match`
|
|
59
|
+
* over its autocompletable fields, several commands share one handler whose arms span every command's
|
|
60
|
+
* fields. The decorator routes and the generic must match exactly, so listing fewer or more than the
|
|
61
|
+
* handler declares is a compile error.
|
|
62
|
+
*
|
|
63
|
+
* @param routes - The command route string(s) this handler serves, e.g. `'search'` or `'search', 'find'`.
|
|
64
|
+
* @decorator
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* \@AutocompleteRoute('search')
|
|
68
|
+
* class SearchAutocomplete extends AutocompleteHandler<'search'> {
|
|
69
|
+
* async execute() {
|
|
70
|
+
* await this.match({ query: (value, respond) => respond([{ name: value, value }]) });
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
function AutocompleteRoute(...routes) {
|
|
76
|
+
return function(constructor) {
|
|
77
|
+
require_permissions.storeInteractionRoute("autocomplete", routes, constructor);
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Routes one or more context-menu commands to a `ContextMenuHandler`.
|
|
82
|
+
*
|
|
83
|
+
* Pass the kind (`ApplicationCommandType.User` or `ApplicationCommandType.Message`) and the command name(s),
|
|
84
|
+
* each checked against that kind's registry, so a typo is a compile error. The handler's generic must
|
|
85
|
+
* declare the same kind, cross-checked both directions. Context menus carry no options, so a multi-name
|
|
86
|
+
* handler reads `this.target` uniformly with no branch.
|
|
87
|
+
*
|
|
88
|
+
* @param kind - The context-menu kind, `ApplicationCommandType.User` or `ApplicationCommandType.Message`.
|
|
89
|
+
* @param names - The command name(s) this handler serves, keyed off the matching registry.
|
|
90
|
+
* @decorator
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* \@ContextMenuRoute(ApplicationCommandType.User, 'View Profile')
|
|
94
|
+
* class ViewProfile extends ContextMenuHandler<ApplicationCommandType.User> {
|
|
95
|
+
* async execute() {
|
|
96
|
+
* const user = this.target;
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
function ContextMenuRoute(kind, ...names) {
|
|
102
|
+
return function(constructor) {
|
|
103
|
+
require_permissions.storeInteractionRoute(require_permissions.contextMenuRouteOf(kind), names, constructor);
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Routes button interactions to handler classes.
|
|
108
|
+
*
|
|
109
|
+
* Pass the {@link CustomId} definition(s) this handler decodes and list the same ones in the handler's
|
|
110
|
+
* generic. Passing different definitions to the decorator and the generic is a compile error. Routing
|
|
111
|
+
* matches the stable prefix, so a wire minted from an older shape still reaches the handler, where
|
|
112
|
+
* reading this.params throws StaleCustomId and the controller boundary turns it into a reply.
|
|
113
|
+
*
|
|
114
|
+
* @param defs - The customId definition(s) this handler decodes, one per route.
|
|
115
|
+
* @decorator
|
|
116
|
+
*/
|
|
117
|
+
function ButtonRoute(...defs) {
|
|
118
|
+
return function(constructor) {
|
|
119
|
+
require_permissions.storeComponentRoute("button", defs, constructor);
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Routes modal submissions to handler classes.
|
|
124
|
+
*
|
|
125
|
+
* Pass the {@link CustomId} definition(s) this handler decodes and list the same ones in the handler's
|
|
126
|
+
* generic. Passing different definitions to the decorator and the generic is a compile error. Routing
|
|
127
|
+
* matches the stable prefix, so an older-shape wire still reaches the handler and throws StaleCustomId
|
|
128
|
+
* on read, the same as a button route.
|
|
129
|
+
*
|
|
130
|
+
* @param defs - The customId definition(s) this handler decodes, one per route.
|
|
131
|
+
* @decorator
|
|
132
|
+
*/
|
|
133
|
+
function ModalRoute(...defs) {
|
|
134
|
+
return function(constructor) {
|
|
135
|
+
require_permissions.storeComponentRoute("modal", defs, constructor);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Routes select menu interactions to handler classes.
|
|
140
|
+
*
|
|
141
|
+
* Pass the select kind and the {@link CustomId} definition(s) this handler decodes. The handler's
|
|
142
|
+
* generic must list the same kind and definitions, or it is a compile error.
|
|
143
|
+
*
|
|
144
|
+
* @param type - Select menu kind from {@link SelectMenuKind}.
|
|
145
|
+
* @param defs - The customId definition(s) this handler decodes, one per route.
|
|
146
|
+
* @decorator
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* \@SelectMenuRoute(SelectMenuKind.User, AssignId)
|
|
151
|
+
* class AssignSelect extends SelectMenuHandler<SelectMenuKind.User, [typeof AssignId]> {}
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
function SelectMenuRoute(type, ...defs) {
|
|
155
|
+
return function(constructor) {
|
|
156
|
+
require_permissions.storeComponentRoute(require_permissions.selectMenuRouteOf(type), defs, constructor);
|
|
24
157
|
};
|
|
25
158
|
}
|
|
26
159
|
|
|
@@ -46,88 +179,75 @@ var DispatchContext = class {
|
|
|
46
179
|
};
|
|
47
180
|
|
|
48
181
|
//#endregion
|
|
49
|
-
//#region src/
|
|
182
|
+
//#region src/handlers/BaseHandler.ts
|
|
50
183
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* the check reads. No annotation defaults to {@link GateContextBase}, an agnostic gate that fits every
|
|
54
|
-
* handler.
|
|
55
|
-
*
|
|
56
|
-
* @typeParam Name - The gate's name captured as a literal, so a mismatch error can name the gate.
|
|
57
|
-
* @typeParam Ctx - The context the check reads, inferred from the `ctx` annotation.
|
|
58
|
-
*
|
|
59
|
-
* @param name - The gate's name, used in mismatch errors.
|
|
60
|
-
* @param fn - The check, which refuses by throwing a Notice or a Silence and passes by returning.
|
|
61
|
-
*
|
|
62
|
-
* @see {@link defineEffectGate}
|
|
63
|
-
* @see the `@Gated` decorator from `seedcord`
|
|
184
|
+
* Base class every transport handler extends. Don't register handlers directly, use the more specific
|
|
185
|
+
* handler subclasses.
|
|
64
186
|
*
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
67
|
-
* // a gate factory that takes its own option and closes over it
|
|
68
|
-
* function MinRoles(min: number): Gate<GateContextBase, 'MinRoles'> {
|
|
69
|
-
* return defineGate('MinRoles', (ctx) => {
|
|
70
|
-
* if (ctx.memberRoleIds.length < min) throw new NotEnoughRoles(min);
|
|
71
|
-
* });
|
|
72
|
-
* }
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* // agnostic gate (no ctx annotation): fits any handler
|
|
78
|
-
* const Owner = defineGate('owner', (ctx) => {
|
|
79
|
-
* if (!ctx.userId) throw new NotOwner();
|
|
80
|
-
* });
|
|
81
|
-
* ```
|
|
187
|
+
* @typeParam Event - The event or interaction this handler processes
|
|
188
|
+
* @typeParam TCore - The transport's Core
|
|
82
189
|
*/
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
190
|
+
var BaseHandler = class {
|
|
191
|
+
core;
|
|
192
|
+
event;
|
|
193
|
+
logger;
|
|
194
|
+
dispatch;
|
|
195
|
+
constructor(event, core, dispatch) {
|
|
196
|
+
this.core = core;
|
|
197
|
+
this.event = event;
|
|
198
|
+
this.logger = new _seedcord_logger.Logger(this.constructor.name);
|
|
199
|
+
this.dispatch = dispatch;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/handlers/RepliableHandler.ts
|
|
89
205
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* commits. In an `or`, a refusing arm's queued commit is rolled back. This is how {@link Cooldown} peeks
|
|
93
|
-
* in `check` and charges the slot in `commit`.
|
|
94
|
-
*
|
|
95
|
-
* @typeParam Name - The gate's name captured as a literal, so a mismatch error can name the gate.
|
|
96
|
-
* @typeParam Ctx - The context both `check` and `commit` read, inferred from the `ctx` annotation.
|
|
97
|
-
*
|
|
98
|
-
* @param name - The gate's name, used in mismatch errors.
|
|
99
|
-
* @param check - Peeks and refuses by throwing, without applying the side effect.
|
|
100
|
-
* @param commit - Applies the side effect, running only after the whole gate set passes.
|
|
101
|
-
*
|
|
102
|
-
* @see {@link defineGate}
|
|
103
|
-
* @see the `@Gated` decorator from `seedcord`
|
|
104
|
-
* @see {@link Cooldown}
|
|
206
|
+
* Shared base the repliable handlers on both transports extend. Defines the reply members over the sender
|
|
207
|
+
* the transport builds.
|
|
105
208
|
*
|
|
106
|
-
* @
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* return defineEffectGate(
|
|
111
|
-
* 'UsesPerDay',
|
|
112
|
-
* (ctx) => {
|
|
113
|
-
* // peek and refuse by throwing, do not mutate yet
|
|
114
|
-
* if (usedToday(ctx.userId) >= max) throw new OutOfUsesNotice(max);
|
|
115
|
-
* },
|
|
116
|
-
* (ctx) => {
|
|
117
|
-
* // runs only after the whole gate set passes
|
|
118
|
-
* recordUse(ctx.userId);
|
|
119
|
-
* }
|
|
120
|
-
* );
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
209
|
+
* @typeParam Event - The repliable interaction type this handler processes
|
|
210
|
+
* @typeParam TCore - The transport's Core
|
|
211
|
+
* @typeParam TMessage - The transport's created-message lens
|
|
212
|
+
* @typeParam TSender - The transport's reply sender
|
|
123
213
|
*/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
214
|
+
var RepliableHandler = class extends BaseHandler {
|
|
215
|
+
sender;
|
|
216
|
+
routeId;
|
|
217
|
+
constructor(event, core, dispatch) {
|
|
218
|
+
super(event, core, dispatch);
|
|
219
|
+
this.routeId = dispatch?.routeId ?? this.constructor.name;
|
|
220
|
+
this.sender = this.buildSender(event, core, this.routeId);
|
|
221
|
+
}
|
|
222
|
+
/** @internal The dispatcher's fault boundary replies through the live ack state. */
|
|
223
|
+
getSender() {
|
|
224
|
+
return this.sender;
|
|
225
|
+
}
|
|
226
|
+
/** Send the initial response, exactly once. */
|
|
227
|
+
reply(response, opts) {
|
|
228
|
+
return this.sender.reply(response, opts);
|
|
229
|
+
}
|
|
230
|
+
/** Show a "thinking" placeholder, then fill it later with {@link edit}. */
|
|
231
|
+
defer(opts) {
|
|
232
|
+
return this.sender.defer(opts);
|
|
233
|
+
}
|
|
234
|
+
/** Send a new message once the interaction is acknowledged. */
|
|
235
|
+
followUp(response, opts) {
|
|
236
|
+
return this.sender.followUp(response, opts);
|
|
237
|
+
}
|
|
238
|
+
edit(targetOrResponse, maybeResponse) {
|
|
239
|
+
if (maybeResponse === void 0) return this.sender.edit(targetOrResponse);
|
|
240
|
+
return this.sender.edit(targetOrResponse, maybeResponse);
|
|
241
|
+
}
|
|
242
|
+
/** Routes to reply, followUp, or edit based on the current ack state. */
|
|
243
|
+
send(response, opts) {
|
|
244
|
+
return this.sender.send(response, opts);
|
|
245
|
+
}
|
|
246
|
+
/** Delete the initial reply or deferred placeholder. Pass a target to delete a message a prior send returned. */
|
|
247
|
+
delete(target) {
|
|
248
|
+
return target === void 0 ? this.sender.delete() : this.sender.delete(target);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
131
251
|
|
|
132
252
|
//#endregion
|
|
133
253
|
//#region src/stops/Fault.ts
|
|
@@ -158,21 +278,21 @@ function defineEffectGate(name, check, commit) {
|
|
|
158
278
|
* }
|
|
159
279
|
* ```
|
|
160
280
|
*/
|
|
161
|
-
var Fault = class extends
|
|
281
|
+
var Fault = class extends require_permissions.Notice {
|
|
162
282
|
constructor(options) {
|
|
163
283
|
super("A fault occurred", options?.cause === void 0 ? void 0 : { cause: options.cause });
|
|
164
284
|
this.report = options?.report ?? true;
|
|
165
285
|
}
|
|
166
286
|
render(ctx) {
|
|
167
|
-
return { components: [new
|
|
287
|
+
return { components: [new require_permissions.NoticeCard(`Something went wrong. Please reach out to ${ctx.developerUsername ?? "the developer"} with a way to reproduce the error and the following:\n### UUID: \`${ctx.uuid}\``, "Error").component] };
|
|
168
288
|
}
|
|
169
289
|
};
|
|
170
290
|
|
|
171
291
|
//#endregion
|
|
172
292
|
//#region src/gates/combinators.ts
|
|
173
293
|
function and(...gates) {
|
|
174
|
-
return defineGate(gates.map((gate) => gate.name).join(" & "), async (ctx) => {
|
|
175
|
-
for (const gate of gates) await
|
|
294
|
+
return require_permissions.defineGate(gates.map((gate) => gate.name).join(" & "), async (ctx) => {
|
|
295
|
+
for (const gate of gates) await require_permissions.runCheck(gate, ctx);
|
|
176
296
|
});
|
|
177
297
|
}
|
|
178
298
|
function isOrOptions(arg) {
|
|
@@ -182,17 +302,17 @@ function or(...args) {
|
|
|
182
302
|
const last = args.at(-1);
|
|
183
303
|
const options = last !== void 0 && isOrOptions(last) ? last : void 0;
|
|
184
304
|
const gates = options ? args.slice(0, -1) : args;
|
|
185
|
-
return defineGate(gates.map((gate) => gate.name).join(" | "), async (ctx) => {
|
|
305
|
+
return require_permissions.defineGate(gates.map((gate) => gate.name).join(" | "), async (ctx) => {
|
|
186
306
|
const summaries = [];
|
|
187
307
|
let everyArmHasSummary = true;
|
|
188
308
|
for (const gate of gates) {
|
|
189
|
-
const mark =
|
|
309
|
+
const mark = require_permissions.markCommits(ctx);
|
|
190
310
|
try {
|
|
191
|
-
await
|
|
311
|
+
await require_permissions.runCheck(gate, ctx);
|
|
192
312
|
return;
|
|
193
313
|
} catch (error) {
|
|
194
|
-
if (error instanceof
|
|
195
|
-
|
|
314
|
+
if (error instanceof require_permissions.Notice && !(error instanceof Fault) && !error.report) {
|
|
315
|
+
require_permissions.rollbackCommits(ctx, mark);
|
|
196
316
|
if (error.summary === void 0) everyArmHasSummary = false;
|
|
197
317
|
else summaries.push(error.summary);
|
|
198
318
|
continue;
|
|
@@ -201,8 +321,8 @@ function or(...args) {
|
|
|
201
321
|
}
|
|
202
322
|
}
|
|
203
323
|
if (options) throw typeof options.fail === "function" ? options.fail(ctx) : options.fail;
|
|
204
|
-
if (everyArmHasSummary && summaries.length > 0) throw new
|
|
205
|
-
throw new
|
|
324
|
+
if (everyArmHasSummary && summaries.length > 0) throw new require_permissions.NeedsAny(summaries);
|
|
325
|
+
throw new require_permissions.NotAllowed();
|
|
206
326
|
});
|
|
207
327
|
}
|
|
208
328
|
|
|
@@ -235,10 +355,10 @@ function or(...args) {
|
|
|
235
355
|
* ```
|
|
236
356
|
*/
|
|
237
357
|
function OwnerOnly(options) {
|
|
238
|
-
return defineGate("OwnerOnly", (ctx) => {
|
|
358
|
+
return require_permissions.defineGate("OwnerOnly", (ctx) => {
|
|
239
359
|
const owners = ctx.core.config.ownerIds ?? [];
|
|
240
360
|
if (ctx.userId !== null && owners.includes(ctx.userId)) return;
|
|
241
|
-
throw
|
|
361
|
+
throw require_permissions.pickNotice(options, (message) => new require_permissions.NotOwner(message));
|
|
242
362
|
});
|
|
243
363
|
}
|
|
244
364
|
/**
|
|
@@ -264,9 +384,9 @@ function OwnerOnly(options) {
|
|
|
264
384
|
* ```
|
|
265
385
|
*/
|
|
266
386
|
function GuildOnly(options) {
|
|
267
|
-
return defineGate("GuildOnly", (ctx) => {
|
|
387
|
+
return require_permissions.defineGate("GuildOnly", (ctx) => {
|
|
268
388
|
if (ctx.guildId) return;
|
|
269
|
-
throw
|
|
389
|
+
throw require_permissions.pickNotice(options, (message) => new require_permissions.NotInGuild(message));
|
|
270
390
|
});
|
|
271
391
|
}
|
|
272
392
|
/**
|
|
@@ -290,9 +410,9 @@ function GuildOnly(options) {
|
|
|
290
410
|
* ```
|
|
291
411
|
*/
|
|
292
412
|
function DmOnly(options) {
|
|
293
|
-
return defineGate("DmOnly", (ctx) => {
|
|
413
|
+
return require_permissions.defineGate("DmOnly", (ctx) => {
|
|
294
414
|
if (!ctx.guildId) return;
|
|
295
|
-
throw
|
|
415
|
+
throw require_permissions.pickNotice(options, (message) => new require_permissions.NotInDm(message));
|
|
296
416
|
});
|
|
297
417
|
}
|
|
298
418
|
|
|
@@ -364,11 +484,11 @@ function Cooldown(duration, options) {
|
|
|
364
484
|
};
|
|
365
485
|
const anonId = anonSeq++;
|
|
366
486
|
const keyOf = (ctx) => `cooldown:${ctx.routeId ?? `anon${anonId}`}:${per}:w${windowMs}:l${options?.limit ?? 1}:${scopeValue(ctx, per)}`;
|
|
367
|
-
return defineEffectGate("Cooldown", async (ctx) => {
|
|
487
|
+
return require_permissions.defineEffectGate("Cooldown", async (ctx) => {
|
|
368
488
|
const result = await ctx.core.rateLimiter.peek(keyOf(ctx), window);
|
|
369
489
|
if (!result.limited) return;
|
|
370
490
|
if (options?.notice) throw options.notice(result.resetAt);
|
|
371
|
-
throw new
|
|
491
|
+
throw new require_permissions.OnCooldown(result.resetAt, options?.message?.(result.resetAt));
|
|
372
492
|
}, async (ctx) => {
|
|
373
493
|
await ctx.core.rateLimiter.charge(keyOf(ctx), window);
|
|
374
494
|
});
|
|
@@ -432,24 +552,38 @@ function paginate(items, page, perPage) {
|
|
|
432
552
|
//#endregion
|
|
433
553
|
//#region src/index.ts
|
|
434
554
|
/** Package version */
|
|
435
|
-
const version = "0.1.0-next.
|
|
555
|
+
const version = "0.1.0-next.6";
|
|
436
556
|
|
|
437
557
|
//#endregion
|
|
438
|
-
exports.
|
|
558
|
+
exports.AutocompleteRoute = AutocompleteRoute;
|
|
559
|
+
exports.BaseHandler = BaseHandler;
|
|
560
|
+
exports.BuilderComponent = require_permissions.BuilderComponent;
|
|
561
|
+
exports.ButtonRoute = ButtonRoute;
|
|
562
|
+
exports.ContextMenuRoute = ContextMenuRoute;
|
|
439
563
|
exports.Cooldown = Cooldown;
|
|
440
|
-
exports.CustomId =
|
|
564
|
+
exports.CustomId = require_permissions.CustomId;
|
|
441
565
|
exports.DispatchContext = DispatchContext;
|
|
442
566
|
exports.DmOnly = DmOnly;
|
|
443
567
|
exports.Fault = Fault;
|
|
444
568
|
exports.GuildOnly = GuildOnly;
|
|
445
|
-
exports.
|
|
569
|
+
exports.ModalRoute = ModalRoute;
|
|
570
|
+
exports.Notice = require_permissions.Notice;
|
|
446
571
|
exports.OwnerOnly = OwnerOnly;
|
|
447
572
|
exports.RegisterCommand = RegisterCommand;
|
|
448
|
-
exports.
|
|
573
|
+
exports.RepliableHandler = RepliableHandler;
|
|
574
|
+
exports.RequireBotPermissions = require_permissions.RequireBotPermissions;
|
|
575
|
+
exports.RequirePermissions = require_permissions.RequirePermissions;
|
|
576
|
+
exports.RequireRole = require_permissions.RequireRole;
|
|
577
|
+
exports.RowComponent = require_permissions.RowComponent;
|
|
578
|
+
exports.SelectMenuKind = require_permissions.SelectMenuKind;
|
|
579
|
+
exports.SelectMenuRoute = SelectMenuRoute;
|
|
580
|
+
exports.ShutdownPhase = require_phases.ShutdownPhase;
|
|
449
581
|
exports.Silence = Silence;
|
|
582
|
+
exports.SlashRoute = SlashRoute;
|
|
583
|
+
exports.StartupPhase = require_phases.StartupPhase;
|
|
450
584
|
exports.and = and;
|
|
451
|
-
exports.defineEffectGate = defineEffectGate;
|
|
452
|
-
exports.defineGate = defineGate;
|
|
585
|
+
exports.defineEffectGate = require_permissions.defineEffectGate;
|
|
586
|
+
exports.defineGate = require_permissions.defineGate;
|
|
453
587
|
exports.or = or;
|
|
454
588
|
exports.paginate = paginate;
|
|
455
589
|
exports.version = version;
|