ignore devoirs older than a week

This commit is contained in:
JOLIMAITRE Matthieu 2024-05-16 19:35:44 +02:00
parent 5e567893d2
commit ad3a06ee9f
2 changed files with 8 additions and 5 deletions

View file

@ -2,7 +2,7 @@ import { Client, EmbedBuilder } from "npm:discord.js";
import { fetch_feed_channel, format_devoir_title } from "./lib.ts"; import { fetch_feed_channel, format_devoir_title } from "./lib.ts";
import { Devoir, Feed, Storage } from "./storage.ts"; import { Devoir, Feed, Storage } from "./storage.ts";
import { Channel, collect, log_from } from "./utils.ts"; import { _1d, Channel, collect, log_from } from "./utils.ts";
const log = log_from(import.meta); const log = log_from(import.meta);
@ -20,6 +20,7 @@ async function get_devoirs_sorted(storage: Storage) {
const devoirs = await collect(storage.devoirs.list()); const devoirs = await collect(storage.devoirs.list());
const sorted_devoirs = devoirs const sorted_devoirs = devoirs
.map(([_, d]) => d) .map(([_, d]) => d)
.filter((d) => d.date >= Date.now() - (7 * _1d))
.toSorted((a, b) => a.date > b.date ? 1 : -1); .toSorted((a, b) => a.date > b.date ? 1 : -1);
return sorted_devoirs; return sorted_devoirs;
} }

View file

@ -211,7 +211,9 @@ async function handle_autocomplete_devoir(interaction: AutocompleteInteraction,
async function autocomplete_with_devoirs(storage: Storage, interaction: AutocompleteInteraction) { async function autocomplete_with_devoirs(storage: Storage, interaction: AutocompleteInteraction) {
const devoirs = await collect(storage.devoirs.list()); const devoirs = await collect(storage.devoirs.list());
const mapped = devoirs.map(([{ id }, { subject, description }]) => ({ const mapped = devoirs
.filter(([, d]) => d.date >= Date.now() - (7 * _1d))
.map(([{ id }, { subject, description }]) => ({
name: trimmed(`[${subject}] ${description}`, 100), name: trimmed(`[${subject}] ${description}`, 100),
value: id, value: id,
})); }));