forked from epita/ruche-manager
fix too long devoir names
This commit is contained in:
parent
2a8700ef04
commit
20160611fd
1 changed files with 9 additions and 4 deletions
13
src/bot.ts
13
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<boolean>, 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<string>();
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue