From e4dcbf03ae18c4061539caa9a30d948c90c68c4b Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Tue, 12 Jul 2022 18:51:21 +0100 Subject: [PATCH] Create ignore command --- src/commands/ignore.ts | 37 +++++++++++++++++++ ... => 1657647026816-CreateIgnoredChannel.ts} | 0 src/registry.ts | 8 ++-- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/commands/ignore.ts rename src/migration/{1657647026816-CreateIgnoredChannel => 1657647026816-CreateIgnoredChannel.ts} (100%) diff --git a/src/commands/ignore.ts b/src/commands/ignore.ts new file mode 100644 index 0000000..2bd3297 --- /dev/null +++ b/src/commands/ignore.ts @@ -0,0 +1,37 @@ +import { ICommandContext } from "../contracts/ICommandContext"; +import IgnoredChannel from "../entity/IgnoredChannel"; +import PublicEmbed from "../helpers/embeds/PublicEmbed"; +import { Command } from "../type/command"; + +export default class Ignore extends Command { + constructor() { + super(); + + super.Category = "Moderation"; + super.Roles = [ + "moderator" + ]; + } + + public override async execute(context: ICommandContext) { + if (!context.message.guild) return; + + const isChannelIgnored = await IgnoredChannel.IsChannelIgnored(context.message.channel.id); + + if (isChannelIgnored) { + const entity = await IgnoredChannel.FetchOneById(IgnoredChannel, context.message.channel.id); + + await IgnoredChannel.Remove(IgnoredChannel, entity); + + const embed = new PublicEmbed(context, "Success", "This channel will start being logged again."); + await embed.SendToCurrentChannel(); + } else { + const entity = new IgnoredChannel(context.message.channel.id); + + await entity.Save(IgnoredChannel, entity); + + const embed = new PublicEmbed(context, "Success", "This channel will now be ignored from logging."); + await embed.SendToCurrentChannel(); + } + } +} \ No newline at end of file diff --git a/src/migration/1657647026816-CreateIgnoredChannel b/src/migration/1657647026816-CreateIgnoredChannel.ts similarity index 100% rename from src/migration/1657647026816-CreateIgnoredChannel rename to src/migration/1657647026816-CreateIgnoredChannel.ts diff --git a/src/registry.ts b/src/registry.ts index 9d073b1..183bac2 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -8,6 +8,7 @@ import Code from "./commands/code"; import Config from "./commands/config"; import Disable from "./commands/disable"; import Help from "./commands/help"; +import Ignore from "./commands/ignore"; import Kick from "./commands/kick"; import Mute from "./commands/mute"; import Poll from "./commands/poll"; @@ -32,7 +33,11 @@ export default class Registry { CoreClient.RegisterCommand("ban", new Ban()); CoreClient.RegisterCommand("bunny", new Bunny()); CoreClient.RegisterCommand("clear", new Clear()); + CoreClient.RegisterCommand("code", new Code()); + CoreClient.RegisterCommand("config", new Config()); + CoreClient.RegisterCommand("disable", new Disable()); CoreClient.RegisterCommand("help", new Help()); + CoreClient.RegisterCommand("ignore", new Ignore()); CoreClient.RegisterCommand("kick", new Kick()); CoreClient.RegisterCommand("mute", new Mute()); CoreClient.RegisterCommand("poll", new Poll()); @@ -41,9 +46,6 @@ export default class Registry { CoreClient.RegisterCommand("unmute", new Unmute()); CoreClient.RegisterCommand("warn", new Warn()); CoreClient.RegisterCommand("setup", new Setup()); - CoreClient.RegisterCommand("config", new Config()); - CoreClient.RegisterCommand("code", new Code()); - CoreClient.RegisterCommand("disable", new Disable()); // Exclusive Commands: MankBot CoreClient.RegisterCommand("lobby", new Lobby(), "501231711271780357");