Skip to content
Snippets Groups Projects
Commit 8475385d authored by Valtteri Aarnio's avatar Valtteri Aarnio
Browse files

Week menus that exceed 2000 character limit now split into multiple messages

parent 5d0f0aeb
No related branches found
No related tags found
No related merge requests found
Pipeline #63103 passed
......@@ -103,13 +103,23 @@ let command = {
fetch(`http://127.0.0.1:5000/restaurants/${restaurantEntryId}/week`)
.then(r => r.json())
.then(data => {
let output = `**This weeks menu for restaurant id ${restaurantEntryId}:**\n`;
let messageIndex = 0;
const messages: string[] = [`**This weeks menu for restaurant id ${restaurantEntryId}:**\n`];
for(const [key, value] of Object.entries(data)){
const menu = Object(value);
output += `__**Day ${key}:**__\n` + menuToString(menu) + "\n";
const daymenu = `__**Day ${key}:**__\n` + menuToString(menu) + "\n";
// Messages must be less than 2000 characters in length, breaking messages into parts if max length is exceeded.
if(messages[messageIndex].length + daymenu.length <= 2000){
messages[messageIndex] += daymenu;
} else {
console.log(messages[messageIndex]);
interaction.followUp(messages[messageIndex]);
messages[++messageIndex] = `Command response part ${messageIndex + 1} (Maximum Discord message length exceeded)\n` + daymenu;
}
}
console.log(output);
interaction.followUp(output);
console.log(messages[messageIndex]);
interaction.followUp(messages[messageIndex]);
})
.catch(e => {
console.error(e);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment