mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 10:49:20 +00:00
Fixed cache not updating on guild join
This commit is contained in:
+16
-9
@@ -1,3 +1,4 @@
|
||||
import { Guild } from ".prisma/client";
|
||||
import { Message } from "discord.js";
|
||||
import Logger from "../libs/Logger";
|
||||
import Cache from "../providers/Cache";
|
||||
@@ -17,21 +18,27 @@ export default class Core {
|
||||
skipDuplicates: true
|
||||
});
|
||||
|
||||
// TODO : Make it cache guild on join
|
||||
|
||||
await Cache.updateGuildsCache();
|
||||
// TODO: Better timer
|
||||
setInterval(() => {
|
||||
Cache.updateGuildsCache();
|
||||
}, 5 * 60 * 1000)
|
||||
|
||||
if(DiscordProvider.client.user)
|
||||
DiscordProvider.client.user.setActivity("your heartbeat 💗", {
|
||||
type: "LISTENING"
|
||||
});
|
||||
|
||||
|
||||
DiscordProvider.client.user!.setActivity("your heartbeat 💗", {
|
||||
type: "LISTENING"
|
||||
});
|
||||
|
||||
Logger.info('Core started successfully');
|
||||
|
||||
}
|
||||
async guildCreate(guild: Guild) {
|
||||
if(await Prisma.client.guild.findFirst({ where: {id: guild.id} })) return;
|
||||
|
||||
await Prisma.client.guild.create({
|
||||
data: {
|
||||
id: guild.id
|
||||
}
|
||||
});
|
||||
|
||||
await Cache.updateGuildCache(guild.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Snowflake } from "discord-api-types";
|
||||
import Prisma from "./Prisma";
|
||||
|
||||
class Cache {
|
||||
@@ -19,6 +20,13 @@ class Cache {
|
||||
}
|
||||
}
|
||||
|
||||
public async updateGuildCache(guildID: Snowflake) {
|
||||
const DBGuild = await Prisma.client.guild.findFirst({ where:{id: guildID} });
|
||||
|
||||
if(DBGuild === null) return;
|
||||
this.setGuildData(guildID, DBGuild);
|
||||
}
|
||||
|
||||
public setGuildData(id: string, data: Object): void {
|
||||
this.cache.Guilds[id] = data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user