diff --git a/src/index.js b/src/index.js index c8cbe9e..1db7620 100644 --- a/src/index.js +++ b/src/index.js @@ -92,6 +92,9 @@ client.on(Events.InteractionCreate, async (interaction) => { case 'contactmods': await contactMods.contactMods(interaction); break; + case 'pingmods': + await contactMods.pingMods(interaction); + break; case 'purge': await purgeMessages.purgeMessages(interaction); break; diff --git a/src/modules/contact-mods.js b/src/modules/contact-mods.js index abcd8cf..d2cc0dd 100644 --- a/src/modules/contact-mods.js +++ b/src/modules/contact-mods.js @@ -229,9 +229,36 @@ const reportUser = async (interaction) => { } }; +const pingMods = async (interaction) => { + const reason = interaction.options.getString('reason'); + const recentMessages = await interaction.channel.messages.fetch({ + limit: 1 + }); + const mostRecentMessage = recentMessages.first(); + const modRole = await interaction.guild.roles.fetch(config.modRoleId); + const modChannel = await client.channels.fetch(config.modChannelId); + + let pingMessage = `${modRole}: ${interaction.user} pinged mods in ${interaction.channel}`; + if (mostRecentMessage) { + pingMessage += ` at ${mostRecentMessage.url}`; + } + if (reason) { + pingMessage += ' because:\n\`\`\`'; + pingMessage += reason.replace(/```/g, '[escaped code block]'); + pingMessage += '\n\`\`\`'; + } + await modChannel.send(pingMessage); + + await interaction.reply({ + content: 'Mods have been pinged. Be patient. Pinging again does not help.', + ephemeral: true + }); +}; + module.exports = { ticketActivity, contactMods, reportMessage, - reportUser + reportUser, + pingMods }; diff --git a/src/register-commands.js b/src/register-commands.js index cd6fde3..5835afb 100644 --- a/src/register-commands.js +++ b/src/register-commands.js @@ -14,7 +14,7 @@ const { const commands = [ new SlashCommandBuilder() .setName('contactmods') - .setDescription('Contact moderators without posting a public message (previously /pingmods)') + .setDescription('Contact moderators without posting a public message') .addStringOption(option => option .setName('topic') .setDescription('What are you contacting us about?') @@ -27,6 +27,14 @@ const commands = [ .setMaxLength(1000) .setRequired(true) ), + new SlashCommandBuilder() + .setName('pingmods') + .setDescription('Ping moderators without posting a public message') + .addStringOption(option => option + .setName('reason') + .setDescription('Message will be provided to moderators.') + .setMaxLength(1000) + ), new SlashCommandBuilder() .setName('purge') .setDescription('Purge messages in the current channel')