Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

Commit

Permalink
fix chunking
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasptsch committed Mar 5, 2022
1 parent 79b4241 commit 731ffd3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/commands/alias.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Embed, SlashCommandBuilder } from "@discordjs/builders";
import { Command } from "../Command";
import { checkManager } from "../utils/conditions";
import { logger } from "../utils/logger";
import {
deleteAlias,
listAliases,
Expand Down Expand Up @@ -69,12 +70,22 @@ export const alias: Command = {

case "list":
const aliases = await listAliases(interaction.guildId);
const numsPerGroup = Math.ceil(aliases.length / 25);
const results = new Array().map((_, i) =>
aliases.slice(i * numsPerGroup, (i + 1) * numsPerGroup)
);
const embeds = results.map((result) =>
new Embed().addFields(...result).setTitle("Alias List")
const chunk = (arr, size) => {
const res = [];
for(let i = 0; i < arr.length; i++) {
if(i % size === 0){
// Push a new array containing the current value to the res array
res.push([arr[i]]);
}
else{
// Push the current value to the current array
res[res.length-1].push(arr[i]);
};
};
return res;
};
const embeds = chunk(aliases, 25).map((result) =>
new Embed().addFields(...result)
);
interaction.reply({
content: `Alias List`,
Expand Down

0 comments on commit 731ffd3

Please sign in to comment.