[BREAKING] Switch from rename channel to delete channel
Reason: rate limits by Discord suck :(
This commit is contained in:
parent
ee9039c239
commit
c3b0a4316b
@ -10,7 +10,6 @@ import { Color, Emoji } from "../tools/design";
|
|||||||
client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
||||||
if (oldChannel.isDMBased() || newChannel.isDMBased()) return;
|
if (oldChannel.isDMBased() || newChannel.isDMBased()) return;
|
||||||
const name = newChannel.name.toLowerCase();
|
const name = newChannel.name.toLowerCase();
|
||||||
if (name === "censored") return;
|
|
||||||
|
|
||||||
const guild = oldChannel.guild;
|
const guild = oldChannel.guild;
|
||||||
const settings = await getGuildSetting(guild.id);
|
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;
|
const logChannel = settings.notificationChannelID ? await getGuildChannel(guild.id, settings.notificationChannelID) : null;
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
if (!logChannel || !logChannel.isTextBased()) return;
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
const embed = getFailedEmbed();
|
const embed = getFailedEmbed();
|
||||||
embed.setDescription(`Couldn't censor <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
|
embed.setDescription(`Couldn't delete <#${newChannel.id}> (${newChannel.id}): ${error instanceof Error ? error.message : error}`);
|
||||||
if (isPremium) embed.addFields({
|
embed.addFields({
|
||||||
name: "Detected banned word:",
|
name: "Detected banned word:",
|
||||||
value: `||${found}||`
|
value: `||${found}||`
|
||||||
},{
|
|
||||||
name: "Old channel name:",
|
|
||||||
value: `||${name}||`,
|
|
||||||
inline: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
@ -66,16 +62,12 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
|
|||||||
if (!logChannel || !logChannel.isTextBased()) return;
|
if (!logChannel || !logChannel.isTextBased()) return;
|
||||||
const embed = getDefaultEmbed();
|
const embed = getDefaultEmbed();
|
||||||
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);
|
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.setColor(Color.WARNING_YELLOW);
|
||||||
embed.addFields({
|
embed.addFields({
|
||||||
name: "Detected banned word:",
|
name: "Detected banned word:",
|
||||||
value: `||${found}||`,
|
value: `||${found}||`,
|
||||||
inline: true
|
inline: true
|
||||||
},{
|
|
||||||
name: "Old channel name:",
|
|
||||||
value: `||${name}||`,
|
|
||||||
inline: true
|
|
||||||
});
|
});
|
||||||
|
|
||||||
logChannel.send({
|
logChannel.send({
|
||||||
|
Loading…
Reference in New Issue
Block a user