From 4530b265e7dfea1c62382c430291395596a8a343 Mon Sep 17 00:00:00 2001 From: Supositware Date: Wed, 17 Aug 2022 16:21:58 +0200 Subject: [PATCH] Move to scripts folder and add new owner commands --- commands/owner/deletetweet.js | 37 ++++++++++ commands/owner/die.js | 7 +- commands/owner/ublacklist.js | 70 +++++++++++++++++++ deploy-owner-commands.cjs | 18 ----- .../deploy-commands.cjs | 4 ++ scripts/deploy-owner-commands.cjs | 42 +++++++++++ 6 files changed, 154 insertions(+), 24 deletions(-) create mode 100644 commands/owner/deletetweet.js create mode 100644 commands/owner/ublacklist.js delete mode 100644 deploy-owner-commands.cjs rename deploy-commands.cjs => scripts/deploy-commands.cjs (96%) create mode 100644 scripts/deploy-owner-commands.cjs diff --git a/commands/owner/deletetweet.js b/commands/owner/deletetweet.js new file mode 100644 index 0000000..f5842a4 --- /dev/null +++ b/commands/owner/deletetweet.js @@ -0,0 +1,37 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import Twit from 'twit'; + +import dotenv from 'dotenv'; +dotenv.config(); +const { twiConsumer, twiConsumerSecret, twiToken, twiTokenSecret } = process.env; + +export default { + data: new SlashCommandBuilder() + .setName('deletewteet') + .setDescription('Delete a tweet') + .addStringOption(option => + option.setName('tweetid') + .setDescription('The id of the tweet you wish to delete.') + .setRequired(true)), + ownerOnly: true, + async execute(interaction) { + await interaction.deferReply(); + try { + const T = new Twit({ + consumer_key: twiConsumer, + consumer_secret: twiConsumerSecret, + access_token: twiToken, + access_token_secret: twiTokenSecret, + }); + + T.post('statuses/destroy', { + id: interaction.options.getString('tweetid'), + }); + return interaction.editReply('Tweet have been deleted!'); + } + catch (err) { + console.error(err); + return interaction.editReply('Oh no, an error has occurred :('); + } + }, +}; diff --git a/commands/owner/die.js b/commands/owner/die.js index 9caf89a..30a3fb7 100644 --- a/commands/owner/die.js +++ b/commands/owner/die.js @@ -1,17 +1,12 @@ import { SlashCommandBuilder } from '@discordjs/builders'; -import dotenv from 'dotenv'; import process from 'node:process'; -dotenv.config(); -const { ownerId } = process.env; export default { data: new SlashCommandBuilder() .setName('die') .setDescription('Kill the bot'), + ownerOnly: true, async execute(interaction) { - if (interaction.user.id !== ownerId) { - return interaction.reply({ content: '❌ This command is reserved for the owner!', ephemeral: true }); - } console.log('\x1b[31m\x1b[47m\x1b[5mSHUTING DOWN!!!!!\x1b[0m'); await interaction.reply({ content: 'Good bye', ephemeral: true }) .then(() => { diff --git a/commands/owner/ublacklist.js b/commands/owner/ublacklist.js new file mode 100644 index 0000000..889054f --- /dev/null +++ b/commands/owner/ublacklist.js @@ -0,0 +1,70 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import { MessageButton, MessageActionRow } from 'discord.js'; +import db from '../../models/index.js'; +const Blacklists = db.Blacklists; + +export default { + data: new SlashCommandBuilder() + .setName('ublacklist') + .setDescription('Blacklist a user from the bot') + .addStringOption(option => + option.setName('command') + .setDescription('Which command do you want to get a user blacklisted from?') + .setRequired(true)) + .addStringOption(option => + option.setName('userid') + .setDescription('Who do you want to blacklist?') + .setRequired(true)) + .addStringOption(option => + option.setName('reason') + .setDescription('The reason of the blacklist.') + .setRequired(false)), + ownerOnly: true, + async execute(interaction) { + await interaction.deferReply({ ephemeral: true }); + const client = interaction.client; + const command = interaction.options.getString('command'); + const userid = interaction.options.getString('userid'); + const reason = interaction.options.getString('reason'); + + const blacklist = await Blacklists.findOne({ where: { type:command, uid:userid } }); + + if (!blacklist) { + const body = { type:command, uid: userid, reason: reason }; + Blacklists.create(body); + let user = userid; + if (command !== 'guild') {user = client.users.resolve(userid).tag;} + + return interaction.editReply(`${user} has been blacklisted from ${command} with the following reason ${reason}`); + } + else { + const row = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId('yes') + .setLabel('Yes') + .setStyle('PRIMARY'), + ) + .addComponents( + new MessageButton() + .setCustomId('no') + .setLabel('No') + .setStyle('DANGER'), + ); + + await interaction.editReply({ content: 'This user is already blacklisted, do you want to unblacklist him?', ephemeral: true, components: [row] }); + + interaction.client.once('interactionCreate', async (interactionMenu) => { + if (!interactionMenu.isButton) return; + interactionMenu.update({ components: [] }); + if (interactionMenu.customId === 'yes') { + Blacklists.destroy({ where: { type:command, uid:userid } }); + return interaction.editReply(`The following ID have been unblacklisted from ${command}: ${userid}`); + } + else { + return interaction.editReply('No one has been unblacklisted.'); + } + }); + } + }, +}; diff --git a/deploy-owner-commands.cjs b/deploy-owner-commands.cjs deleted file mode 100644 index 8351ea8..0000000 --- a/deploy-owner-commands.cjs +++ /dev/null @@ -1,18 +0,0 @@ -const { SlashCommandBuilder } = require('@discordjs/builders'); -const { REST } = require('@discordjs/rest'); -const { Routes } = require('discord-api-types/v9'); -require('dotenv').config(); -const { clientId, guildId, token } = process.env; - -const commands = [ - new SlashCommandBuilder() - .setName('die') - .setDescription('Kill the bot'), -] - .map(command => command.toJSON()); - -const rest = new REST({ version: '9' }).setToken(token); - -rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) - .then(() => console.log(`Successfully registered application commands for the guild ${guildId}.`)) - .catch(console.error); diff --git a/deploy-commands.cjs b/scripts/deploy-commands.cjs similarity index 96% rename from deploy-commands.cjs rename to scripts/deploy-commands.cjs index eb3d6e1..ea27e3c 100644 --- a/deploy-commands.cjs +++ b/scripts/deploy-commands.cjs @@ -69,6 +69,10 @@ const commands = [ option.setName('board') .setDescription('The board you wish to see') .setRequired(true)), + + new SlashCommandBuilder() + .setName('donator') + .setDescription('All the people who donated for this bot <3'), ] .map(command => command.toJSON()); diff --git a/scripts/deploy-owner-commands.cjs b/scripts/deploy-owner-commands.cjs new file mode 100644 index 0000000..d1fd137 --- /dev/null +++ b/scripts/deploy-owner-commands.cjs @@ -0,0 +1,42 @@ +const { SlashCommandBuilder } = require('@discordjs/builders'); +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +require('dotenv').config(); +const { clientId, guildId, token } = process.env; + +const commands = [ + new SlashCommandBuilder() + .setName('die') + .setDescription('Kill the bot'), + + new SlashCommandBuilder() + .setName('ublacklist') + .setDescription('Blacklist a user from the bot') + .addStringOption(option => + option.setName('command') + .setDescription('Which command do you want to get a user blacklisted from?') + .setRequired(true)) + .addStringOption(option => + option.setName('userid') + .setDescription('Who do you want to blacklist?') + .setRequired(true)) + .addStringOption(option => + option.setName('reason') + .setDescription('The reason of the blacklist.') + .setRequired(false)), + + new SlashCommandBuilder() + .setName('deletewteet') + .setDescription('Delete a tweet') + .addStringOption(option => + option.setName('tweetid') + .setDescription('The id of the tweet you wish to delete.') + .setRequired(true)), +] + .map(command => command.toJSON()); + +const rest = new REST({ version: '9' }).setToken(token); + +rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) + .then(() => console.log(`Successfully registered application commands for the guild ${guildId}.`)) + .catch(console.error);