Browse Source

Add rudimentary pagination for viewing feeds

master
benji7425 3 years ago
parent
commit
4c7d826b52
  1. 4
      CHANGELOG.md
  2. 9
      app/commands/view-feeds.js
  3. 4
      discord-bot-core/Client.js
  4. 2
      discord-bot-core/HandleMessage.js

4
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

9
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);
}

4
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 => {

2
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;

Loading…
Cancel
Save