ignore devoirs older than a week
This commit is contained in:
parent
5e567893d2
commit
ad3a06ee9f
2 changed files with 8 additions and 5 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,9 +211,11 @@ 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
|
||||||
name: trimmed(`[${subject}] ${description}`, 100),
|
.filter(([, d]) => d.date >= Date.now() - (7 * _1d))
|
||||||
value: id,
|
.map(([{ id }, { subject, description }]) => ({
|
||||||
}));
|
name: trimmed(`[${subject}] ${description}`, 100),
|
||||||
|
value: id,
|
||||||
|
}));
|
||||||
await interaction.respond(mapped);
|
await interaction.respond(mapped);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue