diff --git a/commands/message/search/quora.js b/commands/message/search/quora.js index 259cca2..55ec4fc 100644 --- a/commands/message/search/quora.js +++ b/commands/message/search/quora.js @@ -48,7 +48,8 @@ async function quoraPaginator(context, pages, refMappings, currentRef) { "previous", "next", "search" - ] + ], + disableCloning: true }); paging.on("interaction", async ({ context: ctx, listener }) => { diff --git a/labscore/paginator/structures/BasePaginator.js b/labscore/paginator/structures/BasePaginator.js index a5b0f28..10e4143 100644 --- a/labscore/paginator/structures/BasePaginator.js +++ b/labscore/paginator/structures/BasePaginator.js @@ -1,20 +1,25 @@ const EventEmitter = require("eventemitter3"); const { Context } = require("detritus-client/lib/command"); const { editOrReply } = require("#utils/message"); +const { MessageFlags } = require("detritus-client/lib/constants"); module.exports = class BasePaginator extends EventEmitter { constructor(client, data) { super(); this.client = client; + this.data = data; this.message = BasePaginator.asMessage(data.context); this.commandMessage = data.commandMessage || null; this.pages = data.pages; - this.index = 0; + this.index = data.index || 0; + this.ephemeral = data.ephemeral || false; this.context = data.context; this.targetUser = data.targetUser || this.message?.author?.id || data.context?.user?.id; + this.disableCloning = data.disableCloning || false; + this.isInteractionPaginator = false; this.editOrReply; if(data.context.editOrReply) this.editOrReply = editOrReply.bind(data.context); @@ -31,7 +36,7 @@ module.exports = class BasePaginator extends EventEmitter { get isShared() { return this.commandMessage instanceof Map; } - + isCommandMessage(messageId) { if (!this.commandMessage) return false; @@ -68,6 +73,12 @@ module.exports = class BasePaginator extends EventEmitter { if(!msg.message_reference) msg.reference = true if(!msg.allowedMentions) msg.allowedMentions = {parse: [], repliedUser: false} + if(this.ephemeral){ + msg.flags = MessageFlags.EPHEMERAL + this.commandMessage = await this.context.createMessage(msg); + + return this.commandMessage; + } return this.commandMessage = await this.editOrReply(this.context, msg); } diff --git a/labscore/paginator/structures/Paginator.js b/labscore/paginator/structures/Paginator.js index 9edb64d..5606c83 100644 --- a/labscore/paginator/structures/Paginator.js +++ b/labscore/paginator/structures/Paginator.js @@ -1,5 +1,6 @@ const { COMPONENT_BUTTON_ICONS } = require("#constants"); const { icon } = require("#utils/markdown"); +const { MessageFlags } = require("detritus-client/lib/constants"); const InteractionPaginator = require("./InteractionPaginator"); const assert = require("assert"); @@ -63,7 +64,28 @@ module.exports = class Paginator { // If person that interacted isnt the target, send a generic ping response and ignore it if (!listener.isTarget(context.user.id)) { - await context.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE) + + // If ephemeral cloning is disabled ignore the interaction + if(listener.disableCloning) return await context.respond(InteractionCallbackTypes.DEFERRED_UPDATE_MESSAGE); + + await context.respond(InteractionCallbackTypes.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE, { flags: MessageFlags.EPHEMERAL }); + + // (this is very hacky but the best i can think of right now) + // clones the current paginator and attaches a new one to that response + + // i have plans to fix this with pagination v2 whenever i get around to working on it + + let newPaginator = Object.assign(Object.create(Object.getPrototypeOf(listener)), listener); + + newPaginator.context = context; + newPaginator.targetUser = context.user.id; + newPaginator.ephemeral = true; + + if(context.customId == "next") await newPaginator.getNext() + else if(context.customId == "previous") await newPaginator.getPrevious() + + this.activeListeners.push(newPaginator); + await newPaginator.init(); return; }