Skip to content

Commit

Permalink
fix(report): fix bug that created double report posts
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-737 committed Apr 30, 2023
1 parent 1a36c45 commit f4eb357
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 71 deletions.
8 changes: 7 additions & 1 deletion src/Commands/Support/report-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export default {
const target = interaction.targetMessage;

const messageData = getDb().messageData;
const messageInDb = await messageData?.findFirst({ where: { channelAndMessageIds: { some: { messageId: { equals: target.id } } } } });
const messageInDb = await messageData?.findFirst({
where: {
channelAndMessageIds: {
some: { messageId: { equals: target.id } },
},
},
});

// check if args.channel is in connectedList DB
if (!messageInDb) {
Expand Down
2 changes: 1 addition & 1 deletion src/Scripts/blacklist/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export = {
inline: true,
},
{
name: 'Duration',
name: 'Expires',
value: expires ? `<t:${Math.round(expires.getTime() / 1000)}:R>` : 'Never.',
inline: true,
},
Expand Down
164 changes: 95 additions & 69 deletions src/Scripts/support/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import logger from '../../Utils/logger';
export = {
async execute(interaction: ChatInputCommandInteraction) {
const reportType = interaction.options.getString('type', true) as 'user' | 'server' | 'bug' | 'other';
const emojis = interaction.client.emotes.normal;

const reportSubmit = new ModalBuilder()
const reportModal = new ModalBuilder()
.setTitle('New Report')
.setCustomId(interaction.id)
.addComponents(
Expand All @@ -24,89 +22,119 @@ export = {
),
);

if (reportType === 'bug') {
const bugEmbed = new EmbedBuilder()
.setTitle('Affected Components')
.setDescription('Please choose what component of the bot you are facing issues with.')
.setColor('Random');
const emojis = interaction.client.emotes.normal;

const bugComponent = new ActionRowBuilder<StringSelectMenuBuilder>()
if (reportType === 'bug') {
const bugSelect = new ActionRowBuilder<StringSelectMenuBuilder>()
.addComponents(
new StringSelectMenuBuilder()
.setMaxValues(2)
.setCustomId('component')
.setOptions(
new StringSelectMenuOptionBuilder()
.setLabel('Commands')
.setEmoji(emojis.slash as any)
.setEmoji(emojis.slash)
.setValue('Commands'),
new StringSelectMenuOptionBuilder()
.setLabel('Network')
.setEmoji(emojis.clipart as any)
.setEmoji(emojis.clipart)
.setValue('Network'),
new StringSelectMenuOptionBuilder()
.setLabel('Other (Specify)')
.setEmoji('❓' as any)
.setEmoji('❓')
.setValue('Other'),
),
);

const bugReportChannel = await interaction.client.channels.fetch(constants.channel.bugs).catch(() => null) as ForumChannel | null;
const message = await interaction.reply({ embeds: [bugEmbed], components: [bugComponent] });
const collector = message.createMessageComponentCollector({ componentType: ComponentType.StringSelect, idle: 30_000 });

collector.on('collect', async (i) => {
reportSubmit.setComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('summary')
.setLabel('Whats the bug about?')
.setPlaceholder('Frequent interaction failures...')
.setStyle(TextInputStyle.Short)),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('description')
.setLabel('Detailed Description (OPTIONAL)')
.setPlaceholder('Please describe the steps to reproduce the issue, include any unexpected behavior.')
.setStyle(TextInputStyle.Paragraph)
.setRequired(false)
.setMinLength(17),
));
await i.showModal(reportSubmit);

i.awaitModalSubmit({ time: 60_000 * 5 })
.then(async (bugModal) => {
if (!bugReportChannel) {
logger.error('Bug report channel not found.');
captureMessage('Bug report channel not found.', { user: { id: interaction.user.id, username: interaction.user.tag }, extra: { command: 'Bug Report' } });
return bugModal.reply({ content: 'An error occured while sending your report.', ephemeral: true });
}
const bugEmbed = new EmbedBuilder()
.setTitle('Affected Components')
.setDescription('Please choose what component of the bot you are facing issues with.')
.setColor('Random');

const summary = bugModal.fields.getTextInputValue('summary');
const description = bugModal.fields.getTextInputValue('description');
const appliedTags = i.values.map((value) => bugReportChannel.availableTags.find((tag) => tag.name.includes(value))?.id || 'error lmao');
const message = await interaction.reply({
embeds: [bugEmbed],
components: [bugSelect],
ephemeral: true,
});

const bugReportEmbed = new EmbedBuilder()
.setColor(colors('invisible'))
.setTitle(summary)
.setDescription(`**Affects:** ${i.values.join(', ')}`)
.setThumbnail(interaction.user.avatarURL({ size: 2048 }) ?? interaction.user.defaultAvatarURL)
.setFooter({ text: `Reported by ${interaction.user.tag} (${interaction.user.id})`, iconURL: interaction.user.avatarURL() || interaction.user.defaultAvatarURL });
// get selected bug type
const typeSelection = await message.awaitMessageComponent({
componentType: ComponentType.StringSelect,
time: 30_000,
}).catch(() => null);

reportModal.setComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('summary')
.setLabel('Whats the bug about?')
.setPlaceholder('Frequent interaction failures...')
.setStyle(TextInputStyle.Short)),
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('description')
.setLabel('Detailed Description (OPTIONAL)')
.setPlaceholder('Please describe the steps to reproduce the issue, include any unexpected behavior.')
.setStyle(TextInputStyle.Paragraph)
.setRequired(false)
.setMinLength(17),
));

if (description) bugReportEmbed.addFields({ name: 'Details', value: description });
// show modal to collect extra information
await typeSelection?.showModal(reportModal);

// get modal input and post it to support server forum
typeSelection?.awaitModalSubmit({
time: 60_000 * 5,
filter: (i) => i.customId === reportModal.data.custom_id,
}).then(async (bugModal) => {
const bugReportChannel = await bugModal.client.channels.fetch(constants.channel.bugs).catch(() => null) as ForumChannel | null;
if (!bugReportChannel) {
logger.error('Bug report channel not found.');
captureMessage('Bug report channel not found.', { user: { id: bugModal.user.id, username: bugModal.user.tag }, extra: { command: 'Bug Report' } });
return bugModal.reply({
content: 'An error occured while sending your report. The developers have been notified!',
ephemeral: true,
});
}

await bugReportChannel.threads.create({ name: summary, message: { embeds: [bugReportEmbed] }, appliedTags });
bugModal.reply({
content: `${emojis.yes} Successfully submitted report. Join the support server to view and/or attach screenshots to it.`,
ephemeral: true,
});
const summary = bugModal.fields.getTextInputValue('summary');
const description = bugModal.fields.getTextInputValue('description');

const bugReportEmbed = new EmbedBuilder()
.setColor(colors('invisible'))
.setTitle(summary)
.setDescription(`**Affects:** ${typeSelection.values.join(', ')}`)
.setThumbnail(interaction.user.avatarURL({ size: 2048 }) ?? interaction.user.defaultAvatarURL)
.setFooter({
text: `Reported by ${interaction.user.tag} (${interaction.user.id})`,
iconURL: interaction.user.avatarURL() || interaction.user.defaultAvatarURL,
});

if (description) bugReportEmbed.addFields({ name: 'Details', value: description });

const appliedTags = typeSelection.values
.map((value) => bugReportChannel.availableTags.find((tag) => tag.name.includes(value))?.id || 'error lmao');

// finally make the post in ic central
await bugReportChannel.threads.create({
name: summary,
message: { embeds: [bugReportEmbed] },
appliedTags,
});

bugModal.reply({
content: `${emojis.yes} Successfully submitted report. Join the </support server:924659341049626636> to view and/or attach screenshots to it.`,
ephemeral: true,
});
}).catch((error) => {
if (!error.message.includes('ending with reason: time')) logger.error(error);
});
return;
}

else if (reportType === 'server' || reportType === 'user') {
reportSubmit.addComponents(
reportModal.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('id')
Expand All @@ -118,12 +146,10 @@ export = {
));
}

await interaction.showModal(reportSubmit);

const reportChannel = await interaction.client.channels.fetch(constants.channel.reports).catch(() => null) as TextChannel | null;

interaction.awaitModalSubmit({ time: 60000 * 5, filter: (i) => i.user.id === interaction.user.id && i.customId === reportSubmit.data.custom_id })
await interaction.showModal(reportModal);
interaction.awaitModalSubmit({ time: 60000 * 5, filter: (i) => i.user.id === interaction.user.id && i.customId === reportModal.data.custom_id })
.then(async modalInteraction => {
const reportChannel = await modalInteraction.client.channels.fetch(constants.channel.reports).catch(() => null) as TextChannel | null;
const reportDescription = modalInteraction.fields.getTextInputValue('description');

switch (reportType) {
Expand All @@ -135,8 +161,8 @@ export = {
content: stripIndents`
${emojis.no} I couldn't find a user with that ID.\n\n
**To find a user's ID within the network, please follow these instructions:**
${emojis.dotYellow} Right click on a message sent from the user in question select \`Apps > User Info\` or you can get it from the [embed author](https://i.imgur.com/AbTTlry.gif). Please double-check the ID and try again.
`,
${emojis.dotYellow} Right click on a message sent from the user in question select \`Apps > User Info\`. Please double-check the ID and try again.
`,
ephemeral: true,
});
}
Expand All @@ -153,8 +179,8 @@ export = {
}

case 'server': {
const Ids = modalInteraction.fields.getTextInputValue('id');
const reportedServer = await interaction.client.guilds.fetch(Ids).catch(() => null);
const ids = modalInteraction.fields.getTextInputValue('id');
const reportedServer = await interaction.client.guilds.fetch(ids).catch(() => null);
if (!reportedServer) {
return modalInteraction.reply({
content: stripIndents`
Expand All @@ -174,8 +200,8 @@ export = {
.setThumbnail(reportedServer.iconURL({ size: 2048 }))
.setFooter({ text: `Reported by ${interaction.user.tag} (${interaction.user.id})`, iconURL: interaction.user.avatarURL() || interaction.user.defaultAvatarURL });
await reportChannel?.send({ embeds: [serverReport] });
}
break;
}
default: {
const otherReport = new EmbedBuilder()
.setColor('Random')
Expand All @@ -191,4 +217,4 @@ export = {
}).catch((error) => {if (!error.message.includes('ending with reason: time')) logger.error(error);});

},
};
};

0 comments on commit f4eb357

Please sign in to comment.