Skip to content

Commit

Permalink
fix(pencil): custom command listing not always dumping properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno authored May 17, 2018
1 parent 3387dae commit c9d3cd1
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/commands/CustomCommands/ListCustomCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,19 @@ class ListCustomCommand extends Command {
}

async run(message) {
const ccs = (await this.settings.getCustomCommandsForGuild(message.guild))
.map(cc => ({ call: cc.call, response: cc.response }));

const longest = ccs.map(cc => cc.call)
.reduce((a, b) => (a.length > b.length ? a : b)).length;
const subGroupCCs = createGroupedArray(ccs.map(cc => `\`${rpad(cc.call, longest, ' ')} | ${decodeURIComponent(cc.response)}\``), 5);
const metaGroups = createGroupedArray(subGroupCCs, 4);
const ccs = [];
const gcc = await this.settings.getCustomCommandsForGuild(message.guild);
gcc.forEach((cc) => {
if (cc.response.length > 1024) {
ccs.push({ name: cc.call, value: decodeURIComponent(cc.response.substring(0, 1020))});
ccs.push({ name: '_ _', value: decodeURIComponent(cc.response.substring(1021))});
} else {
ccs.push({ name: cc.call, value: decodeURIComponent(cc.response)});
}
});
const metaGroups = createGroupedArray(ccs, 10);
metaGroups.forEach((metaGroup) => {
this.messageManager.embed(message, {
fields: metaGroup.map(ccGroup => ({
name: '_ _',
value: ccGroup.join('\n'),
})),
}, true, false);
this.messageManager.embed(message, { color: 0x301934, fields: metaGroup }, true, false);
});

return this.messageManager.statuses.SUCCESS;
Expand Down

0 comments on commit c9d3cd1

Please sign in to comment.