updater: periodically check for updates while open

This commit is contained in:
Vendicated 2025-05-13 22:39:56 +02:00
parent 8c7225d106
commit 59ddf55b99
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
3 changed files with 65 additions and 33 deletions

View file

@ -46,8 +46,6 @@ const ContributorBadge: ProfileBadge = {
let DonorBadges = {} as Record<string, Array<Record<"tooltip" | "badge", string>>>;
async function loadBadges(noCache = false) {
DonorBadges = {};
const init = {} as RequestInit;
if (noCache)
init.cache = "no-cache";
@ -56,6 +54,8 @@ async function loadBadges(noCache = false) {
.then(r => r.json());
}
let intervalId: any;
export default definePlugin({
name: "BadgeAPI",
description: "API to add badges to users.",
@ -89,6 +89,11 @@ export default definePlugin({
}
],
// for access from the console or other plugins
get DonorBadges() {
return DonorBadges;
},
toolboxActions: {
async "Refetch Badges"() {
await loadBadges(true);
@ -104,6 +109,13 @@ export default definePlugin({
async start() {
await loadBadges();
clearInterval(intervalId);
intervalId = setInterval(loadBadges, 1000 * 60 * 30); // 30 minutes
},
async stop() {
clearInterval(intervalId);
},
getBadges(props: { userId: string; user?: User; guildId: string; }) {