V1.0.0-beta.1 #1
1
index.ts
1
index.ts
@ -6,6 +6,7 @@ swapConsole();
|
|||||||
|
|
||||||
import "./src/client/init";
|
import "./src/client/init";
|
||||||
import "./src/commands";
|
import "./src/commands";
|
||||||
|
import "./src/events";
|
||||||
import client from "./src/client";
|
import client from "./src/client";
|
||||||
|
|
||||||
function shutdown() {
|
function shutdown() {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "eu.astrogd.white-leopard",
|
"name": "eu.astrogd.white-leopard",
|
||||||
"version": "1.0.0-alpha.3",
|
"version": "1.0.0-alpha.4",
|
||||||
"description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary",
|
"description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
85
src/events/channelUpdate.ts
Normal file
85
src/events/channelUpdate.ts
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import client from "../client";
|
||||||
|
import { Events } from "discord.js";
|
||||||
|
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
||||||
|
import { Badword, database } from "../data";
|
||||||
|
import { IsNull } from "typeorm";
|
||||||
|
import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds";
|
||||||
|
import { getGuildChannel } from "../tools/discord";
|
||||||
|
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);
|
||||||
|
const isPremium = isPremiumActive(settings.isPremiumUntil);
|
||||||
|
|
||||||
|
const globalBlocklist = await database.getRepository(Badword).find({
|
||||||
|
where: {
|
||||||
|
guildID: IsNull()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const localBlocklist = await database.getRepository(Badword).find({
|
||||||
|
where: {
|
||||||
|
guildID: guild.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const blocklist = [...globalBlocklist, ...localBlocklist];
|
||||||
|
let found: string | null = null;
|
||||||
|
|
||||||
|
for (let i = 0; i < blocklist.length; i++) {
|
||||||
|
const word = blocklist[i];
|
||||||
|
if (!word) continue;
|
||||||
|
|
||||||
|
if (!name.includes(word.value)) continue;
|
||||||
|
found = word.value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found === null) return;
|
||||||
|
|
||||||
|
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`);
|
||||||
|
} 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({
|
||||||
|
name: "Detected banned word:",
|
||||||
|
value: `||${found}||`
|
||||||
|
},{
|
||||||
|
name: "Old channel name:",
|
||||||
|
value: `||${name}||`,
|
||||||
|
inline: true
|
||||||
|
});
|
||||||
|
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [embed]
|
||||||
|
}).catch();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.setColor(Color.WARNING_YELLOW);
|
||||||
|
if (isPremium) embed.addFields({
|
||||||
|
name: "Detected banned word:",
|
||||||
|
value: `||${found}||`,
|
||||||
|
inline: true
|
||||||
|
},{
|
||||||
|
name: "Old channel name:",
|
||||||
|
value: `||${name}||`,
|
||||||
|
inline: true
|
||||||
|
});
|
||||||
|
|
||||||
|
logChannel.send({
|
||||||
|
embeds: [embed]
|
||||||
|
}).catch();
|
||||||
|
});
|
1
src/events/index.ts
Normal file
1
src/events/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
import "./channelUpdate";
|
Loading…
Reference in New Issue
Block a user