mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
start adding lil cache
This commit is contained in:
48
src/bot.ts
48
src/bot.ts
@@ -21,7 +21,7 @@ import { DiscordenoChannel, transformChannel } from "./transformers/channel.ts";
|
||||
import { transformVoiceState } from "./transformers/voice_state.ts";
|
||||
import { transformRole } from "./transformers/role.ts";
|
||||
import { transformMessage } from "./transformers/message.ts";
|
||||
import { transformGuild } from "./transformers/guild.ts";
|
||||
import { DiscordenoGuild, transformGuild } from "./transformers/guild.ts";
|
||||
import { DiscordenoShard } from "./ws/ws.ts";
|
||||
import { startGateway } from "./ws/start_gateway.ts";
|
||||
import { spawnShards } from "./ws/spawn_shards.ts";
|
||||
@@ -63,6 +63,52 @@ export async function createBot(options: CreateBotOptions) {
|
||||
isReady: false,
|
||||
activeGuildIds: new Set<bigint>(),
|
||||
constants: createBotConstants(),
|
||||
cache: {
|
||||
guilds: {
|
||||
get: async function (id: bigint): Promise<DiscordenoGuild | undefined> {
|
||||
return {} as any as DiscordenoGuild;
|
||||
},
|
||||
has: async function (id: bigint): Promise<boolean> {
|
||||
return false;
|
||||
},
|
||||
set: async function (id: bigint, guild: DiscordenoGuild): Promise<void> {
|
||||
return;
|
||||
},
|
||||
},
|
||||
channels: {
|
||||
get: async function (id: bigint): Promise<DiscordenoChannel | undefined> {
|
||||
return {} as any as DiscordenoChannel;
|
||||
},
|
||||
has: async function (id: bigint): Promise<boolean> {
|
||||
return false;
|
||||
},
|
||||
set: async function (id: bigint, guild: DiscordenoChannel): Promise<void> {
|
||||
return;
|
||||
},
|
||||
},
|
||||
dispatchedGuildIds: {
|
||||
has: async function (id: bigint): Promise<boolean> {
|
||||
return false;
|
||||
},
|
||||
set: async function (id: bigint): Promise<void> {
|
||||
return;
|
||||
},
|
||||
delete: async function (id: bigint): Promise<void> {
|
||||
return;
|
||||
},
|
||||
},
|
||||
dispatchedChannelIds: {
|
||||
has: async function (id: bigint): Promise<boolean> {
|
||||
return false;
|
||||
},
|
||||
set: async function (id: bigint): Promise<void> {
|
||||
return;
|
||||
},
|
||||
delete: async function (id: bigint): Promise<void> {
|
||||
return;
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { DiscordenoRole, transformRole } from "./role.ts";
|
||||
import { DiscordenoVoiceState, transformVoiceState } from "./voice_state.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||
|
||||
export function transformGuild(bot: Bot, payload: { guild: SnakeCasedPropertiesDeep<Guild> } & { shardId: number }) {
|
||||
export function transformGuild(bot: Bot, payload: { guild: SnakeCasedPropertiesDeep<Guild> } & { shardId: number }): DiscordenoGuild {
|
||||
return {
|
||||
afkTimeout: payload.guild.afk_timeout,
|
||||
approximateMemberCount: payload.guild.approximate_member_count,
|
||||
|
||||
@@ -22,7 +22,7 @@ export async function dispatchRequirements(bot: Bot, data: DiscordGatewayPayload
|
||||
if (!id || bot.activeGuildIds.has(id)) return;
|
||||
|
||||
// If this guild is in cache, it has not been swept and we can cancel
|
||||
if (bot.guilds.has(id)) {
|
||||
if (await bot.cache.guilds.has(id)) {
|
||||
bot.activeGuildIds.add(id);
|
||||
return;
|
||||
}
|
||||
@@ -77,18 +77,18 @@ export async function dispatchRequirements(bot: Bot, data: DiscordGatewayPayload
|
||||
);
|
||||
}
|
||||
|
||||
const guild = await bot.transformers.guild(bot, {
|
||||
const guild = bot.transformers.guild(bot, {
|
||||
...rawGuild,
|
||||
member_count: rawGuild.approximateMemberCount,
|
||||
shardId,
|
||||
});
|
||||
|
||||
// Add to cache
|
||||
bot.guilds.set(id, guild);
|
||||
bot.dispatchedGuildIds.delete(id);
|
||||
await bot.cache.guilds.set(id, guild);
|
||||
bot.cache.dispatchedGuildIds.delete(id);
|
||||
channels.forEach((channel) => {
|
||||
bot.dispatchedChannelIds.delete(channel.id);
|
||||
bot.channels.set(channel.id, channel);
|
||||
bot.cache.dispatchedChannelIds.delete(channel.id);
|
||||
bot.cache.channels.set(channel.id, channel);
|
||||
});
|
||||
|
||||
processing.delete(id);
|
||||
|
||||
Reference in New Issue
Block a user