mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-22 21:07:02 -04:00
adds support for the paginator in interaction contexts
This commit is contained in:
parent
bfe83b807f
commit
58790fd034
3 changed files with 19 additions and 16 deletions
|
@ -9,9 +9,20 @@ 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;
|
this.targetUser = data.targetUser || this.message?.author?.id || data.context?.user?.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) => {
|
||||||
|
console.log(d)
|
||||||
|
return this.editOrRespond(d)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static asMessage(ctx) {
|
static asMessage(ctx) {
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
const BasePaginator = require("./BasePaginator");
|
|
||||||
|
|
||||||
module.exports = class InteractionPaginator extends BasePaginator {
|
|
||||||
constructor(client, data) {
|
|
||||||
super(client, data);
|
|
||||||
this.waitingForPage = null;
|
|
||||||
}
|
|
||||||
};
|
|
|
@ -1,7 +1,7 @@
|
||||||
const InteractionPaginator = require("./InteractionPaginator");
|
const BasePaginator = require("./BasePaginator");
|
||||||
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 InteractionPaginator)) continue;
|
if (!(listener instanceof BasePaginator)) 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 InteractionPaginator)) continue;
|
if (!(l instanceof BasePaginator)) 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,7 +150,7 @@ 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 InteractionPaginator)) continue;
|
if (!(l instanceof BasePaginator)) continue;
|
||||||
if (!l.commandMessage) continue;
|
if (!l.commandMessage) continue;
|
||||||
|
|
||||||
if (l.isCommandMessage(data.context.message.id)) {
|
if (l.isCommandMessage(data.context.message.id)) {
|
||||||
|
@ -159,7 +159,7 @@ module.exports = class Paginator {
|
||||||
}
|
}
|
||||||
if(listener) await listener.stop()
|
if(listener) await listener.stop()
|
||||||
|
|
||||||
const instance = new InteractionPaginator(this, data);
|
const instance = new BasePaginator(this, data);
|
||||||
this.activeListeners.push(instance);
|
this.activeListeners.push(instance);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue