Compare commits
2 Commits
1.0.0-alph
...
1.0.0-alph
Author | SHA1 | Date | |
---|---|---|---|
dc6755eb19
|
|||
def44d2774
|
1
index.ts
1
index.ts
@ -6,6 +6,7 @@ swapConsole();
|
||||
|
||||
import "./src/client/init";
|
||||
import "./src/commands";
|
||||
import "./src/events";
|
||||
import client from "./src/client";
|
||||
|
||||
function shutdown() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "eu.astrogd.white-leopard",
|
||||
"version": "1.0.0-alpha.2",
|
||||
"version": "1.0.0-alpha.4",
|
||||
"description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary",
|
||||
"main": "build/index.js",
|
||||
"scripts": {
|
||||
|
@ -4,6 +4,7 @@ import { IsNull } from "typeorm";
|
||||
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
||||
import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds";
|
||||
import { getGuildChannel } from "../tools/discord";
|
||||
import { Color, Emoji } from "../tools/design";
|
||||
|
||||
const builder = new SlashCommandBuilder();
|
||||
builder.setName("blocklist");
|
||||
@ -81,7 +82,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
||||
const limit = isPremium ? 100 : 10;
|
||||
if (count >= limit) {
|
||||
const embed = getFailedEmbed();
|
||||
embed.setDescription("You reached the word limit for your guild. Please delete a word before adding a new one");
|
||||
embed.setDescription(`You reached the word limit for your guild. Please delete a word before adding a new one`);
|
||||
interaction.reply({
|
||||
embeds: [embed],
|
||||
ephemeral: true
|
||||
@ -122,7 +123,8 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
||||
});
|
||||
|
||||
const logMessage = getDefaultEmbed();
|
||||
logMessage.setTitle("Word added");
|
||||
logMessage.setTitle(`${Emoji.SETTINGS} Word added`);
|
||||
logMessage.setColor(Color.INFORMING_BLUE);
|
||||
logMessage.setDescription(`"||${word}||" has been added to the blocklist`);
|
||||
logMessage.addFields({
|
||||
name: "This action was performed by",
|
||||
@ -168,7 +170,8 @@ async function execute(interaction: ChatInputCommandInteraction): Promise<void>
|
||||
}).catch();
|
||||
|
||||
const logMessage = getDefaultEmbed();
|
||||
logMessage.setTitle("Word removed");
|
||||
logMessage.setTitle(`${Emoji.SETTINGS} Word removed`);
|
||||
logMessage.setColor(Color.INFORMING_BLUE);
|
||||
logMessage.setDescription(`"||${word}||" has been removed from the blocklist`);
|
||||
logMessage.addFields({
|
||||
name: "This action was performed by",
|
||||
|
@ -1,7 +1,8 @@
|
||||
import * as notification from "./notification";
|
||||
import * as blocklist from "./blocklist";
|
||||
import * as info from "./info";
|
||||
|
||||
const array = [notification.builder.toJSON(), blocklist.builder.toJSON()];
|
||||
const array = [notification.builder.toJSON(), blocklist.builder.toJSON(), info.builder.toJSON()];
|
||||
|
||||
export {
|
||||
array
|
||||
|
@ -1,12 +1,14 @@
|
||||
import { ChatInputCommandInteraction, Collection, Events, SlashCommandBuilder } from "discord.js";
|
||||
import * as notification from "./notification";
|
||||
import * as blocklist from "./blocklist";
|
||||
import * as info from "./info";
|
||||
import client from "../client";
|
||||
import getDefaultEmbed from "../tools/defaultEmbeds";
|
||||
|
||||
const commands = new Collection<string, { builder: SlashCommandBuilder, execute: (interaction: ChatInputCommandInteraction) => Promise<void> }>();
|
||||
commands.set(notification.builder.name, notification);
|
||||
commands.set(blocklist.builder.name, blocklist);
|
||||
commands.set(info.builder.name, info);
|
||||
|
||||
client.on(Events.InteractionCreate, async (interaction) => {
|
||||
if (!interaction.isChatInputCommand()) return;
|
||||
|
66
src/commands/info.ts
Normal file
66
src/commands/info.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
|
||||
import { IsNull } from "typeorm";
|
||||
import { Badword, database } from "../data";
|
||||
import { getGuildSetting, isPremiumActive } from "../tools/data";
|
||||
import getDefaultEmbed from "../tools/defaultEmbeds";
|
||||
import pack from "../../package.json";
|
||||
import { Color, Emoji } from "../tools/design";
|
||||
|
||||
const builder = new SlashCommandBuilder();
|
||||
builder.setName("info");
|
||||
builder.setDescription("Shows information about this bot and the server settings");
|
||||
builder.setDMPermission(false);
|
||||
|
||||
async function execute(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||
if (!interaction.inGuild()) throw new Error("Command was executed outside guild context");
|
||||
|
||||
const settings = await getGuildSetting(interaction.guildId);
|
||||
const isPremium = isPremiumActive(settings.isPremiumUntil);
|
||||
const globalBlockedWordsCount = await database.getRepository(Badword).count({
|
||||
where: {
|
||||
guildID: IsNull()
|
||||
}
|
||||
});
|
||||
const localBlockedWordsCount = await database.getRepository(Badword).count({
|
||||
where: {
|
||||
guildID: interaction.guildId
|
||||
}
|
||||
});
|
||||
|
||||
const embed = getDefaultEmbed();
|
||||
embed.setTitle(`${Emoji.SECURITY_CHALLENGE} Channel filter V${pack.version} by AstroGD®`);
|
||||
embed.setDescription(`Codename eu.astrogd.white-leopard`);
|
||||
embed.setColor(isPremium ? Color.PREMIUM_ORANGE : Color.INFORMING_BLUE);
|
||||
embed.addFields({
|
||||
name: "What does this bot do?",
|
||||
value: "This bot checks for blocked words contained in channel names and reverts the changes if found."
|
||||
},{
|
||||
name: "Author",
|
||||
value: `This bot was created by AstroGD#0001 ${Emoji.ASTROGD} mainly for the official r/Overwatch2 Subreddit Discord server`
|
||||
},{
|
||||
name: "Server status",
|
||||
value: `${isPremium ? Emoji.PREMIUM : Emoji.SWITCH_OFF} Premium features are ${isPremium ? "enabled" : "disabled"} on this server`,
|
||||
inline: true
|
||||
},{
|
||||
name: "Global word count",
|
||||
value: globalBlockedWordsCount.toString(),
|
||||
inline: true
|
||||
},{
|
||||
name: "Local word count",
|
||||
value: localBlockedWordsCount.toString(),
|
||||
inline: true
|
||||
},{
|
||||
name: `${Emoji.WAVING} Have a question or want to say hello?`,
|
||||
value: "Join the support Discord server at https://go.astrogd.eu/discord"
|
||||
});
|
||||
|
||||
interaction.reply({
|
||||
embeds: [embed],
|
||||
ephemeral: true
|
||||
}).catch();
|
||||
}
|
||||
|
||||
export {
|
||||
builder,
|
||||
execute
|
||||
}
|
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";
|
@ -18,9 +18,6 @@ export async function getGuildSetting(guildID: string): Promise<GuildSetting> {
|
||||
}
|
||||
|
||||
export function isPremiumActive(timestamp: Date | null): boolean {
|
||||
|
||||
console.log(timestamp);
|
||||
|
||||
if (timestamp === null) return false;
|
||||
const now = Number(new Date());
|
||||
const activeUntil = Number(timestamp);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import pack from "../../package.json";
|
||||
import { EmbedBuilder } from "discord.js";
|
||||
import client from "../client";
|
||||
import { Color, Emoji } from "./design";
|
||||
|
||||
// const _coolColors = [0x054566];
|
||||
|
||||
@ -11,21 +12,21 @@ export default function getDefaultEmbed(): EmbedBuilder {
|
||||
iconURL: client.user?.avatarURL() || undefined,
|
||||
});
|
||||
embed.setTimestamp(new Date());
|
||||
embed.setColor(0x3682cc);
|
||||
embed.setColor(Color.ANONYMOUS_GRAY);
|
||||
|
||||
return embed;
|
||||
}
|
||||
|
||||
export function getSuccessEmbed(): EmbedBuilder {
|
||||
const embed = getDefaultEmbed();
|
||||
embed.setTitle("Success");
|
||||
embed.setColor(0x32d122);
|
||||
embed.setTitle(`${Emoji.CHAT_APPROVE} Success`);
|
||||
embed.setColor(Color.SUCCESSFUL_GREEN);
|
||||
return embed;
|
||||
}
|
||||
|
||||
export function getFailedEmbed(): EmbedBuilder {
|
||||
const embed = getDefaultEmbed();
|
||||
embed.setTitle("Failed");
|
||||
embed.setColor(0xD01B15);
|
||||
embed.setTitle(`${Emoji.CHAT_DENY} Failed`);
|
||||
embed.setColor(Color.STOPSIGN_RED);
|
||||
return embed;
|
||||
}
|
30
src/tools/design.ts
Normal file
30
src/tools/design.ts
Normal file
@ -0,0 +1,30 @@
|
||||
export enum Emoji {
|
||||
DOUBLE_ARROW_RIGHT = "<:double_arrow_right:918922668936413267>",
|
||||
SETTINGS = "<:settings:918912063970099232>",
|
||||
TIME = "<:time:918913616743387156>",
|
||||
DOCS = "<:docs:918917779283918899>",
|
||||
MESSAGE = "<:message:918920872683786280>",
|
||||
WAVING = "<:waving:918949572804505640>",
|
||||
CHAT_APPROVE = "<:chat_approve:918910607317667860>",
|
||||
CHAT_DENY = "<:chat_deny:918911411663544410>",
|
||||
WARN = "<:warn:918914600181825556>",
|
||||
INFORMATION = "<:information:918912973874028614>",
|
||||
ERROR = "<:error:918915254447136841>",
|
||||
SWITCH_ON = "<:switch_on:918915977662586892>",
|
||||
SWITCH_OFF = "<:switch_off:918917065899925584>",
|
||||
SWITCH_UNSET = "<:switch_unset:918917082807156796>",
|
||||
SECURITY_CHALLENGE = "<:security_challenge:918919903405305946>",
|
||||
SECURITY_CHALLENGE_SUCCESS = "<:security_challenge_success:918919918672576562>",
|
||||
SECURITY_CHALLENGE_FAILED = "<:security_challenge_failed:918919932887064696>",
|
||||
ASTROGD = "<:astrogd:918906741125697626>",
|
||||
PREMIUM = "<:premium:918909591255908442>",
|
||||
}
|
||||
|
||||
export enum Color {
|
||||
PREMIUM_ORANGE = 0xFFC800,
|
||||
SUCCESSFUL_GREEN = 0x77DE37,
|
||||
STOPSIGN_RED = 0xDA2132,
|
||||
WARNING_YELLOW = 0xF0E210,
|
||||
INFORMING_BLUE = 0x2FAAE2,
|
||||
ANONYMOUS_GRAY = 0x7B7B7B
|
||||
}
|
Reference in New Issue
Block a user