@minesa-org/mini-interaction 0.2.11 → 0.2.12
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.
|
@@ -46,23 +46,23 @@ export interface CommandInteraction extends Omit<APIChatInputApplicationCommandI
|
|
|
46
46
|
options: CommandInteractionOptionResolver;
|
|
47
47
|
getResponse(): APIInteractionResponse | null;
|
|
48
48
|
reply(data: InteractionMessageData): APIInteractionResponseChannelMessageWithSource;
|
|
49
|
-
followUp(data: InteractionMessageData): Promise<
|
|
49
|
+
followUp(data: InteractionMessageData): Promise<void>;
|
|
50
50
|
edit(data?: InteractionMessageData): APIInteractionResponseUpdateMessage;
|
|
51
|
-
editReply(data?: InteractionMessageData): Promise<
|
|
51
|
+
editReply(data?: InteractionMessageData): Promise<void>;
|
|
52
52
|
deferReply(options?: DeferReplyOptions): APIInteractionResponseDeferredChannelMessageWithSource;
|
|
53
53
|
showModal(data: APIModalInteractionResponseCallbackData | {
|
|
54
54
|
toJSON(): APIModalInteractionResponseCallbackData;
|
|
55
55
|
}): APIModalInteractionResponse;
|
|
56
56
|
withTimeoutProtection<T>(operation: () => Promise<T>, deferOptions?: DeferReplyOptions): Promise<T>;
|
|
57
57
|
canRespond?(interactionId: string): boolean;
|
|
58
|
-
trackResponse?(interactionId: string, token: string, state:
|
|
58
|
+
trackResponse?(interactionId: string, token: string, state: 'responded' | 'deferred'): void;
|
|
59
59
|
onAck?(response: APIInteractionResponse): void;
|
|
60
60
|
sendFollowUp?(token: string, response: APIInteractionResponse, messageId?: string): Promise<void>;
|
|
61
61
|
}
|
|
62
62
|
export declare const CommandInteraction: {};
|
|
63
63
|
export declare function createCommandInteraction(interaction: APIChatInputApplicationCommandInteraction, helpers?: {
|
|
64
64
|
canRespond?: (interactionId: string) => boolean;
|
|
65
|
-
trackResponse?: (interactionId: string, token: string, state:
|
|
65
|
+
trackResponse?: (interactionId: string, token: string, state: 'responded' | 'deferred') => void;
|
|
66
66
|
logTiming?: (interactionId: string, operation: string, startTime: number, success: boolean) => void;
|
|
67
67
|
onAck?: (response: APIInteractionResponse) => void;
|
|
68
68
|
sendFollowUp?: (token: string, response: APIInteractionResponse, messageId?: string) => Promise<void>;
|
|
@@ -253,10 +253,10 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
253
253
|
},
|
|
254
254
|
reply(data) {
|
|
255
255
|
if (this.canRespond && !this.canRespond(this.id)) {
|
|
256
|
-
throw new Error(
|
|
256
|
+
throw new Error('Interaction cannot respond: already responded or expired');
|
|
257
257
|
}
|
|
258
258
|
const response = createMessageResponse(InteractionResponseType.ChannelMessageWithSource, data);
|
|
259
|
-
this.trackResponse?.(this.id, this.token,
|
|
259
|
+
this.trackResponse?.(this.id, this.token, 'responded');
|
|
260
260
|
hasResponded = true;
|
|
261
261
|
this.onAck?.(response);
|
|
262
262
|
return response;
|
|
@@ -264,53 +264,45 @@ export function createCommandInteraction(interaction, helpers) {
|
|
|
264
264
|
async followUp(data) {
|
|
265
265
|
const normalisedData = normaliseInteractionMessageData(data);
|
|
266
266
|
if (!normalisedData) {
|
|
267
|
-
throw new Error(
|
|
267
|
+
throw new Error('[MiniInteraction] followUp requires data');
|
|
268
268
|
}
|
|
269
269
|
const response = {
|
|
270
270
|
type: InteractionResponseType.ChannelMessageWithSource,
|
|
271
271
|
data: normalisedData,
|
|
272
272
|
};
|
|
273
273
|
if (this.sendFollowUp) {
|
|
274
|
-
await this.sendFollowUp(this.token, response,
|
|
274
|
+
await this.sendFollowUp(this.token, response, '');
|
|
275
275
|
}
|
|
276
|
-
return response;
|
|
277
276
|
},
|
|
278
277
|
edit(data) {
|
|
279
278
|
return createMessageResponse(InteractionResponseType.UpdateMessage, data);
|
|
280
279
|
},
|
|
281
280
|
async editReply(data) {
|
|
282
281
|
if (this.canRespond && !this.canRespond(this.id)) {
|
|
283
|
-
throw new Error(
|
|
282
|
+
throw new Error('Interaction cannot edit reply: expired');
|
|
284
283
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
throw new Error("[MiniInteraction] editReply requires data when deferred");
|
|
289
|
-
}
|
|
290
|
-
const response = {
|
|
291
|
-
type: InteractionResponseType.ChannelMessageWithSource,
|
|
292
|
-
data: normalisedData,
|
|
293
|
-
};
|
|
294
|
-
if (this.sendFollowUp) {
|
|
295
|
-
await this.sendFollowUp(this.token, response, "@original");
|
|
296
|
-
}
|
|
297
|
-
this.trackResponse?.(this.id, this.token, "responded");
|
|
298
|
-
hasResponded = true;
|
|
299
|
-
return response;
|
|
284
|
+
const normalisedData = normaliseInteractionMessageData(data);
|
|
285
|
+
if (!normalisedData) {
|
|
286
|
+
throw new Error('[MiniInteraction] editReply requires data');
|
|
300
287
|
}
|
|
301
|
-
const response =
|
|
302
|
-
|
|
288
|
+
const response = {
|
|
289
|
+
type: InteractionResponseType.ChannelMessageWithSource,
|
|
290
|
+
data: normalisedData,
|
|
291
|
+
};
|
|
292
|
+
if (this.sendFollowUp) {
|
|
293
|
+
await this.sendFollowUp(this.token, response, '@original');
|
|
294
|
+
}
|
|
295
|
+
this.trackResponse?.(this.id, this.token, 'responded');
|
|
303
296
|
hasResponded = true;
|
|
304
|
-
return response;
|
|
305
297
|
},
|
|
306
298
|
deferReply(options) {
|
|
307
299
|
if (this.canRespond && !this.canRespond(this.id)) {
|
|
308
|
-
throw new Error(
|
|
300
|
+
throw new Error('Interaction cannot defer: already responded or expired');
|
|
309
301
|
}
|
|
310
302
|
const response = createDeferredResponse(options?.flags !== undefined
|
|
311
303
|
? { flags: options.flags }
|
|
312
304
|
: undefined);
|
|
313
|
-
this.trackResponse?.(this.id, this.token,
|
|
305
|
+
this.trackResponse?.(this.id, this.token, 'deferred');
|
|
314
306
|
isDeferred = true;
|
|
315
307
|
this.onAck?.(response);
|
|
316
308
|
return response;
|
package/package.json
CHANGED