mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
59 lines
2.8 KiB
TypeScript
59 lines
2.8 KiB
TypeScript
import { ApplicationCommandType, ApplicationIntegrationType, CheckboxBuilder, Client, ContextMenuCommandBuilder, InteractionContextType, LabelBuilder, MessageContextMenuCommandInteraction, MessageFlags, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
|
|
import { Database } from '../shared/Database';
|
|
|
|
export default {
|
|
name: 'Report Message',
|
|
|
|
data: new ContextMenuCommandBuilder()
|
|
.setName('Report Message')
|
|
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
|
.setContexts(InteractionContextType.Guild)
|
|
.setType(ApplicationCommandType.Message),
|
|
|
|
handler: async function (client: Client, interaction: MessageContextMenuCommandInteraction) {
|
|
try {
|
|
const modal = new ModalBuilder()
|
|
.setCustomId(`report-message_${interaction.targetMessage.channelId}_${interaction.targetMessage.id}`)
|
|
.setTitle(`Report message from ${interaction.targetMessage.member?.displayName ?? interaction.targetMessage.author.displayName}`);
|
|
|
|
const additionalInfoInput = new TextInputBuilder()
|
|
.setCustomId('additional-info')
|
|
.setMaxLength(1000)
|
|
.setStyle(TextInputStyle.Paragraph)
|
|
.setRequired(false);
|
|
|
|
const additionalInfoLabel = new LabelBuilder()
|
|
.setLabel('Additional Information')
|
|
.setDescription('Any additional information? This will help staff understand your report. 1000 characters maximum.')
|
|
.setTextInputComponent(additionalInfoInput);
|
|
|
|
const createTicketCheckbox = new CheckboxBuilder()
|
|
.setCustomId('create-private-help-ticket');
|
|
|
|
const createPrivateTicket = new LabelBuilder()
|
|
.setLabel('Create Private Help Ticket')
|
|
.setDescription('Should a private help ticket be opened with this report? (Does not bypass ticket restrictions)')
|
|
.setCheckboxComponent(createTicketCheckbox);
|
|
|
|
modal.addLabelComponents(additionalInfoLabel, createPrivateTicket);
|
|
|
|
const settings = await Database.getOrCreateSettings(interaction.guildId!);
|
|
if (!settings.moderator_channel_id)
|
|
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Moderator channel missing. Unable to submit report' });
|
|
|
|
const reportsChannel = await interaction.guild!.channels.fetch(settings.moderator_channel_id);
|
|
if (!reportsChannel || !reportsChannel.isSendable())
|
|
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Report channel missing. Unable to submit report' });
|
|
|
|
await interaction.showModal(modal);
|
|
} catch (error) {
|
|
console.error(error);
|
|
if (!interaction.replied) {
|
|
await interaction.reply({
|
|
content: 'Hmm, an error occurred while processing your request. If you receive this error more than once, DM a moderator for further assistance.',
|
|
flags: [MessageFlags.Ephemeral]
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}; |