Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save start-report messages #277

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Tracing = require('@sentry/tracing');
const { LogLevel, SapphireClient } = require('@sapphire/framework');
const Pronouns = require('./commands/a_utility/pronouns');
const RoleSelector = require('./commands/a_utility/role-selector');
const StartReport = require('./commands/hacker_utility/start-report');

/**
* The Main App module houses the bot events, process events, and initializes
Expand Down Expand Up @@ -204,6 +205,15 @@ bot.once('ready', async () => {
} else {
mainLogger.verbose('Restored role selector command message');
}

/** @type {StartReport} */
const startReportCommand = bot.stores.get('commands').get('start-report');
const startReportError = await startReportCommand.tryRestoreReactionListeners(guild);
if (startReportError) {
mainLogger.warning(roleSelectorError);
} else {
mainLogger.verbose('Restored role selector command message');
}
}

guild.commandPrefix = botGuild.prefix;
Expand Down
321 changes: 145 additions & 176 deletions commands/hacker_utility/start-report.js
Original file line number Diff line number Diff line change
@@ -1,177 +1,146 @@
// const { Command } = require('discord.js-commando');
// const { deleteMessage, sendMessageToMember, } = require('../../discord-services');
// const { MessageEmbed, Message } = require('discord.js');
// const BotGuild = require('../../db/mongo/BotGuild');

// /**
// * The report command allows users to report incidents from the server to the admins. Reports are made
// * via the bot's DMs and are 100% anonymous.
// * @category Commands
// * @subcategory Hacker-Utility
// * @extends Command
// */
// class Report extends Command {
// constructor(client) {
// super(client, {
// name: 'report',
// group: 'hacker_utility',
// memberName: 'report to admins',
// description: 'Will send report format to user via DM for user to send back via DM. Admins will get the report!',
// // not guild only!
// args: [],
// });
// }

// /**
// * @param {Message} message
// */
// async run (message) {
// let botGuild = await BotGuild.findById(message.guild.id);

// deleteMessage(message);

// if (!botGuild.report.isEnabled) {
// sendMessageToMember(message.author, 'The report functionality is disabled for this guild.');
// return;
// }

// const embed = new MessageEmbed()
// .setColor(botGuild.colors.embedColor)
// .setTitle('Thank you for taking the time to report users who are not following server or MLH rules. You help makes our community safer!')
// .setDescription('Please use the format below, be as precise and accurate as possible. \n ' +
// 'Everything you say will be 100% anonymous. We have no way of reaching back to you so again, be as detailed as possible!\n' +
// 'Copy paste the format and send it to me in this channel!')
// .addField('Format:', 'User(s) discord username(s) (including discord id number(s)):\n' +
// 'Reason for report (one line):\n' +
// 'Detailed Explanation:\n' +
// 'Name of channel where the incident occurred (if possible):');

// // send message to user with report format
// var msgEmbed = await message.author.send(embed);

// // await response
// msgEmbed.channel.awaitMessages(m => true, {max: 1}).then(async msgs => {
// var msg = msgs.first();

// msgEmbed.delete();
// message.author.send('Thank you for the report! Our admin team will look at it ASAP!');

// // send the report content to the admin report channel!
// var incomingReportChn = await message.guild.channels.resolve(botGuild.report.incomingReportChannelID);

// const adminMsgEmbed = new MessageEmbed()
// .setColor(botGuild.colors.embedColor)
// .setTitle('There is a new report that needs your attention!')
// .setDescription(msg.content);

// // send embed with text message to ping admin
// incomingReportChn.send('<@&' + botGuild.roleIDs.adminRole + '> Incoming Report', {embed: adminMsgEmbed});
// });

// }
// }
// module.exports = Report;

const { Command } = require('@sapphire/framework');
// const { deleteMessage, sendMessageToMember, } = require('../../discord-services');
const { Message, MessageEmbed, Modal, MessageActionRow, MessageButton, TextInputComponent } = require('discord.js');
const { discordLog } = require('../../discord-services');

/**
* The report command allows users to report incidents from the server to the admins. Reports are made
* via the bot's DMs and are 100% anonymous.
* @category Commands
* @subcategory Hacker-Utility
* @extends Command
*/
class StartReport extends Command {
constructor(context, options) {
super(context, {
...options,
description: 'Will send report format to user via DM for user to send back via DM. Admins will get the report!',
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
),
{
idHints: '1214159059880517652'
};
}

/**
*
* @param {Command.ChatInputInteraction} interaction
*/
async chatInputRun(interaction) {
// const userId = interaction.user.id;

// const embed = new MessageEmbed()
// .setTitle(`See an issue you'd like to annoymously report at ${interaction.guild.name}? Let our organizers know!`);

const embed = new MessageEmbed()
.setTitle('Anonymously report users who are not following server or MLH rules. Help makes our community safer!')
.setDescription('Please use the format below, be as precise and accurate as possible. \n ' +
'Everything you say will be 100% anonymous. We have no way of reaching back to you so again, be as detailed as possible!\n' +
'Copy paste the format and send it to me in this channel!')
.addFields({
name: 'Format:',
value: 'User(s) discord username(s) (including discord id number(s)):\n' +
'Reason for report (one line):\n' +
'Detailed Explanation:\n' +
'Name of channel where the incident occurred (if possible):'
});
// modal timeout warning?
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('report')
.setLabel('Report an issue')
.setStyle('PRIMARY'),
);
interaction.reply({ content: 'Report started!', ephemeral: true });
const msg = await interaction.channel.send({ embeds: [embed], components: [row] });

const checkInCollector = msg.createMessageComponentCollector({ filter: i => !i.user.bot});

checkInCollector.on('collect', async i => {
const modal = new Modal()
.setCustomId('reportModal')
.setTitle('Report an issue')
.addComponents([
new MessageActionRow().addComponents(
new TextInputComponent()
.setCustomId('issueMessage')
.setLabel('Reason for report:')
.setMinLength(3)
.setMaxLength(1000)
.setStyle(2)
.setPlaceholder('Type your issue here...')
.setRequired(true),
),
]);
await i.showModal(modal);

const submitted = await i.awaitModalSubmit({ time: 300000, filter: j => j.user.id === i.user.id })
.catch(error => {
});

if (submitted) {
const issueMessage = submitted.fields.getTextInputValue('issueMessage');

try {
discordLog(interaction.guild, `<@&${interaction.guild.roleIDs.staffRole}> New anonymous report:\n\n ${issueMessage}`);
} catch {
discordLog(interaction.guild, `New anonymous report:\n\n ${issueMessage}`);
}
submitted.reply({ content: 'Thank you for taking the time to report users who are not following server or MLH rules. You help makes our community safer!', ephemeral: true });
return;
}
});
}
}
const { Command } = require('@sapphire/framework');
// const { deleteMessage, sendMessageToMember, } = require('../../discord-services');
const { Guild, Message, MessageEmbed, Modal, MessageActionRow, MessageButton, TextInputComponent } = require('discord.js');
const { discordLog } = require('../../discord-services');
const firebaseUtil = require('../../db/firebase/firebaseUtil');

/**
* The report command allows users to report incidents from the server to the admins. Reports are made
* via the bot's DMs and are 100% anonymous.
* @category Commands
* @subcategory Hacker-Utility
* @extends Command
*/
class StartReport extends Command {
constructor(context, options) {
super(context, {
...options,
description: 'Will send report format to user via DM for user to send back via DM. Admins will get the report!',
});
}

registerApplicationCommands(registry) {
registry.registerChatInputCommand((builder) =>
builder
.setName(this.name)
.setDescription(this.description)
),
{
idHints: '1214159059880517652'
};
}

/**
*
* @param {Command.ChatInputInteraction} interaction
*/
async chatInputRun(interaction) {
// const userId = interaction.user.id;

// const embed = new MessageEmbed()
// .setTitle(`See an issue you'd like to annoymously report at ${interaction.guild.name}? Let our organizers know!`);

const embed = new MessageEmbed()
.setTitle('Anonymously report users who are not following server or MLH rules. Help makes our community safer!')
.setDescription('Please use the format below, be as precise and accurate as possible. \n ' +
'Everything you say will be 100% anonymous. We have no way of reaching back to you so again, be as detailed as possible!\n' +
'Copy paste the format and send it to me in this channel!')
.addFields({
name: 'Format:',
value: 'User(s) discord username(s) (including discord id number(s)):\n' +
'Reason for report (one line):\n' +
'Detailed Explanation:\n' +
'Name of channel where the incident occurred (if possible):'
});
// modal timeout warning?
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('report')
.setLabel('Report an issue')
.setStyle('PRIMARY'),
);
interaction.reply({ content: 'Report started!', ephemeral: true });
const msg = await interaction.channel.send({ embeds: [embed], components: [row] });

await this.listenToReports(interaction, msg);

const savedMessagesCol = firebaseUtil.getSavedMessagesSubCol(interaction.guild.id);
await savedMessagesCol.doc('report').set({
messageId: msg.id,
channelId: msg.channel.id,
});
}

/**
*
* @param {Command.ChatInputInteraction} interaction
* @param {Message<boolean>} msg
*/
async listenToReports(interaction, msg) {
const checkInCollector = msg.createMessageComponentCollector({ filter: i => !i.user.bot});

checkInCollector.on('collect', async i => {
const modal = new Modal()
.setCustomId('reportModal')
.setTitle('Report an issue')
.addComponents([
new MessageActionRow().addComponents(
new TextInputComponent()
.setCustomId('issueMessage')
.setLabel('Reason for report:')
.setMinLength(3)
.setMaxLength(1000)
.setStyle(2)
.setPlaceholder('Type your issue here...')
.setRequired(true),
),
]);
await i.showModal(modal);

const submitted = await i.awaitModalSubmit({ time: 300000, filter: j => j.user.id === i.user.id })
.catch(error => {
});

if (submitted) {
const issueMessage = submitted.fields.getTextInputValue('issueMessage');

try {
discordLog(interaction.guild, `<@&${interaction.guild.roleIDs.staffRole}> New anonymous report:\n\n ${issueMessage}`);
} catch {
discordLog(interaction.guild, `New anonymous report:\n\n ${issueMessage}`);
}
submitted.reply({ content: 'Thank you for taking the time to report users who are not following server or MLH rules. You help makes our community safer!', ephemeral: true });
return;
}
});
}

/**
*
* @param {Guild} guild
*/
async tryRestoreReactionListeners(guild) {
const savedMessagesCol = firebaseUtil.getSavedMessagesSubCol(guild.id);
const reportDoc = await savedMessagesCol.doc('report').get();
if (reportDoc.exists) {
const { messageId, channelId } = reportDoc.data();
const channel = await this.container.client.channels.fetch(channelId);
if (channel) {
try {
/** @type {Message} */
const message = await channel.messages.fetch(messageId);
this.listenToReports(guild, message);
} catch (e) {
// message doesn't exist anymore
return e;
}
} else {
return 'Saved message channel does not exist';
}
} else {
return 'No existing saved message for pronouns command';
}
}
}
module.exports = StartReport;