13.2.0 configure work limiter && better default guild settings handler

This commit is contained in:
SowinskiBraeden committed 2022-11-01 10:36:21 -07:00
1 parent c64f1362c4
commit 79f89fe2dd
5 files changed
+49 -27

No files matched your search

+25 -15
View File
@@ -365,6 +365,19 @@ module.exports = {
required: true, 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", name: "reset",
description: "Restore all settings to default configurations", description: "Restore all settings to default configurations",
@@ -847,6 +860,17 @@ module.exports = {
return interaction.send({ embeds: [successEmbed] }); 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') { } else if (args[0].name == 'reset') {
const prompt = new EmbedBuilder() const prompt = new EmbedBuilder()
.setTitle(`Woah!? Hold on.`) .setTitle(`Woah!? Hold on.`)
@@ -1180,21 +1204,7 @@ module.exports = {
let action = ''; let action = '';
if (interaction.customId.split('-')[1]=='yes') { if (interaction.customId.split('-')[1]=='yes') {
action = 'reset'; action = 'reset';
const defaultGuildConfig = { const defaultGuildConfig = client.getDefaultSettings(GuildDB.serverID);
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,
}
client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, function(err, res) { client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$set: {"server": defaultGuildConfig}}, function(err, res) {
if (err) return client.sendInternalError(interaction, err); if (err) return client.sendInternalError(interaction, err);
}); });
+2 -1
View File
@@ -64,7 +64,8 @@ module.exports = {
diff /= (60 * 60); diff /= (60 * 60);
let hoursBetweenDates = Math.abs(Math.round(diff)); 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 workRoles = []
let workPays = [] let workPays = []
for (let i = 0; i < GuildDB.incomeRoles.length; i++) { for (let i = 0; i < GuildDB.incomeRoles.length; i++) {
+1 -1
View File
@@ -2,7 +2,7 @@ require('dotenv').config();
module.exports = { module.exports = {
Dev: "PROD.", 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 Admins: ["362791661274660874", "329371697570381824"], // Admins of the bot
DefaultPrefix: "?", DefaultPrefix: "?",
ServerID: "955668596745461830", ServerID: "955668596745461830",
+6
View File
@@ -124,5 +124,11 @@ module.exports = {
This configurations allows you to customize the multiplier used to determine the winnings from casino games. 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.
`
}
] ]
} }
+15 -10
View File
@@ -191,14 +191,8 @@ class QuarksBot extends Client {
this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id)); this.guilds.cache.forEach((guild) => RegisterGuildCommands(this, guild.id));
} }
async GetGuild(GuildId) { getDefaultSettings(GuildId) {
let guild = undefined; return {
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, serverID: GuildId,
allowedChannels: [], allowedChannels: [],
actionChannel: null, actionChannel: null,
@@ -214,8 +208,18 @@ class QuarksBot extends Client {
onlyOfficersSearch: false, onlyOfficersSearch: false,
casinoMultiplier: 2, casinoMultiplier: 2,
canIgnoreInvoices: true, 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 = {}
guild.server = this.getDefaultSettings(GuildId);
if (this.databaseConnected) { if (this.databaseConnected) {
this.dbo.collection("guilds").insertOne(guild, function(err, res) { this.dbo.collection("guilds").insertOne(guild, function(err, res) {
if (err) throw err; if (err) throw err;
@@ -225,14 +229,14 @@ class QuarksBot extends Client {
let guildData = { let guildData = {
serverID: GuildId, 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, allowedChannels: guild.server.allowedChannels,
actionChannel: guild.server.actionChannel, actionChannel: guild.server.actionChannel,
tweetChannel: guild.server.tweetChannel, tweetChannel: guild.server.tweetChannel,
advertsChannel: guild.server.advertsChannel, advertsChannel: guild.server.advertsChannel,
dispatchChannel: guild.server.dispatchChannel, dispatchChannel: guild.server.dispatchChannel,
startingBalance: guild.server.startingBalance, 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, incomeRoles: guild.server.incomeRoles,
commercialRole: guild.server.commercialRole, commercialRole: guild.server.commercialRole,
officerRole: guild.server.officerRole, officerRole: guild.server.officerRole,
@@ -241,6 +245,7 @@ class QuarksBot extends Client {
botAdmin: guild.server.botAdmin, botAdmin: guild.server.botAdmin,
casinoMultiplier: guild.server.casinoMultiplier, casinoMultiplier: guild.server.casinoMultiplier,
canDismissInvoices: guild.server.canDismissInvoices, canDismissInvoices: guild.server.canDismissInvoices,
workLimiter: guild.server.workLimiter,
} }
return guildData; return guildData;
} }