Merge branch 'main' into threads

This commit is contained in:
ITOH
2021-05-03 20:50:53 +02:00
192 changed files with 1364 additions and 623 deletions
+10 -5
View File
@@ -3,21 +3,25 @@ import { cacheHandlers } from "../../cache.ts";
import { Channel } from "../../types/channels/channel.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
export async function handleChannelDelete(data: DiscordGatewayPayload) {
const payload = data.d as Channel;
const cachedChannel = await cacheHandlers.get("channels", payload.id);
const cachedChannel = await cacheHandlers.get(
"channels",
snowflakeToBigint(payload.id),
);
if (!cachedChannel) return;
if (
cachedChannel.type === DiscordChannelTypes.GuildVoice && payload.guildId
) {
const guild = await cacheHandlers.get("guilds", payload.guildId);
const guild = await cacheHandlers.get("guilds", cachedChannel.guildId);
if (guild) {
return Promise.all(guild.voiceStates.map(async (vs, key) => {
if (vs.channelId !== payload.id) return;
if (vs.channelId !== cachedChannel.id) return;
// Since this channel was deleted all voice states for this channel should be deleted
guild.voiceStates.delete(key);
@@ -38,18 +42,19 @@ export async function handleChannelDelete(data: DiscordGatewayPayload) {
DiscordChannelTypes.GuildNews,
].includes(payload.type)
) {
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
cacheHandlers.forEach("messages", (message) => {
eventHandlers.debug?.(
"loop",
`Running forEach messages loop in CHANNEL_DELTE file.`,
);
if (message.channelId === payload.id) {
if (message.channelId === snowflakeToBigint(payload.id)) {
cacheHandlers.delete("messages", message.id);
}
});
}
await cacheHandlers.delete("channels", payload.id);
await cacheHandlers.delete("channels", snowflakeToBigint(payload.id));
eventHandlers.channelDelete?.(cachedChannel);
}