From f7e35029f7b16aa142e71207f2efa079a1fba9bd Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 4 Jan 2024 21:37:11 +0100 Subject: [PATCH 1/4] Updated subcommands to use default export --- src/commands/guild.ts | 6 +++--- src/commands/guild/info.ts | 6 ++---- src/commands/guild/member.ts | 6 ++---- src/commands/guild/top.ts | 6 ++---- src/commands/staff.ts | 6 +++--- src/commands/staff/beast.ts | 2 +- src/commands/staff/help.ts | 2 +- src/commands/staff/updatediscordroles.ts | 2 +- 8 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/commands/guild.ts b/src/commands/guild.ts index 58207ba..ac18c58 100644 --- a/src/commands/guild.ts +++ b/src/commands/guild.ts @@ -1,9 +1,9 @@ import { SlashCommandBuilder } from "discord.js" import { color, devMessage } from "../../config/options.json" import { Command } from "../interfaces" -import guildMember = require("./guild/member") -import guildInfo = require("./guild/info") -import guildTop = require("./guild/top") +import guildMember from "./guild/member" +import guildInfo from "./guild/info" +import guildTop from "./guild/top" export = { name: "guild", diff --git a/src/commands/guild/info.ts b/src/commands/guild/info.ts index 8162af5..023322b 100644 --- a/src/commands/guild/info.ts +++ b/src/commands/guild/info.ts @@ -9,7 +9,7 @@ import { color, devMessage } from "../../../config/options.json" import { ChatInputCommandInteraction } from "discord.js" import { GuildData } from "../../interfaces/Guild" -async function guildInfo( +export default async function guildInfo( interaction: ChatInputCommandInteraction, ): Promise { await interaction.deferReply() @@ -241,6 +241,4 @@ async function guildInfo( }, ], }) -} - -export = guildInfo +} \ No newline at end of file diff --git a/src/commands/guild/member.ts b/src/commands/guild/member.ts index a369cd1..9a09b49 100644 --- a/src/commands/guild/member.ts +++ b/src/commands/guild/member.ts @@ -2,7 +2,7 @@ import { getUUID, getPlayer, getGuild, getHeadURL } from "../../utils/Hypixel" import { color, devMessage } from "../../../config/options.json" import { ChatInputCommandInteraction } from "discord.js" -async function guildMember( +export default async function guildMember( interaction: ChatInputCommandInteraction, ): Promise { await interaction.deferReply() @@ -211,6 +211,4 @@ async function guildMember( }, ], }) -} - -export = guildMember +} \ No newline at end of file diff --git a/src/commands/guild/top.ts b/src/commands/guild/top.ts index ee5c3b0..0a77f1a 100644 --- a/src/commands/guild/top.ts +++ b/src/commands/guild/top.ts @@ -5,7 +5,7 @@ import { GuildData } from "../../interfaces/Guild" import Illegitimate from "../../utils/Illegitimate" const redis = Illegitimate.redis -async function guildTop( +export default async function guildTop( interaction: ChatInputCommandInteraction, ): Promise { await interaction.deferReply() @@ -291,6 +291,4 @@ async function guildTop( }, ], }) -} - -export = guildTop +} \ No newline at end of file diff --git a/src/commands/staff.ts b/src/commands/staff.ts index 61636df..b7fd962 100644 --- a/src/commands/staff.ts +++ b/src/commands/staff.ts @@ -1,9 +1,9 @@ import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js" import { color, devMessage } from "../../config/options.json" import { Command } from "../interfaces" -import { help } from "./staff/help" -import { beast } from "./staff/beast" -import { updateDiscordRoles } from "./staff/updatediscordroles" +import help from "./staff/help" +import beast from "./staff/beast" +import updateDiscordRoles from "./staff/updatediscordroles" export = { name: "staff", diff --git a/src/commands/staff/beast.ts b/src/commands/staff/beast.ts index 821dc84..d747fea 100644 --- a/src/commands/staff/beast.ts +++ b/src/commands/staff/beast.ts @@ -19,7 +19,7 @@ import { } from "../../utils/Hypixel" import { ChatInputCommandInteraction } from "discord.js" -export async function beast( +export default async function beast( interaction: ChatInputCommandInteraction, ): Promise { await interaction.deferReply() diff --git a/src/commands/staff/help.ts b/src/commands/staff/help.ts index d159c27..a6e1150 100644 --- a/src/commands/staff/help.ts +++ b/src/commands/staff/help.ts @@ -2,7 +2,7 @@ import { ChatInputCommandInteraction } from "discord.js" import { color, devMessage } from "../../../config/options.json" import { ExtendedClient as Client } from "../../utils/Client" -export async function help( +export default async function help( interaction: ChatInputCommandInteraction, client: Client, ): Promise { diff --git a/src/commands/staff/updatediscordroles.ts b/src/commands/staff/updatediscordroles.ts index 7869f7b..2d3da76 100644 --- a/src/commands/staff/updatediscordroles.ts +++ b/src/commands/staff/updatediscordroles.ts @@ -6,7 +6,7 @@ import env from "../../utils/Env" import { getGuild } from "../../utils/Hypixel" import { GuildData } from "../../interfaces" -export async function updateDiscordRoles( +export default async function updateDiscordRoles( interaction: ChatInputCommandInteraction, ): Promise { const discordMember = interaction.member as GuildMember From 2edbaba74235d82c72827f87e3ba50c001d288d5 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 4 Jan 2024 22:11:09 +0100 Subject: [PATCH 2/4] Fixing dev deploy script --- scripts/dev-deploy.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/dev-deploy.ts b/scripts/dev-deploy.ts index ba5f26c..0a5a7e3 100644 --- a/scripts/dev-deploy.ts +++ b/scripts/dev-deploy.ts @@ -5,17 +5,17 @@ import { Command } from "../src/interfaces" const rest = new REST({ version: "10" }).setToken(env.dev.devtoken!) const commands: RESTPutAPIApplicationCommandsJSONBody = [] -const commandFiles = fs.readdirSync("./dist/src/commands/").filter(file => file.endsWith(".js")) -const contentMenuCommands = fs.readdirSync("./dist/src/commands-contextmenu/").filter(file => file.endsWith(".js")) +const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(".ts")) +const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(".ts")) for (const file of commandFiles) { - const command: Command = require(`../dist/src/commands/${file}`) + const command: Command = require(`../src/commands/${file}`) if (command.dev) { commands.push(command.data.toJSON()) } } for (const file of contentMenuCommands) { - const command: Command = require(`../dist/src/commands-contextmenu/${file}`) + const command: Command = require(`../src/commands-contextmenu/${file}`) if (command.dev) { commands.push(command.data.toJSON()) } From 02c159196667d165221a617150e332c63e2105d8 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 4 Jan 2024 22:12:18 +0100 Subject: [PATCH 3/4] Starting the counting system --- config/roles.json | 3 +- src/commands/counting.ts | 91 ++++++++++++++++++++++++++++++++++ src/commands/counting/ban.ts | 52 +++++++++++++++++++ src/commands/counting/setup.ts | 44 ++++++++++++++++ src/commands/counting/unban.ts | 52 +++++++++++++++++++ 5 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/commands/counting.ts create mode 100644 src/commands/counting/ban.ts create mode 100644 src/commands/counting/setup.ts create mode 100644 src/commands/counting/unban.ts diff --git a/config/roles.json b/config/roles.json index d5a26fe..b70a84b 100644 --- a/config/roles.json +++ b/config/roles.json @@ -11,5 +11,6 @@ "defaultMember": "722386801930797056", "admin": "528549814846095360", "helper": "592371991294771226", - "muted": "594355088932339732" + "muted": "594355088932339732", + "countingBanned": "1192183486128341072" } diff --git a/src/commands/counting.ts b/src/commands/counting.ts new file mode 100644 index 0000000..8fa5997 --- /dev/null +++ b/src/commands/counting.ts @@ -0,0 +1,91 @@ +import { ChannelType, PermissionFlagsBits, SlashCommandBuilder } from "discord.js" +import { color, devMessage } from "../../config/options.json" +import { Command } from "../interfaces" +import setup from "./counting/setup" +import ban from "./counting/ban" +import unban from "./counting/unban" + +export = { + name: "counting", + description: "counting subcommands", + type: "slash", + dev: true, + public: true, + subcommands: true, + + data: new SlashCommandBuilder() + .setName("counting") + .setDescription("counting subcommands") + .addSubcommand(subcommand => + subcommand + .setName("setup") + .setDescription("Setup counting channel") + .addChannelOption(option => + option + .setName("channel") + .setDescription("The channel to setup counting in") + .setRequired(true) + .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement) + ), + ) + .addSubcommand(subcommand => + subcommand + .setName("ban") + .setDescription("Ban a user from counting") + .addUserOption(option => + option + .setName("user") + .setDescription("The user to ban") + .setRequired(true) + ) + ) + .addSubcommand(subcommand => + subcommand + .setName("unban") + .setDescription("Unban a user from counting") + .addUserOption(option => + option + .setName("user") + .setDescription("The user to ban") + .setRequired(true) + ) + ) + .setDefaultMemberPermissions(PermissionFlagsBits.Administrator) + .setDMPermission(false), + + async execute(interaction) { + const subcommand = interaction.options.getSubcommand() + const embedColor = Number(color.replace("#", "0x")) + + if (subcommand === "setup") { + setup(interaction) + return + } + + if (subcommand === "ban") { + ban(interaction) + return + } + + if (subcommand === "unban") { + unban(interaction) + return + } + + await interaction.reply({ + embeds: [ + { + description: "This command is currently under development", + color: embedColor, + footer: { + text: interaction.guild!.name + " | " + devMessage, + icon_url: + interaction.guild!.iconURL({ + forceStatic: false, + }) || undefined, + }, + }, + ], + }) + }, +} as Command diff --git a/src/commands/counting/ban.ts b/src/commands/counting/ban.ts new file mode 100644 index 0000000..1e8006a --- /dev/null +++ b/src/commands/counting/ban.ts @@ -0,0 +1,52 @@ +import { + ChatInputCommandInteraction, + GuildMember, + userMention, +} from "discord.js" +import { countingBanned } from "../../../config/roles.json" +import { color, devMessage } from "../../../config/options.json" + +export default async function ban( + interaction: ChatInputCommandInteraction, +): Promise { + const member = interaction.options.getMember("user")! as GuildMember + const embedColor = Number(color.replace("#", "0x")) + + if (member.roles.cache.has(countingBanned)) { + await interaction.reply({ + embeds: [ + { + description: + userMention(member.user.id) + + " is currently banned from counting", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: interaction.guild!.name + " | " + devMessage, + }, + }, + ], + }) + } else { + await member.roles.add(countingBanned) + + await interaction.reply({ + embeds: [ + { + description: + userMention(member.user.id) + + " has been banned from counting", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: interaction.guild!.name + " | " + devMessage, + }, + }, + ], + }) + } +} diff --git a/src/commands/counting/setup.ts b/src/commands/counting/setup.ts new file mode 100644 index 0000000..26050c4 --- /dev/null +++ b/src/commands/counting/setup.ts @@ -0,0 +1,44 @@ +import { ChatInputCommandInteraction, GuildTextBasedChannel, channelMention } from "discord.js" +import settingsSchema from "../../schemas/settingsSchema" +import { color, devMessage } from "../../../config/options.json" +import mongoose from "mongoose" + +export default async function setup(interaction: ChatInputCommandInteraction): Promise { + await interaction.deferReply() + + const channel = interaction.options.getChannel("channel") as GuildTextBasedChannel + const embedColor = Number(color.replace("#", "0x")) + + if (await settingsSchema.findOne({ name: "counting" })) { + await settingsSchema.findOneAndUpdate({ name: "counting" }, { name: "counting", channel: channel.id }) + await interaction.editReply({ + embeds: [{ + description: "Counting channel has been updated to " + channelMention(channel.id), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ forceStatic: false })!, + text: interaction.guild!.name + " | " + devMessage + } + }] + }) + } else { + const counting = new settingsSchema({ + _id: new mongoose.Types.ObjectId(), + name: "counting", + value: channel.id + }) + + await counting.save() + + await interaction.editReply({ + embeds: [{ + description: "Counting channel has been set to " + channelMention(channel.id), + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ forceStatic: false })!, + text: interaction.guild!.name + " | " + devMessage + } + }] + }) + } +} \ No newline at end of file diff --git a/src/commands/counting/unban.ts b/src/commands/counting/unban.ts new file mode 100644 index 0000000..cf2f5bd --- /dev/null +++ b/src/commands/counting/unban.ts @@ -0,0 +1,52 @@ +import { + ChatInputCommandInteraction, + GuildMember, + userMention, +} from "discord.js" +import { countingBanned } from "../../../config/roles.json" +import { color, devMessage } from "../../../config/options.json" + +export default async function ban( + interaction: ChatInputCommandInteraction, +): Promise { + const member = interaction.options.getMember("user")! as GuildMember + const embedColor = Number(color.replace("#", "0x")) + + if (!member.roles.cache.has(countingBanned)) { + await interaction.reply({ + embeds: [ + { + description: + userMention(member.user.id) + + " is currently not banned from counting", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: interaction.guild!.name + " | " + devMessage, + }, + }, + ], + }) + } else { + await member.roles.remove(countingBanned) + + await interaction.reply({ + embeds: [ + { + description: + userMention(member.user.id) + + " has been unbanned from counting", + color: embedColor, + footer: { + icon_url: interaction.guild!.iconURL({ + forceStatic: false, + })!, + text: interaction.guild!.name + " | " + devMessage, + }, + }, + ], + }) + } +} From 10c18202c5f31171fe9cea88892c1928ee707ed1 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 4 Jan 2024 22:13:59 +0100 Subject: [PATCH 4/4] Removed dev flag --- src/commands/counting.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/counting.ts b/src/commands/counting.ts index 8fa5997..87e0c43 100644 --- a/src/commands/counting.ts +++ b/src/commands/counting.ts @@ -9,7 +9,7 @@ export = { name: "counting", description: "counting subcommands", type: "slash", - dev: true, + dev: false, public: true, subcommands: true,