1
0
Fork 0

Added embed field splitter

refactor/models
Bsian 2019-10-19 12:47:08 +01:00
parent 126c3253b2
commit e07ebed824
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
3 changed files with 12 additions and 5 deletions

View File

@ -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.' : ''}***`); 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; 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;
}
} }

View File

@ -32,6 +32,7 @@ export default class Help extends Command {
const embed = new RichEmbed(); const embed = new RichEmbed();
embed.setTimestamp(); embed.setFooter(`Requested by ${message.author.username}#${message.author.discriminator}`, message.author.avatarURL); 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.setAuthor(`${this.client.user.username}#${this.client.user.discriminator}`, this.client.user.avatarURL);
embed.setDescription(`Command list for ${this.client.user.username}`);
} }
} }
} }

View File

@ -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, '') }] }); 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(' ')}***`); 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 formatted = query.map((log) => {
const { account, moderatorID, reason, type, date } = log; const { account, moderatorID, reason, type, date } = log;
const name = type; 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}>`); const users = [...new Set(query.map((log) => log.userID))].map((u) => `<@${u}>`);
while (query.length) { const logs = this.util.splitFields(formatted);
if (logs[index].length >= 25) { index += 1; logs[index] = []; }
logs[index].push(formatted[0]); formatted.shift();
}
const embeds = logs.map((l) => { const embeds = logs.map((l) => {
const embed = new RichEmbed(); const embed = new RichEmbed();