fix too long devoir names

This commit is contained in:
JOLIMAITRE Matthieu 2024-05-01 16:48:38 +02:00
parent 2a8700ef04
commit 20160611fd

View file

@ -61,6 +61,7 @@ async function main() {
update_display.send(); update_display.send();
notification_loop(bot, storage); notification_loop(bot, storage);
log("Oki.");
} }
async function fetch_feed_channel(bot: Client<boolean>, feed: { channel_id: string }) { async function fetch_feed_channel(bot: Client<boolean>, feed: { channel_id: string }) {
@ -225,7 +226,7 @@ async function handle_autocomplete(interaction: AutocompleteInteraction, storage
if (subcommand === "retirer") { if (subcommand === "retirer") {
const devoirs = await collect(storage.devoirs.list()); const devoirs = await collect(storage.devoirs.list());
const mapped = devoirs.map(([{ id }, value]) => ({ const mapped = devoirs.map(([{ id }, value]) => ({
name: `[${value.subject}] ${value.description}`, name: trimmed(`[${value.subject}] ${value.description}`, 100),
value: id, value: id,
})); }));
return await interaction.respond(mapped); return await interaction.respond(mapped);
@ -233,7 +234,7 @@ async function handle_autocomplete(interaction: AutocompleteInteraction, storage
if (subcommand === "éditer") { if (subcommand === "éditer") {
const devoirs = await collect(storage.devoirs.list()); const devoirs = await collect(storage.devoirs.list());
const mapped = devoirs.map(([{ id }, value]) => ({ const mapped = devoirs.map(([{ id }, value]) => ({
name: `[${value.subject}] ${value.description}`, name: trimmed(`[${value.subject}] ${value.description}`, 100),
value: id, value: id,
})); }));
return await interaction.respond(mapped); return await interaction.respond(mapped);
@ -274,7 +275,6 @@ function format_devoir_title(devoir: Devoir) {
async function notification_loop(bot: Client, storage: Storage) { async function notification_loop(bot: Client, storage: Storage) {
while (true) { while (true) {
log("Updating notification.");
// get all devoirs to notify // get all devoirs to notify
const devoirs_to_notify = new Set<string>(); const devoirs_to_notify = new Set<string>();
const notification_threshold = _7d; const notification_threshold = _7d;
@ -346,8 +346,13 @@ async function notification_loop(bot: Client, storage: Storage) {
await message.edit({ embeds: [embed], content: "" }); 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(); if (import.meta.main) await main();