From e07ebed824c9c21df516d7c2ac4deb001e95528f Mon Sep 17 00:00:00 2001 From: Bsian Date: Sat, 19 Oct 2019 12:47:08 +0100 Subject: [PATCH] Added embed field splitter --- src/Util.ts | 10 ++++++++++ src/commands/help.ts | 1 + src/commands/modlogs.ts | 6 +----- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Util.ts b/src/Util.ts index 9564405..b7bcee8 100644 --- a/src/Util.ts +++ b/src/Util.ts @@ -42,4 +42,14 @@ export default class Util { if (message) message.channel.createMessage(`***${this.client.stores.emojis.error} An unexpected error has occured - please contact a member of the Engineering Team.${command ? ' This command has been disabled.' : ''}***`); return stack; } + + public splitFields(fields: {name: string, value: string, inline?: boolean}[]): {name: string, value: string, inline?: boolean}[][] { + let index = 0; + const array: {name: string, value: string, inline?: boolean}[][] = [[]]; + while (fields.length) { + if (array[index].length >= 25) { index += 1; array[index] = []; } + array[index].push(fields[0]); fields.shift(); + } + return array; + } } diff --git a/src/commands/help.ts b/src/commands/help.ts index 54df6a5..e73c34e 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -32,6 +32,7 @@ export default class Help extends Command { const embed = new RichEmbed(); embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); embed.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL); + embed.setDescription(`Command list for ${this.client.user.username}`); } } } diff --git a/src/commands/modlogs.ts b/src/commands/modlogs.ts index cf13a93..3deb738 100644 --- a/src/commands/modlogs.ts +++ b/src/commands/modlogs.ts @@ -22,7 +22,6 @@ export default class Modlogs extends Command { const query = await this.client.db.Moderation.find({ $or: [{ account: args.join(' ') }, { userID: args.filter((a) => a)[0].replace(/[<@!>]/g, '') }] }); if (!query.length) return msg.edit(`***${this.client.stores.emojis.error} Cannot locate modlogs for ${args.join(' ')}***`); - let index = 0; const logs: {name: string, value: string, inline: boolean}[][] = [[]]; const formatted = query.map((log) => { const { account, moderatorID, reason, type, date } = log; const name = type; @@ -32,10 +31,7 @@ export default class Modlogs extends Command { }); const users = [...new Set(query.map((log) => log.userID))].map((u) => `<@${u}>`); - while (query.length) { - if (logs[index].length >= 25) { index += 1; logs[index] = []; } - logs[index].push(formatted[0]); formatted.shift(); - } + const logs = this.util.splitFields(formatted); const embeds = logs.map((l) => { const embed = new RichEmbed();