Rework bot function #13

Merged
AstroGD merged 15 commits from feature/12-show-warning-if-logchannel-is-unreachable into dev 2022-11-29 03:07:01 +01:00
Showing only changes of commit c3b0a4316b - Show all commits

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({