mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-17 02:17:03 -04:00
updater: periodically check for updates while open
This commit is contained in:
parent
8c7225d106
commit
59ddf55b99
3 changed files with 65 additions and 33 deletions
|
@ -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; }) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue