From 79f89fe2dd58b8d8ad3121b79c085c6c0554d754 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Tue, 1 Nov 2022 10:36:21 -0700 Subject: [PATCH] 13.2.0 configure work limiter && better default guild settings handler --- commands/config.js | 40 ++++++++++++++++++++++------------- commands/work.js | 3 ++- config/config.js | 2 +- config/settingsHelp.js | 6 ++++++ structures/QuarksBot.js | 47 +++++++++++++++++++++++------------------ 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/commands/config.js b/commands/config.js index b69d9af..11e6f91 100644 --- a/commands/config.js +++ b/commands/config.js @@ -365,6 +365,19 @@ module.exports = { required: true, }] }, + { + name: "work_limiter", + description: "Configure the number of hours users have to wait to work again", + value: "work_limiter", + type: 1, + options: [{ + name: "hours", + description: "Set the hours to wait till a user can work again", + value: 24, + type: 4, + min_value: 1, + }] + }, { name: "reset", description: "Restore all settings to default configurations", @@ -847,6 +860,17 @@ module.exports = { return interaction.send({ embeds: [successEmbed] }); + } else if (arg[0].name == 'work_limiter') { + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server.workLimiter": args[0].options[0].value}}, function(err, res) { + if (err) return client.sendInternalError(interaction, err); + }); + + const successEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Green) + .setDescription(`**Success:** Set work limiter to **${args[0].options[0].value}** hours. Users need to wait this set amount of time to use the \`/work\` command again.`); + + return interaction.send({ embeds: [successEmbed] }); + } else if (args[0].name == 'reset') { const prompt = new EmbedBuilder() .setTitle(`Woah!? Hold on.`) @@ -1180,21 +1204,7 @@ module.exports = { let action = ''; if (interaction.customId.split('-')[1]=='yes') { action = 'reset'; - const defaultGuildConfig = { - serverID: GuildDB.serverID, - allowedChannels: [], - actionChannel: null, - tweetChannel: null, - advertsChannel: null, - dispatchChannel: null, - startingBalance: 1000.00, - incomeRoles: [], - botAdmin: null, - commercialRole: null, - officerRole: null, - dispatcherRole: null, - onlyOfficersSearch: false, - } + const defaultGuildConfig = client.getDefaultSettings(GuildDB.serverID); client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, function(err, res) { if (err) return client.sendInternalError(interaction, err); }); diff --git a/commands/work.js b/commands/work.js index 12e370b..dedcbad 100644 --- a/commands/work.js +++ b/commands/work.js @@ -64,7 +64,8 @@ module.exports = { diff /= (60 * 60); let hoursBetweenDates = Math.abs(Math.round(diff)); - if (hoursBetweenDates >= 24) { + // work limiter is # of hours to wait before next time a user can use /work + if (hoursBetweenDates >= GuildDB.workLimiter) { let workRoles = [] let workPays = [] for (let i = 0; i < GuildDB.incomeRoles.length; i++) { diff --git a/config/config.js b/config/config.js index 7f3a9f1..d72daba 100644 --- a/config/config.js +++ b/config/config.js @@ -2,7 +2,7 @@ require('dotenv').config(); module.exports = { Dev: "PROD.", - Version: "13.1.9", // (major).(feature).(revision/bug/refactoring) + Version: "13.2.0", // (major).(feature).(revision/bug/refactoring) Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot DefaultPrefix: "?", ServerID: "955668596745461830", diff --git a/config/settingsHelp.js b/config/settingsHelp.js index 8ea50b3..4e2f9a2 100644 --- a/config/settingsHelp.js +++ b/config/settingsHelp.js @@ -124,5 +124,11 @@ module.exports = { This configurations allows you to customize the multiplier used to determine the winnings from casino games. ` }, + { + name: "work_limiter", + description: ` + This configuration allows you to alter the number of hours a user has to wait between the use of the \`/work\` command. By default, users need to wait **24** hours before the can use the \`/work\` command again. + ` + } ] } \ No newline at end of file diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index a915c67..a84b06e 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -191,31 +191,35 @@ class QuarksBot extends Client { this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id)); } + getDefaultSettings(GuildId) { + return { + serverID: GuildId, + allowedChannels: [], + actionChannel: null, + tweetChannel: null, + advertsChannel: null, + dispatchChannel: null, + startingBalance: 1000.00, + incomeRoles: [], + botAdmin: null, + commercialRole: null, + officerRole: null, + dispatcherRole: null, + onlyOfficersSearch: false, + casinoMultiplier: 2, + canIgnoreInvoices: true, + workLimiter: 24, + } + } + async GetGuild(GuildId) { let guild = undefined; if (this.databaseConnected) guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild); // If guild not found, generate guild default if (!guild) { - guild = { - server: { - serverID: GuildId, - allowedChannels: [], - actionChannel: null, - tweetChannel: null, - advertsChannel: null, - dispatchChannel: null, - startingBalance: 1000.00, - incomeRoles: [], - botAdmin: null, - commercialRole: null, - officerRole: null, - dispatcherRole: null, - onlyOfficersSearch: false, - casinoMultiplier: 2, - canIgnoreInvoices: true, - } - } + guild = {} + guild.server = this.getDefaultSettings(GuildId); if (this.databaseConnected) { this.dbo.collection("guilds").insertOne(guild, function(err, res) { if (err) throw err; @@ -225,14 +229,14 @@ class QuarksBot extends Client { let guildData = { serverID: GuildId, - customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false, + customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false, // not stored but calculated after allowedChannels: guild.server.allowedChannels, actionChannel: guild.server.actionChannel, tweetChannel: guild.server.tweetChannel, advertsChannel: guild.server.advertsChannel, dispatchChannel: guild.server.dispatchChannel, startingBalance: guild.server.startingBalance, - incomeRoleStatus: guild.server.incomeRoles.length > 0 ? true : false, + incomeRoleStatus: guild.server.incomeRoles.length > 0 ? true : false, // not stored but calculated after incomeRoles: guild.server.incomeRoles, commercialRole: guild.server.commercialRole, officerRole: guild.server.officerRole, @@ -241,6 +245,7 @@ class QuarksBot extends Client { botAdmin: guild.server.botAdmin, casinoMultiplier: guild.server.casinoMultiplier, canDismissInvoices: guild.server.canDismissInvoices, + workLimiter: guild.server.workLimiter, } return guildData; }