diff --git a/commands/message/core/help.js b/commands/message/core/help.js index 1ee1920..aac4efa 100644 --- a/commands/message/core/help.js +++ b/commands/message/core/help.js @@ -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 }); } diff --git a/commands/message/dev/debug/page.js b/commands/message/dev/debug/page.js index bfce9ca..c10b1af 100644 --- a/commands/message/dev/debug/page.js +++ b/commands/message/dev/debug/page.js @@ -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 + }); }, }; \ No newline at end of file diff --git a/commands/message/search/bing-images.js b/commands/message/search/bing-images.js index 6aaa239..f999def 100644 --- a/commands/message/search/bing-images.js +++ b/commands/message/search/bing-images.js @@ -48,9 +48,8 @@ module.exports = { } pages = formatPaginationEmbeds(pages) - const message = context.message const paging = await paginator.createPaginator({ - message, + context, pages }); }catch(e){ diff --git a/commands/message/search/bing.js b/commands/message/search/bing.js index dd60bc1..7025e38 100644 --- a/commands/message/search/bing.js +++ b/commands/message/search/bing.js @@ -44,9 +44,8 @@ module.exports = { } pages = formatPaginationEmbeds(pages) - const message = context.message const paging = await paginator.createPaginator({ - message, + context, pages }); }catch(e){ diff --git a/commands/message/search/google-images.js b/commands/message/search/google-images.js index 72d8370..6c082c8 100644 --- a/commands/message/search/google-images.js +++ b/commands/message/search/google-images.js @@ -48,9 +48,8 @@ module.exports = { } pages = formatPaginationEmbeds(pages) - const message = context.message const paging = await paginator.createPaginator({ - message, + context, pages }); }catch(e){ diff --git a/commands/message/search/google.js b/commands/message/search/google.js index 684d35b..dda89a9 100644 --- a/commands/message/search/google.js +++ b/commands/message/search/google.js @@ -45,9 +45,8 @@ module.exports = { } pages = formatPaginationEmbeds(pages) - const message = context.message const paging = await paginator.createPaginator({ - message, + context, pages }); }catch(e){ diff --git a/commands/message/search/lyrics.js b/commands/message/search/lyrics.js index be57736..cd4ff10 100644 --- a/commands/message/search/lyrics.js +++ b/commands/message/search/lyrics.js @@ -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; diff --git a/commands/message/search/wolfram-alpha.js b/commands/message/search/wolfram-alpha.js index 4bc7bf2..ee99468 100644 --- a/commands/message/search/wolfram-alpha.js +++ b/commands/message/search/wolfram-alpha.js @@ -46,9 +46,8 @@ module.exports = { } pages = formatPaginationEmbeds(pages) - const message = context.message const paging = await paginator.createPaginator({ - message, + context, pages }); }catch(e){ diff --git a/commands/message/search/youtube.js b/commands/message/search/youtube.js index 7c234f1..b3b15f4 100644 --- a/commands/message/search/youtube.js +++ b/commands/message/search/youtube.js @@ -47,9 +47,8 @@ module.exports = { } pages = formatPaginationEmbeds(pages) - const message = context.message const paging = await paginator.createPaginator({ - message, + context, pages }); }catch(e){ diff --git a/labscore/client.js b/labscore/client.js index 18c7213..3e05589 100644 --- a/labscore/client.js +++ b/labscore/client.js @@ -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(); - // } - //}); })(); diff --git a/labscore/paginator/structures/BasePaginator.js b/labscore/paginator/structures/BasePaginator.js index fe84f92..9c2d734 100644 --- a/labscore/paginator/structures/BasePaginator.js +++ b/labscore/paginator/structures/BasePaginator.js @@ -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); } diff --git a/labscore/paginator/structures/Paginator.js b/labscore/paginator/structures/Paginator.js index c0fba10..fa72f57 100644 --- a/labscore/paginator/structures/Paginator.js +++ b/labscore/paginator/structures/Paginator.js @@ -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); diff --git a/labscore/paginator/structures/PaginatorCluster.js b/labscore/paginator/structures/PaginatorCluster.js index 05d9624..4d55bbf 100644 --- a/labscore/paginator/structures/PaginatorCluster.js +++ b/labscore/paginator/structures/PaginatorCluster.js @@ -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); }