[fix] paginator editing works properly now

This commit is contained in:
derpystuff 2022-05-26 00:15:19 +02:00
parent a68b840af7
commit 41721f941f
13 changed files with 32 additions and 37 deletions

View file

@ -96,9 +96,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
return;
@ -125,9 +124,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}

View file

@ -2,7 +2,7 @@ const { Constants } = require('detritus-client');
const { paginator } = require('../../../../labscore/client');
const createEmbedMessage = (title, description) => ({
embeds: [{ title, description }]
embeds: [{ title, description }]
});
module.exports = {
@ -14,17 +14,15 @@ module.exports = {
usage: 'page'
},
run: async (context) => {
const message = context.message
const message = context
const pages = [
createEmbedMessage("Page", "ddd"),
createEmbedMessage("Page2", "eee"),
createEmbedMessage("Page 3", "h")
]
const paging = await paginator.createPaginator({
// message is the message the user has sent
message,
// pages is an array of pages (will be passed as parameter in Message#edit)
pages
});
context,
pages
});
},
};

View file

@ -48,9 +48,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}catch(e){

View file

@ -44,9 +44,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}catch(e){

View file

@ -48,9 +48,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}catch(e){

View file

@ -45,9 +45,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}catch(e){

View file

@ -62,11 +62,10 @@ module.exports = {
while(fields.length) {
pages.push({embeds:[createLyricsPage(context, search, fields.splice(0,3))]})
}
const message = context.message
pages = formatPaginationEmbeds(pages)
const paging = await paginator.createPaginator({
message,
context,
pages
});
return;

View file

@ -46,9 +46,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}catch(e){

View file

@ -47,9 +47,8 @@ module.exports = {
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
context,
pages
});
}catch(e){

View file

@ -1,5 +1,4 @@
const { Constants, ClusterClient, CommandClient } = require('detritus-client');
//const { createPaginator } = require('./paginator')
const Paginator = require('./paginator').PaginatorCluster
// Create client
@ -40,12 +39,6 @@ const paginator = new Paginator(cluster, {
});
await commandClient.addMultipleIn('../commands/message/');
await commandClient.run()
//commandClient.on('commandDelete', async ({reply}) => {
// if (reply){
// reply.delete();
// }
//});
})();

View file

@ -5,14 +5,14 @@ module.exports = class BasePaginator extends EventEmitter {
constructor(client, data) {
super();
this.client = client;
this.message = BasePaginator.asMessage(data.message);
this.message = BasePaginator.asMessage(data.context);
this.commandMessage = data.commandMessage || null;
this.pages = data.pages;
this.index = 0;
this.targetUser = data.targetUser || this.message.author.id;
// TODO: use editOrReply, kill old paginator if it exists
this.editOrReply = (data.message.editOrReply || data.message.reply).bind(data.message);
this.editOrReply = data.context.editOrReply.bind(data.context);
}
static asMessage(ctx) {
@ -53,6 +53,8 @@ module.exports = class BasePaginator extends EventEmitter {
// Create Components
let msg = this.pages[this.index];
msg.components = await this.client.components(this)
if(!msg.message_reference) msg.reference = true
if(!msg.allowedMentions) msg.allowedMentions = {parse: [], repliedUser: false}
return this.commandMessage = await this.editOrReply(msg);
}

View file

@ -150,10 +150,21 @@ module.exports = class Paginator {
if (this.pageNumber && Array.isArray(data.pages)) {
for (let i = 0; i < data.pages.length; ++i) {
const element = data.pages[i];
}
}
// Check if a paginator exists, if it does kill the old one
let listener;
for (const l of this.activeListeners) {
if (!(l instanceof InteractionPaginator)) continue;
if (!l.commandMessage) continue;
if (l.isCommandMessage(data.context.message.id)) {
listener = l
}
}
if(listener) await listener.stop()
const instance = new InteractionPaginator(this, data);
this.activeListeners.push(instance);

View file

@ -30,7 +30,7 @@ module.exports = class PaginatorCluster {
}
createPaginator(data) {
const targetPaginator = this.findOrSetPaginator(data.message.client);
const targetPaginator = this.findOrSetPaginator(data.context.client);
return targetPaginator.createPaginator(data);
}