Rename warnings to notes

This commit is contained in:
Tarrgon
2025-05-29 10:34:11 -04:00
parent b5e631a965
commit 41299da489
8 changed files with 97 additions and 98 deletions
@@ -1,48 +1,47 @@
import { ApplicationCommandOptionType, ApplicationIntegrationType, AutocompleteInteraction, ChatInputCommandInteraction, Client, GuildBasedChannel, InteractionContextType, MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';
import { Database } from '../shared/Database';
import { channelIsInStaffCategory, getE621User } from '../utils';
import { config } from '../config';
import { getWarningMessage } from '../utils/warning-utils';
import { channelIsInStaffCategory } from '../utils';
import { getNoteMessage } from '../utils/note-utils';
export default {
name: 'warnings',
name: 'notes',
data: new SlashCommandBuilder()
.setName('warnings')
.setDescription('Add, view, or remove user warnings.')
.setName('notes')
.setDescription('Add, view, or remove user notes.')
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
.setContexts(InteractionContextType.Guild)
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.addSubcommand(subcommand =>
subcommand
.setName('add')
.setDescription('Add warnings to a user.')
.setDescription('Add notes to a user.')
.addUserOption(option =>
option
.setName('user')
.setDescription('The user to add a warning to.')
.setDescription('The user to add a note to.')
.setRequired(true)
)
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for the warning.')
.setDescription('The reason for the note.')
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('remove')
.setDescription('Remove warnings from a user.')
.setDescription('Remove notes from a user.')
.addUserOption(option =>
option
.setName('user')
.setDescription('The user to remove a warning from.')
.setDescription('The user to remove a note from.')
.setRequired(true)
)
.addIntegerOption(option =>
option
.setName('warning')
.setDescription('The warning to remove.')
.setName('note')
.setDescription('The note to remove.')
.setRequired(true)
.setAutocomplete(true)
)
@@ -50,11 +49,11 @@ export default {
.addSubcommand(subcommand =>
subcommand
.setName('list')
.setDescription("List a user's warnings")
.setDescription("List a user's notes")
.addUserOption(option =>
option
.setName('user')
.setDescription('The user to list the warnings of.')
.setDescription('The user to list the notes of.')
.setRequired(true)
)
),
@@ -70,26 +69,26 @@ export default {
if (subcommand == 'add') {
const reason = interaction.options.getString('reason', true);
await Database.putWarning(user.id, reason, interaction.user.id);
await Database.putNote(user.id, reason, interaction.user.id);
if (isStaffChannel) interaction.editReply('Added warning.');
else interaction.editReply({ content: 'Added warning.' });
if (isStaffChannel) interaction.editReply('Added note.');
else interaction.editReply({ content: 'Added note.' });
} else if (subcommand == 'remove') {
const warningId = interaction.options.getInteger('warning', true);
const noteId = interaction.options.getInteger('note', true);
if (await Database.removeWarning(warningId)) {
if (isStaffChannel) interaction.editReply('Removed warning.');
else interaction.editReply({ content: 'Removed warning.' });
if (await Database.removeNote(noteId)) {
if (isStaffChannel) interaction.editReply('Removed note.');
else interaction.editReply({ content: 'Removed note.' });
} else {
if (isStaffChannel) interaction.editReply('Warning not found.');
else interaction.editReply({ content: 'Warning not found.' });
if (isStaffChannel) interaction.editReply('Note not found.');
else interaction.editReply({ content: 'Note not found.' });
}
} else if (subcommand == 'list') {
const warningMessage = await getWarningMessage(user.id, 1);
const noteMessage = await getNoteMessage(user.id, 1);
if (!warningMessage) return interaction.editReply(`No warnings found for <@${user.id}>`);
if (!noteMessage) return interaction.editReply(`No notes found for <@${user.id}>`);
interaction.editReply(warningMessage);
interaction.editReply(noteMessage);
}
},
autoComplete: async function (client: Client, interaction: AutocompleteInteraction) {
@@ -101,9 +100,9 @@ export default {
const value = interaction.options.getFocused().toLowerCase();
const warnings = await Database.getWarnings(userId);
const notes = await Database.getNotes(userId);
const toRespond = warnings.filter(w => !value ? true : w.reason.toLowerCase().includes(value));
const toRespond = notes.filter(w => !value ? true : w.reason.toLowerCase().includes(value));
if (toRespond.length > 25) toRespond.length = 25;
interaction.respond(toRespond.map((w) => {