Added a cooldown with a default of 5 minutes. This can be adjusted to meet desired timing.
This commit is contained in:
+80
-18
@@ -1,45 +1,107 @@
|
|||||||
import { ApplicationCommandType, ApplicationIntegrationType, Client, ContextMenuCommandBuilder, GuildTextBasedChannel, InteractionContextType, MessageContextMenuCommandInteraction, MessageFlags } from "discord.js";
|
import {
|
||||||
|
ApplicationCommandType,
|
||||||
|
ApplicationIntegrationType,
|
||||||
|
Client,
|
||||||
|
ContextMenuCommandBuilder,
|
||||||
|
GuildTextBasedChannel,
|
||||||
|
InteractionContextType,
|
||||||
|
MessageContextMenuCommandInteraction,
|
||||||
|
MessageFlags
|
||||||
|
} from "discord.js";
|
||||||
|
|
||||||
// TODO: Later Nix's problem: Command Cooldown.
|
import { Database } from "../shared/Database";
|
||||||
|
|
||||||
|
const cooldowns = new Map<string, number>();
|
||||||
|
const COOLDOWN_TIME = 300000; // 5 minutes
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Report Message',
|
name: 'Report Message',
|
||||||
|
|
||||||
data: new ContextMenuCommandBuilder()
|
data: new ContextMenuCommandBuilder()
|
||||||
.setName('Report Message')
|
.setName('Report Message')
|
||||||
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
.setIntegrationTypes(ApplicationIntegrationType.GuildInstall)
|
||||||
.setContexts(InteractionContextType.Guild)
|
.setContexts(InteractionContextType.Guild)
|
||||||
.setType(ApplicationCommandType.Message),
|
.setType(ApplicationCommandType.Message),
|
||||||
|
|
||||||
handler: async function (client: Client, interaction: MessageContextMenuCommandInteraction) {
|
handler: async function (
|
||||||
|
client: Client,
|
||||||
|
interaction: MessageContextMenuCommandInteraction
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
const reportsChannel = await client.channels.fetch("1504936076081369150") as GuildTextBasedChannel;
|
const userId = interaction.user.id;
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
reportsChannel.send({
|
const cooldownExpiration = cooldowns.get(userId);
|
||||||
|
if (cooldownExpiration && now < cooldownExpiration) {
|
||||||
|
const expiresAt = Math.floor(cooldownExpiration / 1000);
|
||||||
|
return interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
color: 0xffaa00,
|
||||||
|
description: `Slow down there, you can report another message <t:${expiresAt}:R>.`
|
||||||
|
}],
|
||||||
|
flags: [MessageFlags.Ephemeral]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set cooldown
|
||||||
|
cooldowns.set(userId, now + COOLDOWN_TIME);
|
||||||
|
|
||||||
|
// Optional cleanup
|
||||||
|
setTimeout(() => {
|
||||||
|
cooldowns.delete(userId);
|
||||||
|
}, COOLDOWN_TIME);
|
||||||
|
|
||||||
|
const guildSettings = await Database.getGuildSettings(interaction.guildId!);
|
||||||
|
|
||||||
|
const reportsChannel =
|
||||||
|
await client.channels.fetch(
|
||||||
|
guildSettings?.moderator_channel_id!
|
||||||
|
) as GuildTextBasedChannel;
|
||||||
|
|
||||||
|
await reportsChannel.send({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
title: 'New Message Report!',
|
title: 'New Message Report!',
|
||||||
fields: [
|
fields: [
|
||||||
{ name: 'Message', value: interaction.targetMessage.url, inline: false },
|
{
|
||||||
{ name: 'Author', value: interaction.targetMessage.author.toString(), inline: false },
|
name: 'Message',
|
||||||
{ name: 'Reporter', value: interaction.user.toString(), inline: false }
|
value: interaction.targetMessage.url,
|
||||||
|
inline: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Author',
|
||||||
|
value: interaction.targetMessage.author.toString(),
|
||||||
|
inline: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Reporter',
|
||||||
|
value: interaction.user.toString(),
|
||||||
|
inline: false
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [{
|
embeds: [{
|
||||||
color: 0x014995,
|
color: 0x014995,
|
||||||
description: "Thanks for making a report! Moderators have been notified and will investigate when they can next!"
|
description:
|
||||||
|
"Thanks for making a report! I've notified the moderators who can take further action."
|
||||||
}],
|
}],
|
||||||
|
|
||||||
flags: [MessageFlags.Ephemeral]
|
flags: [MessageFlags.Ephemeral]
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
interaction.reply({
|
console.error(error);
|
||||||
embeds: [{
|
if (!interaction.replied) {
|
||||||
color: 0xff5555,
|
await interaction.reply({
|
||||||
description: "Hmm, an error occured while processing your request. If you receive this error more than once, DM a moderator for assistance."
|
embeds: [{
|
||||||
}]
|
color: 0xff5555,
|
||||||
})
|
description:
|
||||||
|
"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]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Reference in New Issue
Block a user