From a14f087495ed6c1c4472d815521ef44b9e80c659 Mon Sep 17 00:00:00 2001 From: ForGetFulSkyBro <47897305+forgetfulskybro@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:20:44 -0500 Subject: [PATCH 1/4] Update replay.js --- src/commands/replay.js | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/commands/replay.js b/src/commands/replay.js index 185e7205..c7590927 100644 --- a/src/commands/replay.js +++ b/src/commands/replay.js @@ -1,4 +1,4 @@ -const {EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits, ButtonBuilder, ActionRowBuilder} = require('discord.js'); +const { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits, ButtonBuilder, ActionRowBuilder } = require('discord.js'); const guildModel = require('../util/Models/guildModel'); require("dotenv").config(); const Topgg = require(`@top-gg/sdk`) @@ -22,15 +22,6 @@ module.exports = { .setName('enable') .setDescription('Disable or enable the replay button.') .setRequired(true) - )) - .addSubcommand((subcommand) => subcommand - .setName('cooldown') - .setDescription('Change the cooldown for the replay button.') - .addNumberOption((option) => - option - .setName('cooldown') - .setDescription('Change the cooldown for the replay button. Use seconds to determine how long.') - .setRequired(true) )), /** @@ -39,7 +30,7 @@ module.exports = { * @param {guildModel} guildDb */ async execute(interaction, client, guildDb) { - const {REPLAY} = require(`../languages/${guildDb.language}.json`); + const { REPLAY } = require(`../languages/${guildDb.language}.json`); if ( interaction.member.permissions.has(PermissionFlagsBits.ManageGuild) ) { @@ -88,26 +79,6 @@ module.exports = { return; }); break; - case "cooldown": - const cooldown = interaction.options.getNumber('cooldown'); - - await client.database.updateGuild(interaction.guildId, { - replayCooldown: cooldown * 1000, - }, true) - - const nochannelEmbed = new EmbedBuilder() - .setColor("#2f3037") - .setTitle("Error!") - .setDescription(`${REPLAY.embed.cooldownSuccess}\`${cooldown.toLocaleString()}\`${REPLAY.embed.cooldownSuccess2}`); - await interaction - .reply({ - embeds: [nochannelEmbed], - ephemeral: true, - }) - .catch((err) => { - - }); - break; } } else { const errorembed = new EmbedBuilder() From da613886779930cc8256af1ae6b24711fe15849c Mon Sep 17 00:00:00 2001 From: ForGetFulSkyBro <47897305+forgetfulskybro@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:21:06 -0500 Subject: [PATCH 2/4] Create cooldown.js --- src/commands/cooldown.js | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/commands/cooldown.js diff --git a/src/commands/cooldown.js b/src/commands/cooldown.js new file mode 100644 index 00000000..b0a37077 --- /dev/null +++ b/src/commands/cooldown.js @@ -0,0 +1,112 @@ +const { EmbedBuilder, SlashCommandBuilder, PermissionFlagsBits } = require('discord.js'); +const guildModel = require('../util/Models/guildModel'); +function time(str, sec = false) { + const x = sec ? 1 : 1000; + if (typeof str !== 'string') return 0; + const fixed = str.replace(/\s/g, ''); + const tail = +fixed.match(/-?\d+$/g) || 0; + const parts = (fixed.match(/-?\d+[^-0-9]+/g) || []) + .map(v => +v.replace(/[^-0-9]+/g, '') * ({ s: x, m: 60 * x, h: 3600 * x, d: 86400 * x }[v.replace(/[-0-9]+/g, '')] || 0)); + return [tail, ...parts].reduce((a, b) => a + b, 0); +}; +module.exports = { + requireGuild: true, + data: new SlashCommandBuilder() + .setName('cooldown') + .setDescription('Configure cooldown for multiple commands.') + .setDMPermission(false) + .setDescriptionLocalizations({ + de: 'TBA', + "es-ES": 'TBA' + }) + .addSubcommand((subcommand) => subcommand + .setName('replay') + .setDescription('Cooldown for Replay Button') + .addStringOption((option) => + option + .setName('time') + .setDescription('Change the cooldown for the voting timer. Example: 30s, 5m, 2d') + .setRequired(true) + )) + .addSubcommand((subcommand) => subcommand + .setName('voting') + .setDescription('Cooldown for Voting Timer.') + .addStringOption((option) => + option + .setName('time') + .setDescription('Change the cooldown for the voting timer. Example: 30s, 5m, 2d') + .setRequired(true) + )), + + /** + * @param {CommandInteraction} interaction + * @param {Client} client + * @param {guildModel} guildDb + */ + async execute(interaction, client, guildDb) { + const { COOLDOWN } = require(`../languages/${guildDb.language}.json`); + if ( + interaction.member.permissions.has(PermissionFlagsBits.ManageGuild) + ) { + const timeStamp = interaction.options.getString('time') + switch (interaction.options.getSubcommand()) { + case "replay": + const replay = time(timeStamp); + if (replay < 5000) return interaction.reply({ ephemeral: true, content: COOLDOWN.error.notEnough }) + else if (replay > 86400000) return interaction.reply({ ephemeral: true, content: COOLDOWN.error.tooMuchReplay }) + else if (timeStamp.includes("-")) return interaction.reply({ ephemeral: true, content: COOLDOWN.error.syntax }) + + await client.database.updateGuild(interaction.guildId, { + replayCooldown: replay + }, true) + + const replayembed = new EmbedBuilder() + .setColor("#2f3037") + .setDescription(`${COOLDOWN.embed.replaySuccess}\`${timeStamp}\``); + await interaction.reply({ + embeds: [replayembed], + ephemeral: true, + }) + .catch((err) => { + + }); + break; + case "voting": + const voting = time(timeStamp); + if (voting < 5000) return interaction.reply({ ephemeral: true, content: COOLDOWN.error.notEnough }) + else if (voting > 604800000) return interaction.reply({ ephemeral: true, content: COOLDOWN.error.tooMuch }) + else if (timeStamp.includes("-")) return interaction.reply({ ephemeral: true, content: COOLDOWN.error.syntax }) + + await client.database.updateGuild(interaction.guildId, { + votingCooldown: voting + }, true) + + const votingembed = new EmbedBuilder() + .setColor("#2f3037") + .setDescription(`${COOLDOWN.embed.votingSuccess}\`${timeStamp}\``); + await interaction.reply({ + embeds: [votingembed], + ephemeral: true, + }) + .catch((err) => { + + }); + break; + } + } else { + const errorembed = new EmbedBuilder() + .setColor("#F00505") + .setTitle("Error!") + .setDescription(REPLAY.embed.missingPerms); + + return interaction + .reply({ + embeds: [errorembed], + ephemeral: true, + }) + .catch((err) => { + return; + }); + } + }, +}; From 120fe622cd3af4d2b95d89a6621dd6451e6f8e8d Mon Sep 17 00:00:00 2001 From: ForGetFulSkyBro <47897305+forgetfulskybro@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:22:06 -0500 Subject: [PATCH 3/4] Update en_EN.json --- src/languages/en_EN.json | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/languages/en_EN.json b/src/languages/en_EN.json index 1341d550..7c27d803 100644 --- a/src/languages/en_EN.json +++ b/src/languages/en_EN.json @@ -193,6 +193,18 @@ "missingPerms": "You are missing the `Manage Server` permission to use this command." } }, + "COOLDOWN": { + "error": { + "syntax": "Cooldowns can't have negative numbers! Make sure to put only positive numbers.", + "notEnough": "Cooldown can't be below 5 seconds! Make sure to put all cooldowns above 5 seconds.", + "tooMuch": "Voting cooldown can't be above a week! Make sure to put all cooldowns below one week.", + "tooMuchReplay": "Replay cooldown can't be above a day! Make sure to put all cooldowns below one day." + }, + "embed": { + "votingSuccess": "Successfully set voting cooldown to ", + "replaySuccess": "Successfully set replay cooldown to " + } + }, "REPLAY": { "embed": { "title": "Would You Replays", @@ -200,8 +212,6 @@ "errorDesc": "In order to use this command you need to vote for the bot!", "errorAlready": "Replaying is already disabled", "errorAlready2": "Replaying is already enabled", - "cooldownSuccess": "Successfully put cooldown for ", - "cooldownSuccess2": " seconds!", "success": "Replay has been disabled successfully", "missingPerms": "You are missing the `Manage Server` permission to use this command." } From a98e1274be7e2bc61ca4aff26b7b752a870492ce Mon Sep 17 00:00:00 2001 From: ForGetFulSkyBro <47897305+forgetfulskybro@users.noreply.github.com> Date: Thu, 9 Feb 2023 16:24:30 -0500 Subject: [PATCH 4/4] -votingCooldown --- src/util/Models/guildModel.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/Models/guildModel.js b/src/util/Models/guildModel.js index 1d57a365..a4db3259 100644 --- a/src/util/Models/guildModel.js +++ b/src/util/Models/guildModel.js @@ -48,6 +48,10 @@ const guildProfile = new Schema( type: Number, default: 30000, }, + votingCooldown: { + type: Number, + default: 20000, + }, botJoined: { type: Number, },