3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 08:45:03 +00:00
zeppelin/backend/src/plugins/Slowmode/util/clearBotSlowmodeFromUserId.ts
2021-07-04 17:41:44 +02:00

24 lines
970 B
TypeScript

import { GuildChannel, Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { SlowmodePluginType } from "../types";
export async function clearBotSlowmodeFromUserId(
pluginData: GuildPluginData<SlowmodePluginType>,
channel: GuildChannel & TextChannel,
userId: string,
force = false,
) {
try {
// Remove permission overrides from the channel for this user
// Previously we diffed the overrides so we could clear the "send messages" override without touching other
// overrides. Unfortunately, it seems that was a bit buggy - we didn't always receive the event for the changed
// overrides and then we also couldn't diff against them. For consistency's sake, we just delete the override now.
await channel.permissionOverwrites.resolve(userId as Snowflake)?.delete();
} catch (e) {
if (!force) {
throw e;
}
}
await pluginData.state.slowmodes.clearSlowmodeUser(channel.id, userId);
}