Move to scripts folder and add new owner commands

This commit is contained in:
Supositware 2022-08-17 16:21:58 +02:00
parent 511111cf59
commit 4530b265e7
6 changed files with 154 additions and 24 deletions

View file

@ -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 :(');
}
},
};

View file

@ -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(() => {

View file

@ -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.');
}
});
}
},
};

View file

@ -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);

View file

@ -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());

View file

@ -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);