From 9d8350f5692eb3646386762590fc790c4cc79b62 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 2 Aug 2022 22:41:18 -0700 Subject: [PATCH] add more settings/revamp some settings --- commands/settings.js | 482 ++++++++++++++++++++++++++++++++++------ structures/QuarksBot.js | 88 +++----- 2 files changed, 443 insertions(+), 127 deletions(-) diff --git a/commands/settings.js b/commands/settings.js index ac7f624..78baf33 100644 --- a/commands/settings.js +++ b/commands/settings.js @@ -86,6 +86,31 @@ module.exports = { } ] }, + { + name: "adverts_channel", + description: "Set the channel for users to send commercial adverts", + value: "adverts_channel", + type: 1, + options: [ + { + name: "set_or_remove", + description: "Set/remove channel", + value: "set_or_remove", + type: 3, + required: true, + choices: [ + { name: "set", value: "set" }, { name: "remove", value: "remove" }, + ] + }, + { + name: "channel", + description: "The channel to configure", + value: "channel", + type: 7, + required: true, + } + ] + }, { name: "starting_balance", description: "Set the starting balance", @@ -105,6 +130,16 @@ module.exports = { value: "set_income_role", type: 1, options: [ + { + name: "set_or_remove", + description: "Set/remove role", + value: "set_or_remove", + type: 3, + required: true, + choices: [ + { name: "set", value: "set" }, { name: "remove", value: "remove" }, + ] + }, { name: "role", description: "Role for this income", @@ -117,24 +152,59 @@ module.exports = { description: "The amount to earn in 1 day of work", value: 120.00, type: 10, - required: true, + required: false, } ], }, { - name: "remove_income_role", - description: "Remove a role from earning income", - value: "remove_income_role", + name: "commercial_role", + description: "Set/remove commercial role", + value: "commercial_role", type: 1, options: [ + { + name: "set_or_remove", + description: "Set/remove role", + value: "set_or_remove", + type: 3, + required: true, + choices: [ + { name: "set", value: "set" }, { name: "remove", value: "remove" }, + ] + }, { name: "role", - description: "Role to remove", + description: "Role to set or remove", value: "role", type: 8, required: true, }, - ], + ] + }, + { + name: "officer_role", + description: "Set/remove officer role", + value: "officer_role", + type: 1, + options: [ + { + name: "set_or_remove", + description: "Set/remove role", + value: "set_or_remove", + type: 3, + required: true, + choices: [ + { name: "set", value: "set" }, { name: "remove", value: "remove" }, + ] + }, + { + name: "role", + description: "Role to set or remove", + value: "role", + type: 8, + required: true, + }, + ] }, { name: "view", @@ -360,7 +430,7 @@ module.exports = { const successEmbed = new MessageEmbed() .setColor("GREEN") - .setTitle(`Successfully set <#${channelid}> for actions.`) + .setTitle(`Successfully set <#${channelid}> for tweets.`) return interaction.send({ embeds: [successEmbed] }); } else if (args[0].options[0].value == 'remove') { @@ -415,6 +485,86 @@ module.exports = { return; } + } else if (args[0].name == 'adverts_channel') { + const channelid = args[0].options[1].value; + + if (args[0].options[0].value == 'set') { + const guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + const channelSetting = guild.server.tweetChannel; + + const presetEmbed = new MessageEmbed() + .setColor(client.config.EmbedColor) + .setDescription(`The channel <#${channelid}> has already been set for advertisements.`) + + if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); + client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.advertsChannel":channelid}},function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully set <#${channelid}> for advertisements.`) + + return interaction.send({ embeds: [successEmbed] }); + } else if (args[0].options[0].value == 'remove') { + const prompt = new MessageEmbed() + .setTitle(`Are you sure you want to stop using this channel for advertisements?`) + .setColor(client.config.EmbedColor) + + const opt = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [prompt], components: [opt] }); + + client.on("interactionCreate", ButtonInteraction => { + if(!ButtonInteraction.isButton()) return; + const queryString = ButtonInteraction.customId; + if (!queryString.endsWith(ButtonInteraction.member.user.id)) { + return ButtonInteraction.reply({ + content: "This button is not for you", + ephemeral: true + }) + } + let action = ''; + if (queryString==`yes-${interaction.member.user.id}`) { + action = 'removed'; + client.dbo.collection("guilds").updateOne({"server.serverID":ButtonInteraction.guild.id},{$set:{"server.advertsChannel": null}},function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} channel.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); + }); + return; + } + } else if (args[0].name == 'starting_balance') { client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {"server.startingBalance":args[0].options[0].value}, function(err, res) { if (err) { @@ -434,88 +584,281 @@ module.exports = { return interaction.send({ embeds: [successEmbed] }); } else if (args[0].name == 'set_income_role') { - if (args[0].options[1].value <= 0) { - let embed = new MessageEmbed() - .setDescriptions('**Error Notice:** Amount cannot be $0 or less than $0.') - .setColor("RED"); - - return interaction.send({ embeds: [embed] }); - } - - const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[0].value); - if (searchIndex == -1) { - const newIncome = { - role: args[0].options[0].value, - income: args[0].options[1].value, + if (args[0].options[0].value == 'set') { + if (!args[0].options[2]) { + let embed = new MessageEmbed() + .setDescriptions('**Error Notice:** Please provide an income amount.') + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); } - - client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push: {"server.incomeRoles":newIncome}}, function(err, res) { - if (err) { - client.log(err); - const embed = new MessageEmbed() - .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) - .setColor("RED") + + if (args[0].options[2].value <= 0) { + let embed = new MessageEmbed() + .setDescriptions('**Error Notice:** Amount cannot be $0 or less than $0.') + .setColor("RED"); - return interaction.send({ embeds: [embed] }); - } - }); - } else { - client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID, "server.incomeRoles.role": args[0].options[0].value}, - {$set: {"server.incomeRoles.$.income": args[0].options[1].value}}, function(err, res) { - if (err) { - client.log(err); - const embed = new MessageEmbed() - .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) - .setColor("RED") + return interaction.send({ embeds: [embed] }); + } - return interaction.send({ embeds: [embed] }); + const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[1].value); + if (searchIndex == -1) { + const newIncome = { + role: args[0].options[1].value, + income: args[0].options[2].value, } - }); - } - - const successEmbed = new MessageEmbed() - .setDescription(`Successfully updated <@&${args[0].options[0].value}>'s income to $${args[0].options[1].value}`) - .setColor('GREEN'); - - return interaction.send({ embeds: [successEmbed] }); + + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push: {"server.incomeRoles":newIncome}}, function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") - } else if (args[0].name == 'remove_income_role') { - const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[0].value); - if (searchIndex == -1) { - const errorEmbed = new MessageEmbed() - .setDescription('**Error Notice:** Role not found') - .setColor("RED"); + return interaction.send({ embeds: [embed] }); + } + }); + } else { + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID, "server.incomeRoles.role": args[0].options[1].value}, + {$set: {"server.incomeRoles.$.income": args[0].options[2].value}}, function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + } + const perform = searchIndex = -1 ? 'set' : 'updated'; + + const successEmbed = new MessageEmbed() + .setDescription(`Successfully ${perform} <@&${args[0].options[1].value}>'s income to $${args[0].options[2].value}`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); - return interaction.send({ embeds: [errorEmbed] }); - } else { - client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID}, {$pull: {"server.incomeRoles": args[0].options[0].value}}, function(err, res) { + } else if (args[0].options[0].value == 'remove') { + const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[1].value); + if (searchIndex == -1) { + const errorEmbed = new MessageEmbed() + .setDescription('**Error Notice:** Role not found') + .setColor("RED"); + + return interaction.send({ embeds: [errorEmbed] }); + } else { + const prompt = new MessageEmbed() + .setTitle(`Are you sure you want to remove this role as an income?`) + .setColor(client.config.EmbedColor) + + const opt = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [prompt], components: [opt] }); + + client.on("interactionCreate", ButtonInteraction => { + if(!ButtonInteraction.isButton()) return; + const queryString = ButtonInteraction.customId; + if (!queryString.endsWith(ButtonInteraction.member.user.id)) { + return ButtonInteraction.reply({ + content: "This button is not for you", + ephemeral: true + }) + } + let action = ''; + if (queryString==`yes-${interaction.member.user.id}`) { + action = 'removed'; + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID}, {$pull: {"server.incomeRoles": args[0].options[1].value}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + }); + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} <@&${args[0].options[0].value}> from income roles.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); + }); + return; + } + } + + } else if (args[0].name == 'commercial_role') { + if (args[0].options[0].value == 'set') { + + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID},{$set:{"server.commercialRole": args[0].options[1].value}}, function(err, res) { if (err) { client.log(err); - let embed = new MessageEmbed() - .setTitle(err) - .setColor("RED"); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") return interaction.send({ embeds: [embed] }); } }); + + const successEmbed = new MessageEmbed() + .setDescription(`Successfully set <@&${args[0].options[1].value}>'s as commercial role.\nUsers with this role can now create invoices and send advertisements.`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); + + } else if (args[0].options[0].value == 'remove') { + const prompt = new MessageEmbed() + .setTitle(`Are you sure you want to remove this role as commercial role?`) + .setColor(client.config.EmbedColor) + + const opt = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [prompt], components: [opt] }); + + client.on("interactionCreate", ButtonInteraction => { + if(!ButtonInteraction.isButton()) return; + const queryString = ButtonInteraction.customId; + if (!queryString.endsWith(ButtonInteraction.member.user.id)) { + return ButtonInteraction.reply({ + content: "This button is not for you", + ephemeral: true + }) + } + let action = ''; + if (queryString==`yes-${interaction.member.user.id}`) { + action = 'removed'; + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID}, {$set: {"server.commercialRole": null}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + }); + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} <@&${args[0].options[0].value}> as commercial role.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); + }); + return; } - let successEmbed = new MessageEmbed() - .setTitle('Success') - .setDescription(`Successfully remoed <@&${args[0].options[0].value}> from income roles.`) - .setColor('GREEN'); + } else if (args[0].name == 'officer_role') { + if (args[0].options[0].value == 'set') { - return interaction.send({ embeds: [successEmbed] }); + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID},{$set:{"server.officerRole": args[0].options[1].value}}, function(err, res) { + if (err) { + client.log(err); + const embed = new MessageEmbed() + .setDescriptions(`**Internal Error:** ${err}\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + + const successEmbed = new MessageEmbed() + .setDescription(`Successfully set <@&${args[0].options[1].value}>'s as officer role.\nUsers with this role can now fine other users.`) + .setColor('GREEN'); + + return interaction.send({ embeds: [successEmbed] }); + + } else if (args[0].options[0].value == 'remove') { + const prompt = new MessageEmbed() + .setTitle(`Are you sure you want to remove this role as officer role?`) + .setColor(client.config.EmbedColor) + + const opt = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [prompt], components: [opt] }); + + client.on("interactionCreate", ButtonInteraction => { + if(!ButtonInteraction.isButton()) return; + const queryString = ButtonInteraction.customId; + if (!queryString.endsWith(ButtonInteraction.member.user.id)) { + return ButtonInteraction.reply({ + content: "This button is not for you", + ephemeral: true + }) + } + let action = ''; + if (queryString==`yes-${interaction.member.user.id}`) { + action = 'removed'; + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID}, {$set: {"server.officerRole": null}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + }); + } else if (queryString==`no-${interaction.member.user.id}`) action = 'kept'; + + const successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} <@&${args[0].options[0].value}> as officer role.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); + }); + return; + } } else if (args[0].name == 'view') { - const tweetChannel = client.exists(GuildDB.tweetChannel) ? `\n╚➤ <#${GuildDB.tweetChannel}>` : ''; - const tweetColor = client.exists(GuildDB.tweetChannel) ? '+ ' : '- '; - const actionChannel = client.exists(GuildDB.actionChannel) ? `\n╚➤ <#${GuildDB.actionChannel}>` : ''; - const actionColor = client.exists(GuildDB.actionChannel) ? '+ ' : '- '; + const tweetChannel = GuildDB.tweetChannel ? `\n╚➤ <#${GuildDB.tweetChannel}>` : ''; + const tweetColor = GuildDB.tweetChannel ? '+ ' : '- '; + const actionChannel = GuildDB.actionChannel ? `\n╚➤ <#${GuildDB.actionChannel}>` : ''; + const actionColor = GuildDB.actionChannel ? '+ ' : '- '; + const advertsChannel = GuildDB.advertsChannel ? `\n╚➤ <#${GuildDB.advertsChannel}>` : '' + const advertsColor = GuildDB.advertsChannel ? '+ ' : '- '; const channelsInfo = GuildDB.customChannelStatus ? '\n╚➤ \`/channels\` to view' : ''; const channelColor = GuildDB.customChannelStatus ? '+ ' : '- '; const incomeInfo = GuildDB.incomeRoleStatus ? '\n╚➤ \`/work-roles\` to view' : ''; const incomeColor = GuildDB.incomeRoleStatus ? '+ ' : '- '; + const commercialRole = GuildDB.commercialRole ? `\n╚➤ <@&${GuildDB.commercialRole}>` : ''; + const commercialRoleColor = GuildDB.commercialRole ? '+ ' : '- '; + const officerRole = GuildDB.officerRole ? `\n╚➤ <@&${GuildDB.officerRole}>` : ''; + const officerRoleColor = GuildDB.officerRole ? '+ ' : '- '; const settingsEmbed = new MessageEmbed() .setColor(client.config.EmbedColor) .setTitle('Current Guild Configurations') @@ -526,6 +869,9 @@ module.exports = { { name: 'Has Tweet Channel?', value: `\`\`\`diff\n${tweetColor}${client.exists(GuildDB.tweetChannel)}\`\`\`${tweetChannel}`, inline: true }, { name: 'Has Action Channel?', value: `\`\`\`diff\n${actionColor}${client.exists(GuildDB.actionChannel)}\`\`\`${actionChannel}`, inline: true }, { name: 'Starting Balance', value: `\`\`\`arm\n$${GuildDB.startingBalance}\`\`\``, inline: true }, + { name: 'Has Adverts Channel?', value: `\`\`\`diff${advertsColor}${client.exists(GuildDB.advertsChannel)}\`\`\`${advertsChannel}`, inline: true }, + { name: 'Has Commercial Role?', value: `\`\`\`diff${commercialRoleColor}${client.exists(GuildDB.commercialRole)}\`\`\`${commercialRole}`, inline: true }, + { name: 'Has Officer Role?', value: `\`\`\`diff${officerRoleColor}${client.exists(GuildDB.officerRole)}\`\`\`${officerRole}`, inline: true }, ); return interaction.send({ embeds: [settingsEmbed] }); diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index 66e9262..f9614fe 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -136,74 +136,44 @@ class QuarksBot extends Client { } async GetGuild(GuildId) { - let serverID = GuildId; - let customChannelStatus, allowedChannels; - let actionChannel, tweetChannel; - let startingBalance, incomeRoles, incomeRoleStatus; let guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild); - // If guild not found, generate guild default - if (!guild) { - let newGuild = { - server: { - serverID: GuildId, - hasCustomChannels: false, - allowedChannels: [], - actionChannel: null, - tweetChannel: null, - startingBalance: 1000.00, - hasIncomeRoles: false, - incomeRoles: [], - } + // If guild not found, generate guild default + if (!guild) { + guild = { + server: { + serverID: GuildId, + allowedChannels: [], + actionChannel: null, + tweetChannel: null, + advertsChannel: null, + startingBalance: 1000.00, + incomeRoles: [], + commercialRole: null, + officerRole: null, } - this.dbo.collection("guilds").insertOne(newGuild, function(err, res) { - if (err) throw err; - }); - customChannelStatus = false; - allowedChannels = newGuild.server.allowedChannels; - actionChannel = newGuild.server.actionChannel; - tweetChannel = newGuild.server.tweetChannel; - startingBalance = newGuild.server.startingBalance; - incomeRoleStatus = newGuild.server.hasIncomeRoles - incomeRoles = newGuild.server.incomeRoles; - } else { - customChannelStatus = guild.server.allowedChannels.length > 0 ? true : false; - allowedChannels = guild.server.allowedChannels; - actionChannel = guild.server.actionChannel; - tweetChannel = guild.server.tweetChannel; - startingBalance = guild.server.startingBalance; - incomeRoleStatus = guild.server.incomeRoles.length > 0 ? true : false; - incomeRoles = guild.server.incomeRoles; } + this.dbo.collection("guilds").insertOne(guild, function(err, res) { + if (err) throw err; + }); + } + let guildData = { - serverID: serverID, - customChannelStatus: customChannelStatus, - allowedChannels: allowedChannels, - actionChannel: actionChannel, - tweetChannel: tweetChannel, - startingBalance: startingBalance, - incomeRoleStatus: incomeRoleStatus, - incomeRoles: incomeRoles, + serverID: GuildID, + customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false, + allowedChannels: guild.server.allowedChannels, + actionChannel: guild.server.actionChannel, + tweetChannel: guild.server.tweetChannel, + advertsChannel: guild.server.advertsChannel, + startingBalance: guild.server.startingBalance, + incomeRoleStatus: guild.server.incomeRoles.length > 0 ? true : false, + incomeRoles: guild.server.incomeRoles, + commercialRole: guild.server.commercialRole, + officerRole: guild.server.officerRole, } return guildData; } - /* - This command is to verify a user - has the correct role to use a - command ie. has cop role to use - name-search - */ - async verifyUseCommand(serverID, rolesCache, isList) { - let { customRoleStatus } = await this.GetGuild(serverID) - if (customRoleStatus) { - let hasRole = await this.checkRoleStatus(rolesCache, serverID, isList); - if (hasRole) { - return true // User has role, can use command - } else return false // User does not have role, can't use command - } else return true // There is no role limits - } - log(Text) { this.logger.log(Text); }