mirror of
https://github.com/kirameki-cafe/Yumi.git
synced 2026-09-13 18:59:19 +00:00
Fixed cache not updating on guild join
This commit is contained in:
+15
-8
@@ -1,3 +1,4 @@
|
|||||||
|
import { Guild } from ".prisma/client";
|
||||||
import { Message } from "discord.js";
|
import { Message } from "discord.js";
|
||||||
import Logger from "../libs/Logger";
|
import Logger from "../libs/Logger";
|
||||||
import Cache from "../providers/Cache";
|
import Cache from "../providers/Cache";
|
||||||
@@ -17,21 +18,27 @@ export default class Core {
|
|||||||
skipDuplicates: true
|
skipDuplicates: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO : Make it cache guild on join
|
|
||||||
|
|
||||||
await Cache.updateGuildsCache();
|
await Cache.updateGuildsCache();
|
||||||
// TODO: Better timer
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
Cache.updateGuildsCache();
|
Cache.updateGuildsCache();
|
||||||
}, 5 * 60 * 1000)
|
}, 5 * 60 * 1000)
|
||||||
|
|
||||||
if(DiscordProvider.client.user)
|
DiscordProvider.client.user!.setActivity("your heartbeat 💗", {
|
||||||
DiscordProvider.client.user.setActivity("your heartbeat 💗", {
|
type: "LISTENING"
|
||||||
type: "LISTENING"
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Logger.info('Core started successfully');
|
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";
|
import Prisma from "./Prisma";
|
||||||
|
|
||||||
class Cache {
|
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 {
|
public setGuildData(id: string, data: Object): void {
|
||||||
this.cache.Guilds[id] = data;
|
this.cache.Guilds[id] = data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user