From 20160611fd11fd9bf0955e32fbd84f5e7738d4ea Mon Sep 17 00:00:00 2001 From: JOLIMAITRE Matthieu Date: Wed, 1 May 2024 16:48:38 +0200 Subject: [PATCH] fix too long devoir names --- src/bot.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 3df5cd7..ae052df 100755 --- a/src/bot.ts +++ b/src/bot.ts @@ -61,6 +61,7 @@ async function main() { update_display.send(); notification_loop(bot, storage); + log("Oki."); } async function fetch_feed_channel(bot: Client, feed: { channel_id: string }) { @@ -225,7 +226,7 @@ async function handle_autocomplete(interaction: AutocompleteInteraction, storage if (subcommand === "retirer") { const devoirs = await collect(storage.devoirs.list()); const mapped = devoirs.map(([{ id }, value]) => ({ - name: `[${value.subject}] ${value.description}`, + name: trimmed(`[${value.subject}] ${value.description}`, 100), value: id, })); return await interaction.respond(mapped); @@ -233,7 +234,7 @@ async function handle_autocomplete(interaction: AutocompleteInteraction, storage if (subcommand === "éditer") { const devoirs = await collect(storage.devoirs.list()); const mapped = devoirs.map(([{ id }, value]) => ({ - name: `[${value.subject}] ${value.description}`, + name: trimmed(`[${value.subject}] ${value.description}`, 100), value: id, })); return await interaction.respond(mapped); @@ -274,7 +275,6 @@ function format_devoir_title(devoir: Devoir) { async function notification_loop(bot: Client, storage: Storage) { while (true) { - log("Updating notification."); // get all devoirs to notify const devoirs_to_notify = new Set(); const notification_threshold = _7d; @@ -346,8 +346,13 @@ async function notification_loop(bot: Client, storage: Storage) { await message.edit({ embeds: [embed], content: "" }); } - await wait(_1min); + await wait(15 * _1min); } } +function trimmed(text: string, width: number) { + if (text.length < width) return text; + else return text.slice(0, width - 4) + "..."; +} + if (import.meta.main) await main();