revert certain paginator changes

This commit is contained in:
derpystuff 2024-01-24 18:46:51 +01:00
parent 0470db6a64
commit b9248e6aad
3 changed files with 19 additions and 19 deletions

View file

@ -9,17 +9,9 @@ module.exports = class BasePaginator extends EventEmitter {
this.commandMessage = data.commandMessage || null; this.commandMessage = data.commandMessage || null;
this.pages = data.pages; this.pages = data.pages;
this.index = 0; this.index = 0;
this.targetUser = data.targetUser || this.message?.author?.id || data.context?.user?.id; this.targetUser = data.targetUser || this.message.author.id;
this.waitingForPage = null;
this.editOrReply = data.context.editOrReply?.bind(data.context); this.editOrReply = data.context.editOrReply.bind(data.context);
// Support application command context
if(data.context.editOrRespond) {
this.editOrRespond = data.context.editOrRespond.bind(data.context)
this.editOrReply = (d) => this.editOrRespond(d)
}
} }
static asMessage(ctx) { static asMessage(ctx) {
@ -158,4 +150,4 @@ module.exports = class BasePaginator extends EventEmitter {
this.client.activeListeners.splice(targetIndex, 1); this.client.activeListeners.splice(targetIndex, 1);
return this; return this;
} }
}; };

View file

@ -0,0 +1,8 @@
const BasePaginator = require("./BasePaginator");
module.exports = class InteractionPaginator extends BasePaginator {
constructor(client, data) {
super(client, data);
this.waitingForPage = null;
}
};

View file

@ -1,7 +1,7 @@
const BasePaginator = require("./BasePaginator"); const InteractionPaginator = require("./InteractionPaginator");
const assert = require("assert"); const assert = require("assert");
const { Constants, Utils } = require('detritus-client'); const { Constants, Utils } = require('detritus-client')
const { Components } = Utils const { Components } = Utils
const { InteractionCallbackTypes } = Constants const { InteractionCallbackTypes } = Constants
@ -44,7 +44,7 @@ module.exports = class Paginator {
if (!allowedEvents.has(event)) return; if (!allowedEvents.has(event)) return;
for (const listener of this.activeListeners) { for (const listener of this.activeListeners) {
if (!(listener instanceof BasePaginator)) continue; if (!(listener instanceof InteractionPaginator)) continue;
if (!listener.commandMessage) continue; if (!listener.commandMessage) continue;
if (event === "MESSAGE_CREATE" && if (event === "MESSAGE_CREATE" &&
@ -60,7 +60,7 @@ module.exports = class Paginator {
async handleButtonEvent(context) { async handleButtonEvent(context) {
let listener; let listener;
for (const l of this.activeListeners) { for (const l of this.activeListeners) {
if (!(l instanceof BasePaginator)) continue; if (!(l instanceof InteractionPaginator)) continue;
if (!l.commandMessage) continue; if (!l.commandMessage) continue;
if (l.isCommandMessage(context.message.id)) { if (l.isCommandMessage(context.message.id)) {
listener = l listener = l
@ -150,17 +150,16 @@ module.exports = class Paginator {
// Check if a paginator exists, if it does kill the old one // Check if a paginator exists, if it does kill the old one
let listener; let listener;
for (const l of this.activeListeners) { for (const l of this.activeListeners) {
if (!(l instanceof BasePaginator)) continue; if (!(l instanceof InteractionPaginator)) continue;
if (!l.commandMessage) continue; if (!l.commandMessage) continue;
if (data.context.message?.id && l.isCommandMessage(data.context.message?.id)) { if (l.isCommandMessage(data.context.message.id)) {
listener = l listener = l
} }
} }
if(listener) await listener.stop() if(listener) await listener.stop()
const instance = new BasePaginator(this, data); const instance = new InteractionPaginator(this, data);
this.activeListeners.push(instance); this.activeListeners.push(instance);
setTimeout(() => { setTimeout(() => {
@ -183,3 +182,4 @@ module.exports = class Paginator {
return instance; return instance;
} }
}; };