fix: chunk rankings if exceeding character limit
This commit is contained in:
parent
e2e4464306
commit
1c0144b076
24
index.js
24
index.js
@ -468,7 +468,7 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
}
|
}
|
||||||
fkAttempts++;
|
fkAttempts++;
|
||||||
const idx = Math.floor(Math.random() * pickingPlayers.length);
|
const idx = Math.floor(Math.random() * pickingPlayers.length);
|
||||||
let fk = pickingPlayers[idx]
|
let fk = pickingPlayers[idx];
|
||||||
if (protectedFk.includes(fk.id)) {
|
if (protectedFk.includes(fk.id)) {
|
||||||
protectedStr += `${fk.id}, `;
|
protectedStr += `${fk.id}, `;
|
||||||
} else {
|
} else {
|
||||||
@ -759,8 +759,12 @@ client.on("interactionCreate", async (interaction) => {
|
|||||||
redPlayers = redPlayers.concat(redBalanced);
|
redPlayers = redPlayers.concat(redBalanced);
|
||||||
|
|
||||||
// sort alphebetically then build string
|
// sort alphebetically then build string
|
||||||
bluPlayers.sort((a, b) => a.player.displayName.localeCompare(b.player.displayName));
|
bluPlayers.sort((a, b) =>
|
||||||
redPlayers.sort((a, b) => a.player.displayName.localeCompare(b.player.displayName));
|
a.player.displayName.localeCompare(b.player.displayName)
|
||||||
|
);
|
||||||
|
redPlayers.sort((a, b) =>
|
||||||
|
a.player.displayName.localeCompare(b.player.displayName)
|
||||||
|
);
|
||||||
|
|
||||||
let teamStr = `${backticks}BLU:`;
|
let teamStr = `${backticks}BLU:`;
|
||||||
for (const player of bluPlayers) {
|
for (const player of bluPlayers) {
|
||||||
@ -988,14 +992,20 @@ client.on("messageCreate", async (message) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// build string
|
// build string
|
||||||
let str = backticks;
|
let str = "";
|
||||||
const maxNameLength = Math.max(...players.map((p) => p.name.length));
|
const maxNameLength = Math.max(...players.map((p) => p.name.length));
|
||||||
for (const { name, rank } of players) {
|
for (const { name, rank } of players) {
|
||||||
str += `${name.padEnd(maxNameLength, " ")} - ${"*".repeat(rank)}\n`;
|
str += `${name.padEnd(maxNameLength, " ")} - ${"*".repeat(rank)}\n`;
|
||||||
}
|
}
|
||||||
str += backticks;
|
if (str === "") str = "No rankings found";
|
||||||
if (str === backticks + backticks) str = "No rankings found";
|
if (str.length > 2000) {
|
||||||
await message.reply(str);
|
let chunks = str.match(/[\s\S]{1,1990}/g);
|
||||||
|
for (let chunk of chunks) {
|
||||||
|
await message.reply(`${backticks}${chunk}${backticks}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await message.reply(`${backticks}${str}${backticks}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
await message.reply(`Error getting rankings: ${error.message}`);
|
await message.reply(`Error getting rankings: ${error.message}`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user