WIP: [#1]: Athena Rewrite #1
@@ -0,0 +1,49 @@
|
|||||||
|
// External Imports
|
||||||
|
import { Command, CommandBuilder, CommandClient, CommandInteraction, Constants, SlashCommand } from 'athena-prime';
|
||||||
|
|
||||||
|
// Internal Imports
|
||||||
|
import { Database } from '../../shared/Database';
|
||||||
|
import { CreateDefaultEmbed, SetSeverity } from '../../utils';
|
||||||
|
|
||||||
|
// ---------------
|
||||||
|
|
||||||
|
@SlashCommand(
|
||||||
|
new CommandBuilder('database', "Essential database functions. THESE ARE POTENTIALLY DESTRUCTIVE ACTIONS, BE SURE!")
|
||||||
|
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
||||||
|
.setContexts(Constants.InteractionContextType.Guild)
|
||||||
|
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
||||||
|
.setMemberPermission(Constants.PermissionFlagsBits.Administrator)
|
||||||
|
|
||||||
|
.addSubcommand('purge-user', 'Purge user messages from the database.', builder =>
|
||||||
|
builder.addUserOption('user', 'The user to purge.', true)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
class DatabaseCommand extends Command<CommandClient> {
|
||||||
|
cooldown = 60;
|
||||||
|
userPermissions = [Constants.PermissionFlagsBits.Administrator];
|
||||||
|
|
||||||
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
||||||
|
if (!interaction.inGuild() || !interaction.subcommand) return;
|
||||||
|
|
||||||
|
await interaction.defer();
|
||||||
|
|
||||||
|
switch (interaction.subcommand.at(0)) {
|
||||||
|
case 'purge-user':
|
||||||
|
const user = interaction.getRequiredMember('user');
|
||||||
|
await Database.purgeMessagesFrom(user.id);
|
||||||
|
|
||||||
|
await interaction.createMessage({
|
||||||
|
embeds: [{
|
||||||
|
...CreateDefaultEmbed(context),
|
||||||
|
...SetSeverity('success'),
|
||||||
|
|
||||||
|
description: `Executed user-purge on ${user.mention}.`
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new DatabaseCommand('database');
|
||||||
@@ -8,12 +8,12 @@ import { CreateDefaultEmbed, SetSeverity } from '../../utils';
|
|||||||
// ---------------
|
// ---------------
|
||||||
|
|
||||||
@SlashCommand(
|
@SlashCommand(
|
||||||
new CommandBuilder('rename-channel', 'Rename the general channel.')
|
new CommandBuilder('rename-general', 'Rename the general channel.')
|
||||||
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
.setIntegrationTypes(Constants.ApplicationIntegrationType.GuildInstall)
|
||||||
.setContexts(Constants.InteractionContextType.Guild)
|
.setContexts(Constants.InteractionContextType.Guild)
|
||||||
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
.setCommandType(Constants.ApplicationCommandType.ChatInput)
|
||||||
.setMemberPermission(Constants.PermissionFlagsBits.ManageChannels)
|
.setMemberPermission(Constants.PermissionFlagsBits.ManageChannels)
|
||||||
.addStringOption({ name: 'name', description: 'The new general chat name.', required: true, max_length: 32 })
|
.addStringOption({ name: 'name', description: 'The new general chat name.', required: true, max_length: 64 })
|
||||||
)
|
)
|
||||||
class RenameGeneralCommand extends Command<CommandClient> {
|
class RenameGeneralCommand extends Command<CommandClient> {
|
||||||
cooldown = 360;
|
cooldown = 360;
|
||||||
@@ -21,7 +21,7 @@ class RenameGeneralCommand extends Command<CommandClient> {
|
|||||||
|
|
||||||
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
async handleCommand(context: CommandClient<any, any>, interaction: CommandInteraction, data: any) {
|
||||||
if (!interaction.inGuild()) return;
|
if (!interaction.inGuild()) return;
|
||||||
interaction.defer();
|
await interaction.defer();
|
||||||
|
|
||||||
const settings = await Database.GetOrCreateSettings(interaction.guild.id);
|
const settings = await Database.GetOrCreateSettings(interaction.guild.id);
|
||||||
if (!settings.general_chat_id) {
|
if (!settings.general_chat_id) {
|
||||||
@@ -65,4 +65,4 @@ class RenameGeneralCommand extends Command<CommandClient> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new RenameGeneralCommand('name-sync');
|
export default new RenameGeneralCommand('rename-general');
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import { ApplicationIntegrationType, ChatInputCommandInteraction, Client, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
|
|
||||||
import { Database } from '../shared/Database';
|
|
||||||
import { getIdFromInput } from '../utils';
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'database',
|
|
||||||
data: new SlashCommandBuilder()
|
|
||||||
.setName('database')
|
|
||||||
.setDescription('Database access.')
|
|
||||||
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
|
||||||
.setContexts(InteractionContextType.Guild)
|
|
||||||
.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
|
|
||||||
.addSubcommandGroup(subcommandGroup =>
|
|
||||||
subcommandGroup
|
|
||||||
.setName('messages')
|
|
||||||
.setDescription('Access to messages in the database.')
|
|
||||||
.addSubcommand(subcommand =>
|
|
||||||
subcommand
|
|
||||||
.setName('purge')
|
|
||||||
.setDescription("Purge a user's messages from the database.")
|
|
||||||
.addStringOption(option =>
|
|
||||||
option
|
|
||||||
.setName('user')
|
|
||||||
.setDescription('The discord user id, or mention, of the user.')
|
|
||||||
.setRequired(true)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
handler: async function (client: Client, interaction: ChatInputCommandInteraction) {
|
|
||||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
|
||||||
|
|
||||||
const group = interaction.options.getSubcommandGroup(true);
|
|
||||||
|
|
||||||
const subcommand = interaction.options.getSubcommand(true);
|
|
||||||
|
|
||||||
if (group == 'messages') {
|
|
||||||
if (subcommand == 'purge') {
|
|
||||||
const discordUserInput = interaction.options.getString('discord-user', true);
|
|
||||||
|
|
||||||
const idToUse = getIdFromInput(discordUserInput);
|
|
||||||
|
|
||||||
await Database.purgeMessagesFrom(idToUse);
|
|
||||||
|
|
||||||
return interaction.editReply('Messages purged.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user