From 657a3adb27dd4de05d13bb1b79ff8b02ead85645 Mon Sep 17 00:00:00 2001 From: nick <62725534+nicklvh@users.noreply.github.com> Date: Sat, 13 Jul 2024 18:29:31 +0100 Subject: [PATCH] chore: remove decorators --- src/commands/fun/cat.ts | 21 +- src/commands/fun/coinflip.ts | 18 +- src/commands/fun/dog.ts | 20 +- src/commands/fun/duck.ts | 20 +- src/commands/fun/rps.ts | 63 +++--- src/commands/misc/avatar.ts | 95 ++++----- src/commands/misc/iplookup.ts | 80 ++++++++ src/commands/misc/ping.ts | 24 +++ src/commands/misc/serverinfo.ts | 67 ++---- src/commands/misc/setnick.ts | 55 ++--- src/commands/misc/whois.ts | 35 ++-- src/commands/moderation/ban.ts | 121 +++++------ src/commands/moderation/infractions.ts | 47 +++-- src/commands/moderation/kick.ts | 71 +++---- src/commands/moderation/mute.ts | 191 +++++++++--------- src/commands/moderation/warn.ts | 69 +++---- src/commands/settings/settings.ts | 105 ++++++---- .../client/chatInputCommandDenied.ts | 14 +- .../client/chatInputCommandSuccess.ts | 14 +- src/listeners/client/guildCreate.ts | 14 +- src/listeners/client/guildDelete.ts | 14 +- src/listeners/client/ready.ts | 16 +- src/listeners/guild/channelCreate.ts | 21 +- src/listeners/guild/channelDelete.ts | 21 +- src/listeners/guild/channelUpdate.ts | 21 +- src/listeners/guild/guildMemberAdd.ts | 19 +- src/listeners/guild/guildMemberRemove.ts | 19 +- src/listeners/guild/messageDelete.ts | 17 +- src/listeners/guild/messageUpdate.ts | 19 +- src/listeners/guild/roleCreate.ts | 17 +- src/listeners/guild/roleDelete.ts | 17 +- src/listeners/guild/roleUpdate.ts | 17 +- src/preconditions/global/guildBanned.ts | 14 +- 33 files changed, 814 insertions(+), 562 deletions(-) create mode 100644 src/commands/misc/iplookup.ts create mode 100644 src/commands/misc/ping.ts diff --git a/src/commands/fun/cat.ts b/src/commands/fun/cat.ts index 5478ca8..7fe6909 100644 --- a/src/commands/fun/cat.ts +++ b/src/commands/fun/cat.ts @@ -1,17 +1,22 @@ import { Command } from "@sapphire/framework"; import { fetch, FetchResultTypes } from "@sapphire/fetch"; import { EmbedBuilder } from "discord.js"; -import type { APIPetResponse } from "../../types/index.js"; -import { ApplyOptions } from "@sapphire/decorators"; +import type { APIPetResponse } from "../../utils"; -@ApplyOptions({ - name: "cat", - description: "shows a cat 😽", -}) export class CatCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "cat", + description: "shows a cat 😽", + requiredClientPermissions: ["EmbedLinks"], + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder.setName(this.name).setDescription(this.description) + registry.registerChatInputCommand( + (builder) => builder.setName(this.name).setDescription(this.description), + { idHints: ["1169746949239476275"] } ); } diff --git a/src/commands/fun/coinflip.ts b/src/commands/fun/coinflip.ts index 47cdf39..a951024 100644 --- a/src/commands/fun/coinflip.ts +++ b/src/commands/fun/coinflip.ts @@ -1,15 +1,19 @@ import { Command } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { EmbedBuilder } from "discord.js"; -@ApplyOptions({ - name: "coinflip", - description: "flip! shows heads or tails 🪙", -}) export class CoinflipCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "coinflip", + description: "flip! shows heads or tails 🪙", + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder.setName(this.name).setDescription(this.description) + registry.registerChatInputCommand( + (builder) => builder.setName(this.name).setDescription(this.description), + { idHints: ["1171942952705208390"] } ); } diff --git a/src/commands/fun/dog.ts b/src/commands/fun/dog.ts index b36dca7..72526a9 100644 --- a/src/commands/fun/dog.ts +++ b/src/commands/fun/dog.ts @@ -1,17 +1,21 @@ import { Command } from "@sapphire/framework"; import { fetch, FetchResultTypes } from "@sapphire/fetch"; import { EmbedBuilder } from "discord.js"; -import type { APIPetResponse } from "../../types/index.js"; -import { ApplyOptions } from "@sapphire/decorators"; +import type { APIPetResponse } from "../../utils"; -@ApplyOptions({ - name: "dog", - description: "shows a dog 🐶", -}) export class DogCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "dog", + description: "shows a dog 🐶", + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder.setName(this.name).setDescription(this.description) + registry.registerChatInputCommand( + (builder) => builder.setName(this.name).setDescription(this.description), + { idHints: ["1169750644710703225"] } ); } diff --git a/src/commands/fun/duck.ts b/src/commands/fun/duck.ts index 9d99fd8..f046735 100644 --- a/src/commands/fun/duck.ts +++ b/src/commands/fun/duck.ts @@ -1,17 +1,21 @@ import { Command } from "@sapphire/framework"; import { fetch, FetchResultTypes } from "@sapphire/fetch"; import { EmbedBuilder } from "discord.js"; -import { ApplyOptions } from "@sapphire/decorators"; -import type { APIPetInterface } from "../../types/index.js"; +import type { APIPetInterface } from "../../utils/types/types.js"; -@ApplyOptions({ - name: "duck", - description: "shows a duck 🦆", -}) export class DuckCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "duck", + description: "shows a duck 🦆", + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder.setName(this.name).setDescription(this.description) + registry.registerChatInputCommand( + (builder) => builder.setName(this.name).setDescription(this.description), + { idHints: ["1169732840691355659"] } ); } diff --git a/src/commands/fun/rps.ts b/src/commands/fun/rps.ts index 49db2f8..3ff0fc4 100644 --- a/src/commands/fun/rps.ts +++ b/src/commands/fun/rps.ts @@ -1,37 +1,42 @@ import { Command } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { EmbedBuilder } from "discord.js"; -@ApplyOptions({ - name: "rps", - description: "will it be: rock, paper, or scissors? 🤔", -}) export class RockPaperScissorsCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "rps", + description: "will it be: rock, paper, or scissors? 🤔", + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder - .setName(this.name) - .setDescription(this.description) - .addStringOption((option) => - option - .setName("choice") - .setDescription("your choice of rock, paper, or scissors") - .setRequired(true) - .setChoices( - { - name: "Rock", - value: "Rock", - }, - { - name: "Paper", - value: "Paper", - }, - { - name: "Scissors", - value: "Scissors", - } - ) - ) + registry.registerChatInputCommand( + (builder) => + builder + .setName(this.name) + .setDescription(this.description) + .addStringOption((option) => + option + .setName("choice") + .setDescription("your choice of rock, paper, or scissors") + .setRequired(true) + .setChoices( + { + name: "Rock", + value: "Rock", + }, + { + name: "Paper", + value: "Paper", + }, + { + name: "Scissors", + value: "Scissors", + } + ) + ), + { idHints: ["1171945619875696672"] } ); } diff --git a/src/commands/misc/avatar.ts b/src/commands/misc/avatar.ts index dd20575..01c8e95 100644 --- a/src/commands/misc/avatar.ts +++ b/src/commands/misc/avatar.ts @@ -1,53 +1,58 @@ import { Command } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { EmbedBuilder, type ImageExtension, type ImageSize } from "discord.js"; -@ApplyOptions({ - name: "avatar", - description: "shows a user's avatar", -}) export class AvatarCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "avatar", + description: "shows a user's avatar", + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to show the avatar of") - .setRequired(false) - ) - .addNumberOption((option) => - option - .setName("size") - .setDescription("the size of the avatar") - .setRequired(false) - .setChoices( - { name: "16", value: 16 }, - { name: "32", value: 32 }, - { name: "64", value: 64 }, - { name: "128", value: 128 }, - { name: "256", value: 256 }, - { name: "512", value: 512 }, - { name: "1024", value: 1024 }, - { name: "2048", value: 2048 }, - { name: "4096", value: 4096 } - ) - ) - .addStringOption((option) => - option - .setName("format") - .setDescription("the format of the avatar") - .setRequired(false) - .setChoices( - { name: "webp", value: "webp" }, - { name: "png", value: "png" }, - { name: "jpg", value: "jpg" }, - { name: "jpeg", value: "jpeg" }, - { name: "gif", value: "gif" } - ) - ) + registry.registerChatInputCommand( + (builder) => + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to show the avatar of") + .setRequired(false) + ) + .addNumberOption((option) => + option + .setName("size") + .setDescription("the size of the avatar") + .setRequired(false) + .setChoices( + { name: "16", value: 16 }, + { name: "32", value: 32 }, + { name: "64", value: 64 }, + { name: "128", value: 128 }, + { name: "256", value: 256 }, + { name: "512", value: 512 }, + { name: "1024", value: 1024 }, + { name: "2048", value: 2048 }, + { name: "4096", value: 4096 } + ) + ) + .addStringOption((option) => + option + .setName("format") + .setDescription("the format of the avatar") + .setRequired(false) + .setChoices( + { name: "webp", value: "webp" }, + { name: "png", value: "png" }, + { name: "jpg", value: "jpg" }, + { name: "jpeg", value: "jpeg" }, + { name: "gif", value: "gif" } + ) + ), + { idHints: ["1171494645918875718"] } ); } diff --git a/src/commands/misc/iplookup.ts b/src/commands/misc/iplookup.ts new file mode 100644 index 0000000..c0d42d0 --- /dev/null +++ b/src/commands/misc/iplookup.ts @@ -0,0 +1,80 @@ +import { Command } from "@sapphire/framework"; +import { fetch, FetchResultTypes } from "@sapphire/fetch"; +import { EmbedBuilder } from "discord.js"; + +export class ServerInfoCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "iplookup", + description: "shows information about an ip address", + }); + } + + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => + builder + .setName(this.name) + .setDescription(this.description) + .addStringOption((option) => + option + .setName("ip") + .setDescription("The ip address to lookup") + .setRequired(true) + ), + { idHints: ["1261706053960204351"] } + ); + } + + public override async chatInputRun( + interaction: Command.ChatInputCommandInteraction + ) { + const ip = interaction.options.getString("ip", true); + + if ( + !ip.match( + "((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" + ) && + !ip.match( + "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]).){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))" + ) + ) { + return interaction.reply("Invalid ip address"); + } + + const res: any = await fetch( + `http://ip-api.com/json/${ip}?fields=156435`, + FetchResultTypes.JSON + ); + + if (res.status !== "success") { + return interaction.reply("Failed to lookup ip address"); + } + + const embed = new EmbedBuilder().setTitle("IP Lookup").addFields([ + { + name: "IP Address", + value: `\`${res.query}\``, + }, + { + name: "Country", + value: `\`${res.country}\` (\`${res.countryCode}\`)`, + }, + { + name: "City", + value: `\`${res.city}\``, + }, + { + name: "ISP", + value: `\`${res.isp}\``, + }, + { + name: "VPN/TOR", + value: `\`${res.proxy}\``, + }, + ]); + + return interaction.reply({ embeds: [embed] }); + } +} diff --git a/src/commands/misc/ping.ts b/src/commands/misc/ping.ts new file mode 100644 index 0000000..50fec64 --- /dev/null +++ b/src/commands/misc/ping.ts @@ -0,0 +1,24 @@ +import { Command } from "@sapphire/framework"; + +export class PingCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "ping", + description: "shows latency between bot and discord", + }); + } + + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => builder.setName(this.name).setDescription(this.description), + { idHints: ["1231947622739345450"] } + ); + } + + public override async chatInputRun( + interaction: Command.ChatInputCommandInteraction + ) { + return interaction.reply(`\`${interaction.client.ws.ping}ms\``); + } +} diff --git a/src/commands/misc/serverinfo.ts b/src/commands/misc/serverinfo.ts index 3a461c1..4a851c9 100644 --- a/src/commands/misc/serverinfo.ts +++ b/src/commands/misc/serverinfo.ts @@ -1,5 +1,4 @@ import { Command, CommandOptionsRunTypeEnum } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { ChannelType, EmbedBuilder, @@ -9,15 +8,20 @@ import { time, } from "discord.js"; -@ApplyOptions({ - name: "serverinfo", - description: "shows information about the server", - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) export class ServerInfoCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "serverinfo", + description: "shows information about the server", + runIn: CommandOptionsRunTypeEnum.GuildAny, + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder.setName(this.name).setDescription(this.description) + registry.registerChatInputCommand( + (builder) => builder.setName(this.name).setDescription(this.description), + { idHints: ["1171934681726468106"] } ); } @@ -39,49 +43,22 @@ export class ServerInfoCommand extends Command { const generalContent = [ `${bold("❯ Name:")} ${inlineCode(interaction.guild.name)}`, `${bold("❯ ID:")} ${inlineCode(interaction.guildId)}`, - `${bold("❯ Owner:")} ${inlineCode(owner!.user.tag)} (${inlineCode( - interaction.guild.ownerId - )})`, + `${bold("❯ Owner:")} ${inlineCode(owner!.user.tag)} (${inlineCode(interaction.guild.ownerId)})`, `${bold("❯ Boost Tier:")} ${inlineCode(premiumTier)}`, - `${bold("❯ Time Created:")} ${time( - Math.floor(interaction.guild.createdTimestamp) / 1000, - TimestampStyles.ShortDateTime - )}`, + `${bold("❯ Time Created:")} ${time(Math.floor(interaction.guild.createdTimestamp) / 1000, TimestampStyles.ShortDateTime)}`, ]; const statisticsContent = [ `${bold("❯ Role Count:")} ${inlineCode(`${roles.length}`)}`, `${bold("❯ Emoji Count:")} ${inlineCode(`${emojis.size}`)}`, - `${bold("❯ Regular Emoji Count:")} ${inlineCode( - `${emojis.filter((emoji) => !emoji.animated).size}` - )}`, - `${bold("❯ Animated Emoji Count:")} ${inlineCode( - `${emojis.filter((emoji) => emoji.animated).size}` - )}`, - `${bold("❯ Member Count:")} ${inlineCode( - `${interaction.guild.memberCount}` - )}`, - `${bold("❯ Humans:")} ${inlineCode( - `${members.filter((member) => !member.user.bot).size}` - )}`, - `${bold("❯ Bots:")} ${inlineCode( - `${members.filter((member) => member.user.bot).size}` - )}`, - `${bold("❯ Text Channels:")} ${inlineCode( - `${ - channels.filter((channel) => channel.type === ChannelType.GuildText) - .size - }` - )}`, - `${bold("❯ Voice Channels:")} ${inlineCode( - `${ - channels.filter((channel) => channel.type === ChannelType.GuildVoice) - .size - }` - )}`, - `${bold("❯ Boost Count:")} ${inlineCode( - `${interaction.guild.premiumSubscriptionCount || "0"}` - )}}`, + `${bold("❯ Regular Emoji Count:")} ${inlineCode(`${emojis.filter((emoji) => !emoji.animated).size}`)}`, + `${bold("❯ Animated Emoji Count:")} ${inlineCode(`${emojis.filter((emoji) => emoji.animated).size}`)}`, + `${bold("❯ Member Count:")} ${inlineCode(`${interaction.guild.memberCount}`)}`, + `${bold("❯ Humans:")} ${inlineCode(`${members.filter((member) => !member.user.bot).size}`)}`, + `${bold("❯ Bots:")} ${inlineCode(`${members.filter((member) => member.user.bot).size}`)}`, + `${bold("❯ Text Channels:")} ${inlineCode(`${channels.filter((channel) => channel.type === ChannelType.GuildText).size}`)}`, + `${bold("❯ Voice Channels:")} ${inlineCode(`${channels.filter((channel) => channel.type === ChannelType.GuildVoice).size}`)}`, + `${bold("❯ Boost Count:")} ${inlineCode(`${interaction.guild.premiumSubscriptionCount || "0"}`)}}`, ]; return interaction.reply({ diff --git a/src/commands/misc/setnick.ts b/src/commands/misc/setnick.ts index f49c94e..0a8e7e0 100644 --- a/src/commands/misc/setnick.ts +++ b/src/commands/misc/setnick.ts @@ -1,33 +1,38 @@ import { Command, CommandOptionsRunTypeEnum } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { EmbedBuilder, PermissionFlagsBits } from "discord.js"; -@ApplyOptions({ - name: "setnick", - description: "set the nickname of a user", - requiredClientPermissions: [PermissionFlagsBits.ManageNicknames], - requiredUserPermissions: [PermissionFlagsBits.ManageNicknames], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) export class SetNickCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "setnick", + description: "set the nickname of a user", + requiredClientPermissions: [PermissionFlagsBits.ManageNicknames], + requiredUserPermissions: [PermissionFlagsBits.ManageNicknames], + runIn: CommandOptionsRunTypeEnum.GuildAny, + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to set the nickname of") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("nickname") - .setDescription("the nickname to set") - .setRequired(true) - .setMaxLength(32) - ) + registry.registerChatInputCommand( + (builder) => + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to set the nickname of") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("nickname") + .setDescription("the nickname to set") + .setRequired(true) + .setMaxLength(32) + ), + { idHints: ["1171942330958360587"] } ); } diff --git a/src/commands/misc/whois.ts b/src/commands/misc/whois.ts index 043bbf3..60b8a13 100644 --- a/src/commands/misc/whois.ts +++ b/src/commands/misc/whois.ts @@ -1,23 +1,28 @@ import { Command } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { EmbedBuilder } from "discord.js"; -@ApplyOptions({ - name: "whois", - description: "shows information about a user", -}) export class WhoisCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "whois", + description: "shows information about a user", + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to show information about") - .setRequired(false) - ) + registry.registerChatInputCommand( + (builder) => + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to show information about") + .setRequired(false) + ), + { idHints: ["1171934682846330916"] } ); } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 49ddf3a..c0d54c5 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -7,65 +7,71 @@ import { PermissionFlagsBits, inlineCode, } from "discord.js"; -import { Time } from "@sapphire/time-utilities"; -import { ApplyOptions } from "@sapphire/decorators"; import { ModerationType } from "@prisma/client"; +import { handleInfraction } from "../../utils"; -@ApplyOptions({ - name: "ban", - description: "ban a member 🔨", - requiredUserPermissions: [PermissionFlagsBits.BanMembers], - requiredClientPermissions: [PermissionFlagsBits.BanMembers], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) export class BanCommand extends Command { - public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => { - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to ban") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("reason") - .setDescription("the reason for the ban") - .setRequired(false) - ) - .addIntegerOption((option) => - option - .setName("days") - .setDescription( - "the amount of days to ban the user for, default is a perma ban" - ) - .setRequired(false) - .addChoices( - { - name: "1 day", - value: 1, - }, - { - name: "1 week", - value: 7, - }, - { - name: "2 weeks", - value: 14, - }, - { - name: "1 month", - value: 28, - } - ) - ) - .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers); + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "ban", + description: "ban a member 🔨", + requiredUserPermissions: [PermissionFlagsBits.BanMembers], + requiredClientPermissions: [PermissionFlagsBits.BanMembers], + runIn: CommandOptionsRunTypeEnum.GuildAny, }); } + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => { + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to ban") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("reason") + .setDescription("the reason for the ban") + .setRequired(false) + ) + .addIntegerOption((option) => + option + .setName("days") + .setDescription( + "the amount of days to ban the user for, default is a perma ban" + ) + .setRequired(false) + .addChoices( + { + name: "1 day", + value: 1, + }, + { + name: "1 week", + value: 7, + }, + { + name: "2 weeks", + value: 14, + }, + { + name: "1 month", + value: 28, + } + ) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.BanMembers); + }, + { idHints: ["1169766210443956264"] } + ); + } + public override async chatInputRun( interaction: Command.ChatInputCommandInteraction<"cached"> ) { @@ -164,16 +170,11 @@ export class BanCommand extends Command { try { const confirmation = await message.awaitMessageComponent({ filter: (i) => interaction.user.id === i.user.id, - time: Time.Minute, + time: 60000, // 1 min, }); if (confirmation.customId === "confirm") { - this.container.helpers.handleModeration( - ModerationType.BAN, - interaction, - user, - reason - ); + await handleInfraction(ModerationType.BAN, interaction, user, reason); await interaction.guild.bans.create(user, { reason, diff --git a/src/commands/moderation/infractions.ts b/src/commands/moderation/infractions.ts index 72b9c8c..f7aa0c8 100644 --- a/src/commands/moderation/infractions.ts +++ b/src/commands/moderation/infractions.ts @@ -6,33 +6,40 @@ import { inlineCode, time, } from "discord.js"; -import { ApplyOptions } from "@sapphire/decorators"; import { PaginatedMessage } from "@sapphire/discord.js-utilities"; import { chunk } from "@sapphire/utilities"; -import { ModerationTypeNamesPresent } from "../../types/index.js"; +import { ModerationTypeNamesPresent } from "../../utils"; -@ApplyOptions({ - name: "infractions", - description: "show all of a members infractions, warns/bans/mutes/kicks...", - requiredUserPermissions: [PermissionFlagsBits.ManageMessages], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) export class InfractionsCommand extends Command { - public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => { - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to show infractions for") - .setRequired(false) - ) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages); + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "infractions", + description: + "show all of a members infractions, warns/bans/mutes/kicks...", + requiredUserPermissions: [PermissionFlagsBits.ManageMessages], + runIn: CommandOptionsRunTypeEnum.GuildAny, }); } + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => { + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to show infractions for") + .setRequired(false) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages); + }, + { idHints: ["1175550972718747740"] } + ); + } + public override async chatInputRun( interaction: Command.ChatInputCommandInteraction<"cached"> ) { diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index f3b673d..1bd0de8 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -7,39 +7,45 @@ import { PermissionFlagsBits, inlineCode, } from "discord.js"; -import { ApplyOptions } from "@sapphire/decorators"; import { ModerationType } from "@prisma/client"; -import { Time } from "@sapphire/time-utilities"; - -@ApplyOptions({ - name: "kick", - description: "kick a member", - requiredUserPermissions: [PermissionFlagsBits.KickMembers], - requiredClientPermissions: [PermissionFlagsBits.KickMembers], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) +import { handleInfraction } from "../../utils"; + export class KickCommand extends Command { - public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => { - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to kick") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("reason") - .setDescription("the reason for the kick") - .setRequired(false) - ) - .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers); + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "kick", + description: "kick a member", + requiredUserPermissions: [PermissionFlagsBits.KickMembers], + requiredClientPermissions: [PermissionFlagsBits.KickMembers], + runIn: CommandOptionsRunTypeEnum.GuildAny, }); } + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => { + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to kick") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("reason") + .setDescription("the reason for the kick") + .setRequired(false) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.KickMembers); + }, + { idHints: ["1180299697680822332"] } + ); + } + public override async chatInputRun( interaction: Command.ChatInputCommandInteraction<"cached"> ) { @@ -138,16 +144,11 @@ export class KickCommand extends Command { try { const confirmation = await message.awaitMessageComponent({ filter: (i) => interaction.user.id === i.user.id, - time: Time.Minute, + time: 60000, // 1 min, }); if (confirmation.customId === "confirm") { - this.container.helpers.handleModeration( - ModerationType.KICK, - interaction, - user, - reason - ); + await handleInfraction(ModerationType.KICK, interaction, user, reason); await member.kick(reason); diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 13b45b3..ff8ef8b 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -7,103 +7,101 @@ import { PermissionFlagsBits, inlineCode, } from "discord.js"; -import { ApplyOptions } from "@sapphire/decorators"; import { ModerationType } from "@prisma/client"; -import { Time } from "@sapphire/time-utilities"; +import { handleInfraction } from "../../utils"; -@ApplyOptions({ - name: "mute", - description: "mute a member", - requiredUserPermissions: [PermissionFlagsBits.ModerateMembers], - requiredClientPermissions: [PermissionFlagsBits.ModerateMembers], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) export class MuteCommand extends Command { - public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => { - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to mute") - .setRequired(true) - ) - .addIntegerOption((option) => - option - .setName("duration") - .setDescription("the duration of the mute") - .setRequired(true) - .setChoices( - { - name: "1 minute", - value: Time.Minute, - }, - { - name: "5 minutes", - value: Time.Minute * 5, - }, - { - name: "10 minutes", - value: Time.Minute * 10, - }, - { - name: "30 minutes", - value: Time.Minute * 30, - }, - { - name: "1 hour", - value: Time.Hour, - }, - { - name: "6 hours", - value: Time.Hour * 6, - }, - { - name: "12 hours", - value: Time.Hour * 12, - }, - { - name: "1 day", - value: Time.Day, - }, - { - name: "3 days", - value: Time.Day * 3, - }, - { - name: "1 week", - value: Time.Week, - }, - { - name: "2 weeks", - value: Time.Week * 2, - }, - { - name: "1 month", - value: Time.Month, - }, - { - name: "3 months", - value: Time.Month * 3, - }, - { - name: "6 months", - value: Time.Month * 6, - } - ) - ) - .addStringOption((option) => - option - .setName("reason") - .setDescription("the reason for the mute") - .setRequired(false) - ) - .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers); + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "mute", + description: "mute a member", + requiredUserPermissions: [PermissionFlagsBits.ModerateMembers], + requiredClientPermissions: [PermissionFlagsBits.ModerateMembers], + runIn: CommandOptionsRunTypeEnum.GuildAny, }); } + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => { + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to mute") + .setRequired(true) + ) + .addIntegerOption((option) => + option + .setName("duration") + .setDescription("the duration of the mute") + .setRequired(true) + .setChoices( + { + name: "1 minute", + value: 60000, + }, + { + name: "5 minutes", + value: 300000, + }, + { + name: "10 minutes", + value: 600000, + }, + { + name: "30 minutes", + value: 1800000, + }, + { + name: "1 hour", + value: 3600000, + }, + { + name: "6 hours", + value: 21600000, + }, + { + name: "12 hours", + value: 43200000, + }, + { + name: "1 day", + value: 86400000, + }, + { + name: "3 days", + value: 259200000, + }, + { + name: "1 week", + value: 604800000, + }, + { + name: "2 weeks", + value: 1209600000, + }, + { + name: "1 month", + value: 2629800000, + } + ) + ) + .addStringOption((option) => + option + .setName("reason") + .setDescription("the reason for the mute") + .setRequired(false) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers); + }, + { idHints: ["1180633819628458004"] } + ); + } + public override async chatInputRun( interaction: Command.ChatInputCommandInteraction<"cached"> ) { @@ -203,16 +201,11 @@ export class MuteCommand extends Command { try { const confirmation = await message.awaitMessageComponent({ filter: (i) => interaction.user.id === i.user.id, - time: Time.Minute, + time: 60000, // 1 min, }); if (confirmation.customId === "confirm") { - this.container.helpers.handleModeration( - ModerationType.MUTE, - interaction, - user, - reason - ); + await handleInfraction(ModerationType.MUTE, interaction, user, reason); await member.timeout(duration, reason); @@ -226,7 +219,7 @@ export class MuteCommand extends Command { .addFields([ { name: "Duration", - value: inlineCode(`${duration * Time.Minute}`), + value: inlineCode(`${duration * 60000}`), inline: true, }, { diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 1330f8f..26c1f82 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -7,38 +7,44 @@ import { PermissionFlagsBits, inlineCode, } from "discord.js"; -import { ApplyOptions } from "@sapphire/decorators"; import { ModerationType } from "@prisma/client"; -import { Time } from "@sapphire/time-utilities"; - -@ApplyOptions({ - name: "warn", - description: "warn a member", - requiredUserPermissions: [PermissionFlagsBits.ManageGuild], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) +import { handleInfraction } from "../../utils"; + export class WarnCommand extends Command { - public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => { - builder - .setName(this.name) - .setDescription(this.description) - .addUserOption((option) => - option - .setName("user") - .setDescription("the user to warn") - .setRequired(true) - ) - .addStringOption((option) => - option - .setName("reason") - .setDescription("the reason for the warn") - .setRequired(false) - ) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild); + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "warn", + description: "warn a member", + requiredUserPermissions: [PermissionFlagsBits.ManageGuild], + runIn: CommandOptionsRunTypeEnum.GuildAny, }); } + public override registerApplicationCommands(registry: Command.Registry) { + registry.registerChatInputCommand( + (builder) => { + builder + .setName(this.name) + .setDescription(this.description) + .addUserOption((option) => + option + .setName("user") + .setDescription("the user to warn") + .setRequired(true) + ) + .addStringOption((option) => + option + .setName("reason") + .setDescription("the reason for the warn") + .setRequired(false) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild); + }, + { idHints: ["1175535354334421063"] } + ); + } + public override async chatInputRun( interaction: Command.ChatInputCommandInteraction<"cached"> ) { @@ -136,16 +142,11 @@ export class WarnCommand extends Command { try { const confirmation = await message.awaitMessageComponent({ filter: (i) => interaction.user.id === i.user.id, - time: Time.Minute, + time: 60000, // 1 min, }); if (confirmation.customId === "confirm") { - this.container.helpers.handleModeration( - ModerationType.WARN, - interaction, - user, - reason - ); + await handleInfraction(ModerationType.WARN, interaction, user, reason); await confirmation.update({ embeds: [ diff --git a/src/commands/settings/settings.ts b/src/commands/settings/settings.ts index 1c916a9..5aa7614 100644 --- a/src/commands/settings/settings.ts +++ b/src/commands/settings/settings.ts @@ -1,5 +1,4 @@ import { Command, CommandOptionsRunTypeEnum } from "@sapphire/framework"; -import { ApplyOptions } from "@sapphire/decorators"; import { ActionRowBuilder, ButtonBuilder, @@ -11,30 +10,34 @@ import { PermissionFlagsBits, bold, } from "discord.js"; -import { Time } from "@sapphire/time-utilities"; - -@ApplyOptions({ - name: "settings", - description: "change the settings of the bot for the current server", - requiredUserPermissions: ["ManageGuild"], - runIn: CommandOptionsRunTypeEnum.GuildAny, -}) +import { getGuild } from "../../utils"; + export class SettingsCommand extends Command { + public constructor(context: Command.LoaderContext, options: Command.Options) { + super(context, { + ...options, + name: "settings", + description: "change the settings of the bot for the current server", + requiredUserPermissions: ["ManageGuild"], + runIn: CommandOptionsRunTypeEnum.GuildAny, + }); + } + public override registerApplicationCommands(registry: Command.Registry) { - registry.registerChatInputCommand((builder) => - builder - .setName(this.name) - .setDescription(this.description) - .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild) + registry.registerChatInputCommand( + (builder) => + builder + .setName(this.name) + .setDescription(this.description) + .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild), + { idHints: ["1170836355543212052"] } ); } public override async chatInputRun( interaction: Command.ChatInputCommandInteraction<"cached"> ) { - const guildInDB = await this.container.helpers.getGuild( - interaction.guildId - ); + const guildInDB = await getGuild(interaction.guildId); const loggingButton = new ButtonBuilder() .setLabel("Logging") @@ -97,7 +100,7 @@ export class SettingsCommand extends Command { const collector = message.createMessageComponentCollector({ filter: (i) => i.user.id === interaction.user.id, - time: Time.Minute * 5, + time: 300000, // 5 min, }); collector.on( @@ -105,8 +108,7 @@ export class SettingsCommand extends Command { async (componentInteraction: MessageComponentInteraction<"cached">) => { collector.resetTimer(); - const { logging, fun, starboard } = - await this.container.helpers.getGuild(interaction.guildId); + const { logging, fun, starboard } = await getGuild(interaction.guildId); const goBackButton = new ButtonBuilder() .setCustomId("goBack") @@ -156,9 +158,7 @@ export class SettingsCommand extends Command { }); } - const { starboard } = await this.container.helpers.getGuild( - interaction.guildId - ); + const { starboard } = await getGuild(interaction.guildId); const leftButton = new ButtonBuilder() .setEmoji("⬅") @@ -222,7 +222,9 @@ export class SettingsCommand extends Command { }) .setColor("Yellow") .setDescription( - `Pick a channel below to set as the starboard channel for \`${interaction.guild!.name}\`${channel ? "\nDisable it by selecting `Disable`" : ""}` + `Pick a channel below to set as the starboard channel for \`${ + interaction.guild!.name + }\`${channel ? "\nDisable it by selecting `Disable`" : ""}` ), ], components: [ @@ -235,8 +237,7 @@ export class SettingsCommand extends Command { } if (id === "logging" || id === "starboard" || id === "fun") { - const { logging, starboard } = - await this.container.helpers.getGuild(interaction.guildId); + const { logging, starboard } = await getGuild(interaction.guildId); const toggleButton = new ButtonBuilder() .setCustomId( @@ -261,9 +262,21 @@ export class SettingsCommand extends Command { { name: `Use the buttons below to edit the respective channel and settings`, value: [ - `**Modlog:** ${logging!.modlogId ? `<#${logging!.modlogId}>` : "Disabled"}`, - `**Auditlog:** ${logging!.auditlogId ? `<#${logging!.auditlogId}>` : "Disabled"}`, - `**Welcome:** ${logging!.welcomeId ? `<#${logging!.welcomeId}>` : "Disabled"}`, + `**Modlog:** ${ + logging!.modlogId + ? `<#${logging!.modlogId}>` + : "Disabled" + }`, + `**Auditlog:** ${ + logging!.auditlogId + ? `<#${logging!.auditlogId}>` + : "Disabled" + }`, + `**Welcome:** ${ + logging!.welcomeId + ? `<#${logging!.welcomeId}>` + : "Disabled" + }`, ].join("\n"), }, ]) @@ -311,10 +324,20 @@ export class SettingsCommand extends Command { }) .addFields([ { - name: `Use the buttons below to edit the settings for ${bold(`${interaction.guild.name}'s`)} starboard!`, + name: `Use the buttons below to edit the settings for ${bold( + `${interaction.guild.name}'s` + )} starboard!`, value: [ - `**Stars Required:** ${bold(starboard?.starsRequired?.toString()!)} ${starboard?.starsRequired === 5 ? "(Default)" : ""}`, - `**Channel:** ${starboard?.channelId ? `<#${starboard.channelId}>` : "Not set"}`, + `**Stars Required:** ${bold( + starboard?.starsRequired?.toString()! + )} ${ + starboard?.starsRequired === 5 ? "(Default)" : "" + }`, + `**Channel:** ${ + starboard?.channelId + ? `<#${starboard.channelId}>` + : "Not set" + }`, ].join("\n"), }, ]) @@ -427,7 +450,9 @@ export class SettingsCommand extends Command { }) .setColor("Blue") .setDescription( - `Successfully ${bold("enabled")} the ${name} system for \`${interaction.guild!.name}\`` + `Successfully ${bold("enabled")} the ${name} system for \`${ + interaction.guild!.name + }\`` ), ], components: [goBackRow], @@ -450,7 +475,7 @@ export class SettingsCommand extends Command { } if (name === "modlog" || name == "auditlog" || name === "welcome") { - name = name + "Id"; + name += "Id"; data = { logging: { update: { @@ -491,7 +516,11 @@ export class SettingsCommand extends Command { }) .setColor("Blue") .setDescription( - `Successfully ${bold("disabled")} the ${name.endsWith("Id") ? name.split("Id")[0] : name} ${name.endsWith("Id") ? "channel" : "system"} for \`${interaction.guild!.name}\`` + `Successfully ${bold("disabled")} the ${ + name.endsWith("Id") ? name.split("Id")[0] : name + } ${name.endsWith("Id") ? "channel" : "system"} for \`${ + interaction.guild!.name + }\`` ), ], components: [goBackRow], @@ -499,7 +528,7 @@ export class SettingsCommand extends Command { } if (id === "exit") { - collector.emit("dispose", componentInteraction); + collector.stop(); } } @@ -618,7 +647,9 @@ export class SettingsCommand extends Command { iconURL: interaction.user.displayAvatarURL(), }) .setDescription( - `Run the \`/settings\` command again to change the settings for \`${interaction.guild!.name}\`` + `Run the \`/settings\` command again to change the settings for \`${ + interaction.guild!.name + }\`` ) .setColor("Blue"); diff --git a/src/listeners/client/chatInputCommandDenied.ts b/src/listeners/client/chatInputCommandDenied.ts index e028158..9684710 100644 --- a/src/listeners/client/chatInputCommandDenied.ts +++ b/src/listeners/client/chatInputCommandDenied.ts @@ -1,4 +1,3 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener, @@ -7,10 +6,17 @@ import { } from "@sapphire/framework"; import { ChatInputCommandInteraction } from "discord.js"; -@ApplyOptions({ - event: Events.ChatInputCommandDenied, -}) export class ChatInputCommandDeniedListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.ChatInputCommandDenied, + }); + } + public async run( error: UserError, { interaction }: ChatInputCommandDeniedPayload diff --git a/src/listeners/client/chatInputCommandSuccess.ts b/src/listeners/client/chatInputCommandSuccess.ts index 853e531..63c73d4 100644 --- a/src/listeners/client/chatInputCommandSuccess.ts +++ b/src/listeners/client/chatInputCommandSuccess.ts @@ -1,14 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener, type ChatInputCommandSuccessPayload, } from "@sapphire/framework"; -@ApplyOptions({ - event: Events.ChatInputCommandSuccess, -}) export class ChatInputCommandSuccessListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.ChatInputCommandSuccess, + }); + } + public async run({ command, interaction }: ChatInputCommandSuccessPayload) { this.container.logger.info( `The /${command.name} command was ran by ${interaction.user.tag} successfully.` diff --git a/src/listeners/client/guildCreate.ts b/src/listeners/client/guildCreate.ts index 3b9f319..6e11b9c 100644 --- a/src/listeners/client/guildCreate.ts +++ b/src/listeners/client/guildCreate.ts @@ -1,11 +1,17 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import type { Guild } from "discord.js"; -@ApplyOptions({ - event: Events.GuildCreate, -}) export class GuildCreateListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildCreate, + }); + } + public run(guild: Guild) { return this.container.logger.info(`Joined ${guild.name} (${guild.id})`); } diff --git a/src/listeners/client/guildDelete.ts b/src/listeners/client/guildDelete.ts index 4b51995..1ad2dd8 100644 --- a/src/listeners/client/guildDelete.ts +++ b/src/listeners/client/guildDelete.ts @@ -1,11 +1,17 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import type { Guild } from "discord.js"; -@ApplyOptions({ - event: Events.GuildCreate, -}) export class GuildDeleteListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildDelete, + }); + } + public run(guild: Guild) { return this.container.logger.info(`Left ${guild.name} (${guild.id})`); } diff --git a/src/listeners/client/ready.ts b/src/listeners/client/ready.ts index f3118d5..32141f3 100644 --- a/src/listeners/client/ready.ts +++ b/src/listeners/client/ready.ts @@ -1,12 +1,18 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import type { Client } from "discord.js"; -@ApplyOptions({ - once: true, - event: Events.ClientReady, -}) export class ReadyListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + once: true, + event: Events.ClientReady, + }); + } + public run(client: Client) { return this.container.logger.info(`Logged in as ${client.user!.tag}!`); } diff --git a/src/listeners/guild/channelCreate.ts b/src/listeners/guild/channelCreate.ts index 6d5843a..442d174 100644 --- a/src/listeners/guild/channelCreate.ts +++ b/src/listeners/guild/channelCreate.ts @@ -1,15 +1,22 @@ -import { ChannelTypeNames } from "../../types/index.js"; -import { ApplyOptions } from "@sapphire/decorators"; +import { ChannelTypeNames, logChecks, LoggingTypes } from "../../utils"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, type GuildChannel } from "discord.js"; -@ApplyOptions({ - event: Events.ChannelCreate, -}) export class ChannelCreateListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.ChannelCreate, + }); + } + public async run(channel: GuildChannel) { - const auditlogChannel = await this.container.helpers.auditlogChecks( - channel.guild + const auditlogChannel = await logChecks( + channel.guild, + LoggingTypes.AUDITLOG ); if (!auditlogChannel) return; diff --git a/src/listeners/guild/channelDelete.ts b/src/listeners/guild/channelDelete.ts index ce58faf..7c16591 100644 --- a/src/listeners/guild/channelDelete.ts +++ b/src/listeners/guild/channelDelete.ts @@ -1,15 +1,22 @@ -import { ChannelTypeNames } from "../../types/index.js"; -import { ApplyOptions } from "@sapphire/decorators"; +import { ChannelTypeNames, logChecks, LoggingTypes } from "../../utils"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, channelMention, type GuildChannel } from "discord.js"; -@ApplyOptions({ - event: Events.ChannelDelete, -}) export class ChannelDeleteListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.ChannelDelete, + }); + } + public async run(channel: GuildChannel) { - const auditlogChannel = await this.container.helpers.auditlogChecks( - channel.guild + const auditlogChannel = await logChecks( + channel.guild, + LoggingTypes.AUDITLOG ); if (!auditlogChannel) return; diff --git a/src/listeners/guild/channelUpdate.ts b/src/listeners/guild/channelUpdate.ts index b876a6f..81673b3 100644 --- a/src/listeners/guild/channelUpdate.ts +++ b/src/listeners/guild/channelUpdate.ts @@ -1,15 +1,22 @@ -import { ChannelTypeNames } from "../../types/index.js"; -import { ApplyOptions } from "@sapphire/decorators"; +import { ChannelTypeNames, logChecks, LoggingTypes } from "../../utils"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, channelMention, type GuildChannel } from "discord.js"; -@ApplyOptions({ - event: Events.ChannelUpdate, -}) export class ChannelUpdateListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.ChannelUpdate, + }); + } + public async run(channel: GuildChannel) { - const auditlogChannel = await this.container.helpers.auditlogChecks( - channel.guild + const auditlogChannel = await logChecks( + channel.guild, + LoggingTypes.AUDITLOG ); if (!auditlogChannel) return; diff --git a/src/listeners/guild/guildMemberAdd.ts b/src/listeners/guild/guildMemberAdd.ts index 59bc150..a5123b4 100644 --- a/src/listeners/guild/guildMemberAdd.ts +++ b/src/listeners/guild/guildMemberAdd.ts @@ -1,15 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Listener, Events } from "@sapphire/framework"; import { EmbedBuilder, type GuildMember } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.GuildMemberAdd, -}) export class GuildMemberAddListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildMemberAdd, + }); + } + public override async run(member: GuildMember) { - const welcomeChannel = await this.container.helpers.welcomeChecks( - member.guild - ); + const welcomeChannel = await logChecks(member.guild, LoggingTypes.WELCOME); if (!welcomeChannel) return; const { guild } = member; diff --git a/src/listeners/guild/guildMemberRemove.ts b/src/listeners/guild/guildMemberRemove.ts index b27ed2a..39f49ca 100644 --- a/src/listeners/guild/guildMemberRemove.ts +++ b/src/listeners/guild/guildMemberRemove.ts @@ -1,15 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Listener, Events } from "@sapphire/framework"; import { EmbedBuilder, type GuildMember } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.GuildMemberRemove, -}) export class GuildMemberRemoveListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildMemberRemove, + }); + } + public override async run(member: GuildMember) { - const welcomeChannel = await this.container.helpers.welcomeChecks( - member.guild - ); + const welcomeChannel = await logChecks(member.guild, LoggingTypes.WELCOME); if (!welcomeChannel) return; const { guild } = member; diff --git a/src/listeners/guild/messageDelete.ts b/src/listeners/guild/messageDelete.ts index fd93b01..f34c898 100644 --- a/src/listeners/guild/messageDelete.ts +++ b/src/listeners/guild/messageDelete.ts @@ -1,13 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, type Message } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.MessageDelete, -}) export class MessageDeleteListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.MessageDelete, + }); + } + public async run(message: Message) { - const channel = await this.container.helpers.auditlogChecks(message.guild); + const channel = await logChecks(message.guild, LoggingTypes.AUDITLOG); if (!channel) return; if (message.author.bot) return; diff --git a/src/listeners/guild/messageUpdate.ts b/src/listeners/guild/messageUpdate.ts index 75fefa7..5e12f41 100644 --- a/src/listeners/guild/messageUpdate.ts +++ b/src/listeners/guild/messageUpdate.ts @@ -1,15 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, type Message } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.MessageUpdate, -}) export class MessageUpdateListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.MessageUpdate, + }); + } + public async run(oldMessage: Message, newMessage: Message) { - const channel = await this.container.helpers.auditlogChecks( - oldMessage.guild - ); + const channel = await logChecks(oldMessage.guild, LoggingTypes.AUDITLOG); if (!channel) return; if (oldMessage.content === newMessage.content || oldMessage.author.bot) diff --git a/src/listeners/guild/roleCreate.ts b/src/listeners/guild/roleCreate.ts index f2fa741..6423a5c 100644 --- a/src/listeners/guild/roleCreate.ts +++ b/src/listeners/guild/roleCreate.ts @@ -1,13 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, roleMention, type Role } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.GuildRoleCreate, -}) export class RoleCreateListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildRoleCreate, + }); + } + public async run(role: Role) { - const channel = await this.container.helpers.auditlogChecks(role.guild); + const channel = await logChecks(role.guild, LoggingTypes.AUDITLOG); if (!channel) return; const embed = new EmbedBuilder() diff --git a/src/listeners/guild/roleDelete.ts b/src/listeners/guild/roleDelete.ts index c63cf72..1ce06bb 100644 --- a/src/listeners/guild/roleDelete.ts +++ b/src/listeners/guild/roleDelete.ts @@ -1,13 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, roleMention, type Role } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.GuildRoleDelete, -}) export class RoleDeleteListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildRoleDelete, + }); + } + public async run(role: Role) { - const channel = await this.container.helpers.auditlogChecks(role.guild); + const channel = await logChecks(role.guild, LoggingTypes.AUDITLOG); if (!channel) return; const embed = new EmbedBuilder() diff --git a/src/listeners/guild/roleUpdate.ts b/src/listeners/guild/roleUpdate.ts index 8f43190..b5f1f56 100644 --- a/src/listeners/guild/roleUpdate.ts +++ b/src/listeners/guild/roleUpdate.ts @@ -1,13 +1,20 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { Events, Listener } from "@sapphire/framework"; import { EmbedBuilder, roleMention, type Role } from "discord.js"; +import { logChecks, LoggingTypes } from "../../utils"; -@ApplyOptions({ - event: Events.GuildRoleUpdate, -}) export class RoleUpdateListener extends Listener { + public constructor( + context: Listener.LoaderContext, + options: Listener.Options + ) { + super(context, { + ...options, + event: Events.GuildRoleUpdate, + }); + } + public async run(oldRole: Role, newRole: Role) { - const channel = await this.container.helpers.auditlogChecks(oldRole.guild); + const channel = await logChecks(oldRole.guild, LoggingTypes.AUDITLOG); if (!channel) return; const embed = new EmbedBuilder() diff --git a/src/preconditions/global/guildBanned.ts b/src/preconditions/global/guildBanned.ts index 708322a..6557e6e 100644 --- a/src/preconditions/global/guildBanned.ts +++ b/src/preconditions/global/guildBanned.ts @@ -1,4 +1,3 @@ -import { ApplyOptions } from "@sapphire/decorators"; import { AllFlowsPrecondition } from "@sapphire/framework"; import type { ChatInputCommandInteraction, @@ -6,10 +5,17 @@ import type { Message, } from "discord.js"; -@ApplyOptions({ - position: 20, -}) export class GuildBannedPrecondition extends AllFlowsPrecondition { + public constructor( + context: AllFlowsPrecondition.LoaderContext, + options: AllFlowsPrecondition.Options + ) { + super(context, { + ...options, + position: 20, + }); + } + public override chatInputRun(interaction: ChatInputCommandInteraction) { return this.checkBanned(interaction.guildId); }