From db86cacaa08ae78cdac0eddec21e37d12fed846e Mon Sep 17 00:00:00 2001 From: benji7425 Date: Mon, 27 Nov 2017 00:02:39 +0000 Subject: [PATCH] Add rudimentary pagination for viewing feeds --- CHANGELOG.md | 4 ++++ app/commands/view-feeds.js | 9 ++++++++- discord-bot-core/Client.js | 4 ---- discord-bot-core/HandleMessage.js | 2 -- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69c34f..f46872e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fix articles not posting if contents too long for a single discord message + ## v3.1.2 ### Fixed diff --git a/app/commands/view-feeds.js b/app/commands/view-feeds.js index 1ff56c3..1640761 100644 --- a/app/commands/view-feeds.js +++ b/app/commands/view-feeds.js @@ -12,5 +12,12 @@ function invoke({ message, params, guildData, client }) { if (!guildData) return Promise.reject("Guild not setup"); - return Promise.resolve(guildData.feeds.map(f => f.toString()).join("\n")); + const numToShow = 10; + const startIdx = params[0] ? (params[0] - 1) * numToShow : 0; + const endIdx = startIdx + numToShow + 1; + + let responseStr = guildData.feeds.map(f => f.toString()).slice(startIdx, endIdx).join("\n"); + if (guildData.feeds.length > endIdx) + responseStr += `Use *view-feeds ${startIdx + 2}* to view more`; + return Promise.resolve(responseStr); } \ No newline at end of file diff --git a/discord-bot-core/Client.js b/discord-bot-core/Client.js index 1710a51..c9737bc 100644 --- a/discord-bot-core/Client.js +++ b/discord-bot-core/Client.js @@ -92,10 +92,6 @@ module.exports = class Client extends Discord.Client { err => { if (err) CoreUtil.dateError(`Error writing data file! ${err.message || err}`); }); } - /** - * @param {*} json - * @param {*} guildDataModel - */ fromJSON(json) { const guildsData = Object.keys(json); guildsData.forEach(guildID => { diff --git a/discord-bot-core/HandleMessage.js b/discord-bot-core/HandleMessage.js index 2b83d33..aed8254 100644 --- a/discord-bot-core/HandleMessage.js +++ b/discord-bot-core/HandleMessage.js @@ -4,7 +4,6 @@ const ParentPackageJSON = require("../package.json"); // @ts-ignore const InternalConfig = require("./internal-config.json"); -/**@param param*/ function handleMessage(client, message, commands, guildData) { if (!message.content.startsWith(message.guild.me.toString()) //criteria for a command is the bot being tagged && !message.content.startsWith(message.guild.me.toString().replace("!", ""))) //hacky fix for android mentions not including an exclamation mark @@ -33,7 +32,6 @@ function handleMessage(client, message, commands, guildData) { }); } -/**@param param*/ function handleInternalCommand(message, split, commands, isMemberAdmin) { if (!split[1]) return;