From d4a56009fd2d6152f51175d934712b8f8936f5f7 Mon Sep 17 00:00:00 2001
From: Supositware <sup@libtar.de>
Date: Sat, 10 Sep 2022 10:53:05 +0200
Subject: [PATCH] star/shameboard command

---
 commands/admin/shameboard.js | 38 ++++++++++++++++++++++++++++++++++++
 commands/admin/starboard.js  | 38 ++++++++++++++++++++++++++++++++++++
 scripts/deploy-commands.cjs  | 28 ++++++++++++++++++++++++++
 3 files changed, 104 insertions(+)
 create mode 100644 commands/admin/shameboard.js
 create mode 100644 commands/admin/starboard.js

diff --git a/commands/admin/shameboard.js b/commands/admin/shameboard.js
new file mode 100644
index 0000000..a857679
--- /dev/null
+++ b/commands/admin/shameboard.js
@@ -0,0 +1,38 @@
+import { SlashCommandBuilder, PermissionFlagsBits } from 'discord.js';
+import fs from 'node:fs';
+
+export default {
+	data: new SlashCommandBuilder()
+		.setName('shameboard')
+		.setDescription('Set shameboard to the current channel.')
+		.addStringOption(option =>
+			option.setName('emote') 
+				.setDescription('The emote that should be used to enter the shameboard.'))
+		.addStringOption(option =>
+			option.setName('count')
+				.setDescription('How many react for it to enter shameboard.'))
+		.addBooleanOption(option =>
+			option.setName('remove')
+				.setDescription('Remove the shameboard')
+				.setRequired(false)),
+	category: 'admin',
+	userPermissions: [PermissionFlagsBits.ManageChannels],
+	async execute(interaction, args) {
+		if (args.remove) {
+			fs.unlink(`./json/board/shame${interaction.guild.id}.json`, (err) => {
+				if (err) {return interaction.reply('There is no shameboard');}
+				return interaction.reply('Deleted the shameboard');
+			});
+		}
+		else {
+			if (!args.emote || !args.count) return interaction.reply('You are missing the emote or the count arg!');
+			fs.writeFile(`./json/board/shame${interaction.guild.id}.json`, `{"shameboard": "${interaction.channel.id}", "emote": "${args.emote}", "count": "${args.count}"}`, (err) => {
+				if (err) {
+					console.log(err);
+				}
+			});
+
+			return interaction.reply(`This channel have been set as the shameboard with ${args.emote} with the minimum of ${args.count}`);
+		}
+	},
+};
diff --git a/commands/admin/starboard.js b/commands/admin/starboard.js
new file mode 100644
index 0000000..aac6244
--- /dev/null
+++ b/commands/admin/starboard.js
@@ -0,0 +1,38 @@
+import { SlashCommandBuilder, PermissionFlagsBits } from 'discord.js';
+import fs from 'node:fs';
+
+export default {
+	data: new SlashCommandBuilder()
+		.setName('starboard')
+		.setDescription('Set starboard to the current channel.')
+		.addStringOption(option =>
+			option.setName('emote')
+				.setDescription('The emote that should be used to enter the starboard.'))
+		.addStringOption(option =>
+			option.setName('count')
+				.setDescription('How many react for it to enter starboard.'))
+		.addBooleanOption(option =>
+			option.setName('remove')
+				.setDescription('Remove the starboard')
+				.setRequired(false)),
+	category: 'admin',
+	userPermissions: [PermissionFlagsBits.ManageChannels],
+	async execute(interaction, args) {
+		if (args.remove) {
+			fs.unlink(`./json/board/star${interaction.guild.id}.json`, (err) => {
+				if (err) {return interaction.reply('There is no starboard');}
+				return interaction.reply('Deleted the starboard');
+			});
+		}
+		else {
+			if (!args.emote || !args.count) return interaction.reply('You are missing the emote or the count arg!');
+			fs.writeFile(`./json/board/star${interaction.guild.id}.json`, `{"starboard": "${interaction.channel.id}", "emote": "${args.emote}", "count": "${args.count}"}`, (err) => {
+				if (err) {
+					console.log(err);
+				}
+			});
+
+			return interaction.reply(`This channel have been set as the starboard with ${args.emote} with the minimum of ${args.count}`);
+		}
+	},
+};
diff --git a/scripts/deploy-commands.cjs b/scripts/deploy-commands.cjs
index 81dfa21..3371e14 100644
--- a/scripts/deploy-commands.cjs
+++ b/scripts/deploy-commands.cjs
@@ -193,6 +193,34 @@ const commands = [
 		.addStringOption(option =>
 			option.setName('command')
 				.setDescription('The command you want more details about.')),
+
+	new SlashCommandBuilder()
+		.setName('shameboard')
+		.setDescription('Set shameboard to the current channel.')
+		.addStringOption(option =>
+			option.setName('emote')
+				.setDescription('The emote that should be used to enter the shameboard.'))
+		.addStringOption(option =>
+			option.setName('count')
+				.setDescription('How many react for it to enter shameboard.'))
+		.addBooleanOption(option =>
+			option.setName('remove')
+				.setDescription('Remove the shameboard')
+				.setRequired(false)),
+
+	new SlashCommandBuilder()
+		.setName('starboard')
+		.setDescription('Set starboard to the current channel.')
+		.addStringOption(option =>
+			option.setName('emote')
+				.setDescription('The emote that should be used to enter the starboard.'))
+		.addStringOption(option =>
+			option.setName('count')
+				.setDescription('How many react for it to enter starboard.'))
+		.addBooleanOption(option =>
+			option.setName('remove')
+				.setDescription('Remove the starboard')
+				.setRequired(false)),
 ]
 	.map(command => command.toJSON());