mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
feat: améliorer la gestion des réponses de message dans la commande de présence
This commit is contained in:
@@ -213,6 +213,24 @@ const isMessageResult = (value: unknown): value is Message => {
|
|||||||
return "createMessageComponentCollector" in value && "edit" in value;
|
return "createMessageComponentCollector" in value && "edit" in value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resolveReplyMessage = (value: unknown): Message | null => {
|
||||||
|
if (isMessageResult(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!value || typeof value !== "object" || !("resource" in value)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const resource = (value as { resource?: unknown }).resource;
|
||||||
|
if (!resource || typeof resource !== "object" || !("message" in resource)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = (resource as { message?: unknown }).message;
|
||||||
|
return isMessageResult(message) ? message : null;
|
||||||
|
};
|
||||||
|
|
||||||
const persistAndApplyPresence = async (ctx: CommandExecutionContext, state: PresenceState): Promise<void> => {
|
const persistAndApplyPresence = async (ctx: CommandExecutionContext, state: PresenceState): Promise<void> => {
|
||||||
applyPresenceState(ctx.client, state);
|
applyPresenceState(ctx.client, state);
|
||||||
await savePresenceState(ctx.client, state);
|
await savePresenceState(ctx.client, state);
|
||||||
@@ -243,15 +261,16 @@ export const presenceCommand = defineCommand({
|
|||||||
const replyResult = await ctx.reply({
|
const replyResult = await ctx.reply({
|
||||||
flags: MessageFlags.IsComponentsV2,
|
flags: MessageFlags.IsComponentsV2,
|
||||||
components: [buildContainer(ctx, state, customIds)],
|
components: [buildContainer(ctx, state, customIds)],
|
||||||
fetchReply: true,
|
withResponse: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isMessageResult(replyResult)) {
|
const replyMessage = resolveReplyMessage(replyResult);
|
||||||
|
if (!replyMessage) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ownerId = ctx.user.id;
|
const ownerId = ctx.user.id;
|
||||||
const collector = replyResult.createMessageComponentCollector({ time: 15 * 60_000 });
|
const collector = replyMessage.createMessageComponentCollector({ time: 15 * 60_000 });
|
||||||
|
|
||||||
collector.on("collect", async (interaction) => {
|
collector.on("collect", async (interaction) => {
|
||||||
if (interaction.user.id !== ownerId) {
|
if (interaction.user.id !== ownerId) {
|
||||||
@@ -338,7 +357,7 @@ export const presenceCommand = defineCommand({
|
|||||||
|
|
||||||
await submitted.deferUpdate();
|
await submitted.deferUpdate();
|
||||||
|
|
||||||
await replyResult.edit({
|
await replyMessage.edit({
|
||||||
flags: MessageFlags.IsComponentsV2,
|
flags: MessageFlags.IsComponentsV2,
|
||||||
components: [buildContainer(ctx, state, customIds)],
|
components: [buildContainer(ctx, state, customIds)],
|
||||||
});
|
});
|
||||||
@@ -367,7 +386,7 @@ export const presenceCommand = defineCommand({
|
|||||||
});
|
});
|
||||||
|
|
||||||
collector.on("end", async () => {
|
collector.on("end", async () => {
|
||||||
await replyResult
|
await replyMessage
|
||||||
.edit({
|
.edit({
|
||||||
flags: MessageFlags.IsComponentsV2,
|
flags: MessageFlags.IsComponentsV2,
|
||||||
components: [buildContainer(ctx, state, customIds, true)],
|
components: [buildContainer(ctx, state, customIds, true)],
|
||||||
|
|||||||
Reference in New Issue
Block a user