mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-11-11 07:13:37 -05:00
(modals): Implement report-message modal.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { ApplicationCommandType, ApplicationIntegrationType, Client, ContextMenuCommandBuilder, InteractionContextType, LabelBuilder, MessageContextMenuCommandInteraction, MessageFlags, ModalBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
|
||||
|
||||
import { ApplicationCommandType, ApplicationIntegrationType, CheckboxBuilder, Client, ContextMenuCommandBuilder, InteractionContextType, LabelBuilder, MessageContextMenuCommandInteraction, MessageFlags, ModalBuilder, TextInputBuilder, TextInputStyle } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
|
||||
export default {
|
||||
@@ -28,24 +27,13 @@ export default {
|
||||
.setDescription('Any additional information? This will help staff understand your report. 1000 characters maximum.')
|
||||
.setTextInputComponent(additionalInfoInput);
|
||||
|
||||
const yesNoMenu = new StringSelectMenuBuilder()
|
||||
.setCustomId('create-private-help-ticket')
|
||||
.setRequired(false)
|
||||
.addOptions(
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('No')
|
||||
.setDefault(true)
|
||||
.setValue('no'),
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('Yes')
|
||||
.setDefault(false)
|
||||
.setValue('yes')
|
||||
);
|
||||
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)')
|
||||
.setStringSelectMenuComponent(yesNoMenu);
|
||||
.setCheckboxComponent(createTicketCheckbox);
|
||||
|
||||
modal.addLabelComponents(additionalInfoLabel, createPrivateTicket);
|
||||
|
||||
|
||||
@@ -1,75 +1,52 @@
|
||||
import { ActionRowBuilder, AttachmentBuilder, ButtonBuilder, ButtonStyle, Client, EmbedBuilder, GuildTextBasedChannel, MessageFlags, ModalSubmitInteraction } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
import { canOpenPrivateHelpTicket, createPrivateHelpTicketThread } from '../utils';
|
||||
import { Modal } from '../types';
|
||||
|
||||
export default {
|
||||
name: 'report-message',
|
||||
handler: async function (client: Client, interaction: ModalSubmitInteraction, channelId: string, messageId: string) {
|
||||
class ReportMessageModal implements Modal<Client> {
|
||||
id = 'report-message';
|
||||
|
||||
async execute(context: Client<boolean>, interaction: ModalSubmitInteraction, channelId: string, messageId: string): Promise<void> {
|
||||
if (!interaction.inGuild()) return;
|
||||
await interaction.deferReply({ flags: [MessageFlags.Ephemeral] });
|
||||
|
||||
const guild = await client.guilds.fetch(interaction.guildId!);
|
||||
try {
|
||||
const guild = await context.guilds.fetch(interaction.guildId!);
|
||||
const member = await guild.members.fetch(interaction.user.id);
|
||||
const reportedMessageChannel = await guild.channels.fetch(channelId) as GuildTextBasedChannel;
|
||||
const reportedMessage = await reportedMessageChannel?.messages.fetch(messageId);
|
||||
|
||||
const additionalInfo = interaction.fields.getTextInputValue('additional-info');
|
||||
const createPrivateHelpTicket = interaction.fields.getStringSelectValues('create-private-help-ticket')[0] == 'yes';
|
||||
const createPrivateHelpTicket = interaction.fields.getCheckbox('create-private-help-ticket');
|
||||
|
||||
if (!reportedMessageChannel || !reportedMessage)
|
||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Failed to submit report. Please report this to a staff member.' });
|
||||
if (!reportedMessageChannel || !reportedMessage) throw new Error('Failed to submit report. Please report this to a staff member.');
|
||||
|
||||
const guildSettings = await Database.getOrCreateSettings(interaction.guildId!);
|
||||
const settings = await Database.getOrCreateSettings(interaction.guildId);
|
||||
if (!settings.moderator_channel_id) throw new Error('Report channel missing. Unable to submit report.');
|
||||
|
||||
if (!guildSettings || !guildSettings.moderator_channel_id)
|
||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Report channel missing. Unable to submit report.' });
|
||||
|
||||
const reportsChannel = await interaction.guild!.channels.fetch(guildSettings.moderator_channel_id);
|
||||
|
||||
if (!reportsChannel || !reportsChannel.isSendable())
|
||||
return interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Report channel missing. Unable to submit report.' });
|
||||
const reportsChannel = await interaction.guild!.channels.fetch(settings.moderator_channel_id);
|
||||
if (!reportsChannel || !reportsChannel.isSendable()) throw new Error('Report channel missing. Unable to submit report.');
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('New Message Report!')
|
||||
.setColor(0xFF0000)
|
||||
.addFields(
|
||||
{
|
||||
name: 'Message',
|
||||
value: reportedMessage.url,
|
||||
inline: false
|
||||
},
|
||||
{
|
||||
name: 'Message Author',
|
||||
value: reportedMessage.author.toString(),
|
||||
inline: false
|
||||
},
|
||||
{
|
||||
name: 'Reporter',
|
||||
value: member.toString(),
|
||||
inline: false
|
||||
});
|
||||
|
||||
if (additionalInfo) {
|
||||
embed.addFields(
|
||||
{
|
||||
name: 'Additional Information',
|
||||
value: additionalInfo,
|
||||
inline: false
|
||||
}
|
||||
{ name: 'Message', value: reportedMessage.url, inline: false },
|
||||
{ name: 'Author', value: reportedMessage.author.toString(), inline: false },
|
||||
{ name: 'Reporter', value: member.toString(), inline: false }
|
||||
);
|
||||
}
|
||||
|
||||
if (additionalInfo) embed.addFields({ name: 'Additional Information', value: additionalInfo, inline: false });
|
||||
|
||||
let replyContent = "Thanks for making a report! I've notified the moderators who can take further action.";
|
||||
|
||||
const wantsTicketButCantOpen = createPrivateHelpTicket && !await canOpenPrivateHelpTicket(member.id);
|
||||
|
||||
if (wantsTicketButCantOpen) {
|
||||
embed.addFields(
|
||||
{
|
||||
embed.addFields({
|
||||
name: 'User Requested Private Ticket',
|
||||
value: 'The user requested a private ticket be opened, but already has an open ticket. If additional information is needed, press the button below to open a ticket with the user.',
|
||||
inline: false
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
replyContent += " Could not open private help ticket since you already have one open. Staff have been notified that you'd like to have a ticket opened, and can make one for you if they deem it necessary.";
|
||||
}
|
||||
@@ -89,12 +66,13 @@ export default {
|
||||
await reportsChannel.send({ files: [new AttachmentBuilder(Buffer.from(reportedMessage.content), { name: 'message-content.txt' })] });
|
||||
|
||||
if (createPrivateHelpTicket && !wantsTicketButCantOpen) {
|
||||
if (!guildSettings.private_help_channel_id) {
|
||||
if (!settings.private_help_channel_id) {
|
||||
replyContent += ' Could not open private help ticket. Private help channel not set. Please report this to a staff member.';
|
||||
} else {
|
||||
const thread = await createPrivateHelpTicketThread(client, guild, member, `Ticket created with message report (${reportMessage.url}). ${member}, use this channel to talk with staff privately about the reported message (${reportedMessage.url}). ${additionalInfo ? `\n\nAdditional information provided in report:\n${additionalInfo.split('\n').map(c => `> ${c}`).join('\n')}` : ''}`);
|
||||
const thread = await createPrivateHelpTicketThread(context, guild, member, `Ticket created with message report (${reportMessage.url}). ${member}, use this channel to talk with staff privately about the reported message (${reportedMessage.url}). ${additionalInfo ? `\n\nAdditional information provided in report:\n${additionalInfo.split('\n').map(c => `> ${c}`).join('\n')}` : ''}`);
|
||||
if (thread) {
|
||||
replyContent += ` Private help ticket created: ${thread}.`;
|
||||
|
||||
embed.addFields({
|
||||
name: 'Private Help Ticket',
|
||||
value: thread.url,
|
||||
@@ -102,9 +80,9 @@ export default {
|
||||
});
|
||||
|
||||
await reportMessage.edit({ embeds: [embed] });
|
||||
|
||||
} else {
|
||||
replyContent += ' There was an issue opening a private help ticket, please report this to a staff member.';
|
||||
|
||||
await reportMessage.edit({
|
||||
embeds: [embed],
|
||||
components: [row]
|
||||
@@ -114,5 +92,8 @@ export default {
|
||||
}
|
||||
|
||||
await interaction.editReply(replyContent);
|
||||
} catch (error: Error | any) {
|
||||
await interaction.editReply({ content: error.message }).catch(() => {});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user