Fix cache plugin doesn't update voice state update (#2388)

* Fix cache plugin doesn't update voice state update

* fix putting fix in wrong file

* deno fmt

* delete voice state

* deno fmt

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
LTS20050703
2022-08-25 22:43:33 +07:00
committed by GitHub
parent b89d3ca078
commit 1ea2a81363
2 changed files with 34 additions and 2 deletions

View File

@@ -5,6 +5,7 @@ import type {
DiscordMessageReactionAdd,
DiscordMessageReactionRemove,
DiscordMessageReactionRemoveAll,
DiscordVoiceState,
} from "../deps.ts";
import type { BotWithCache } from "./addCacheCollections.ts";
@@ -15,6 +16,7 @@ export function setupCacheEdits<B extends Bot>(bot: BotWithCache<B>) {
MESSAGE_REACTION_ADD,
MESSAGE_REACTION_REMOVE,
MESSAGE_REACTION_REMOVE_ALL,
VOICE_STATE_UPDATE,
} = bot.handlers;
bot.handlers.GUILD_MEMBER_ADD = function (_, data, shardId) {
@@ -116,4 +118,18 @@ export function setupCacheEdits<B extends Bot>(bot: BotWithCache<B>) {
MESSAGE_REACTION_REMOVE_ALL(bot, data, shardId);
};
bot.handlers.VOICE_STATE_UPDATE = (_, data, shardId) => {
const payload = data.d as DiscordVoiceState;
if (!payload.guild_id) return;
const vs = bot.transformers.voiceState(bot, {
voiceState: payload,
guildId: bot.transformers.snowflake(payload.guild_id),
});
bot.guilds.get(vs.guildId)?.voiceStates.set(vs.userId, vs);
VOICE_STATE_UPDATE(bot, data, shardId);
};
}