This commit is contained in:
Skillz4Killz
2021-10-24 19:13:23 +00:00
committed by GitHub
parent ebdbfcf721
commit 2427a5d2c8
17 changed files with 293 additions and 211 deletions
+12 -10
View File
@@ -1,21 +1,23 @@
import { eventHandlers } from "../../bot.ts";
import { cacheHandlers } from "../../cache.ts";
import { Bot } from "../../bot.ts";
import type { DiscordGatewayPayload } from "../../types/gateway/gateway_payload.ts";
import type { GuildRoleDelete } from "../../types/guilds/guild_role_delete.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { SnakeCasedPropertiesDeep } from "../../types/util.ts";
export async function handleGuildRoleDelete(data: DiscordGatewayPayload) {
const payload = data.d as GuildRoleDelete;
const guild = await cacheHandlers.get("guilds", snowflakeToBigint(payload.guildId));
export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as SnakeCasedPropertiesDeep<GuildRoleDelete>;
const guildId = bot.transformers.snowflake(payload.guild_id);
const guild = await bot.cache.guilds.get(guildId);
if (!guild) return;
const roleId = snowflakeToBigint(payload.roleId);
const roleId = bot.transformers.snowflake(payload.role_id);
const cachedRole = guild.roles.get(roleId)!;
const cachedRole = guild.roles.get(roleId);
guild.roles.delete(roleId);
if (cachedRole) eventHandlers.roleDelete?.(guild, cachedRole);
await bot.cache.guilds.set(guild.id, guild);
if (cachedRole) bot.events.roleDelete(bot, guild, cachedRole);
// For bots without GUILD_MEMBERS member.roles is never updated breaking permissions checking.
await cacheHandlers.forEach("DELETE_ROLE_FROM_MEMBER", { guildId: guild.id, roleId });
await bot.cache.execute("DELETE_ROLE_FROM_MEMBER", { guildId: guild.id, roleId });
}