[BREAKING] Switch from rename channel to delete channel

Reason: rate limits by Discord suck :(
This commit is contained in:
Lukas | AstroGD 2022-11-29 01:57:34 +01:00
parent ee9039c239
commit c3b0a4316b
Signed by: AstroGD
GPG Key ID: 82A5E6C236C535AA

View File

@ -10,7 +10,6 @@ import { Color, Emoji } from "../tools/design";
client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
if (oldChannel.isDMBased() || newChannel.isDMBased()) return;
const name = newChannel.name.toLowerCase();
if (name === "censored") return;
const guild = oldChannel.guild;
const settings = await getGuildSetting(guild.id);
@ -43,18 +42,15 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null;
try {
await newChannel.setName("CENSORED", `[Automated] Detected blocked word in channel name. Name has been censored`);
if (!newChannel.deletable) throw new Error("Missing permissions to delete channel");
await newChannel.delete("[Automated] Detected blocked word in channel name");
} catch (error) {
if (!logChannel || !logChannel.isTextBased()) return;
const embed = getFailedEmbed();
embed.setDescription(`Couldn't censor <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
if (isPremium) embed.addFields({
embed.setDescription(`Couldn't delete <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
embed.addFields({
name: "Detected banned word:",
value: `||${found}||`
},{
name: "Old channel name:",
value: `||${name}||`,
inline: true
});
logChannel.send({
@ -66,16 +62,12 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
if (!logChannel || !logChannel.isTextBased()) return;
const embed = getDefaultEmbed();
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);
embed.setDescription(`<#${newChannel.id}> (${newChannel.id}) has been renamed because its name contained a blocked word.`);
embed.setDescription(`||#${newChannel.name}|| (${newChannel.id}) has been deleted because its name contained a blocked word.`);
embed.setColor(Color.WARNING_YELLOW);
embed.addFields({
name: "Detected banned word:",
value: `||${found}||`,
inline: true
},{
name: "Old channel name:",
value: `||${name}||`,
inline: true
});
logChannel.send({