diff --git a/commands/set-income.js b/commands/set-income.js new file mode 100644 index 0000000..2c492c2 --- /dev/null +++ b/commands/set-income.js @@ -0,0 +1,82 @@ +const { MessageEmbed, Guild } = require('discord.js'); + +module.exports = { + name: "set-income", + description: "set a role to recieve income when working", + usage: "[role] [amount daily]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + SlashCommand: { + options: [ + { + name: "role", + description: "role for this income", + value: "role", + type: 8, + required: true, + }, + { + name: "amount", + description: "the amount to earn in 1 day of work", + value: 120.00, + type: 10, + required: true, + } + ], + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").MessageCreate} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { + return interaction.send(`You are not allowed to use the bot in this channel.`); + } + + if (args[1].value <= 0) { + let embed = new MessageEmbed() + .setTitle('Amount cannot be $0 or less than $0') + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + + const searchIndex = roles.findIndex((role) => role.role==args[0].value); + if (searchIndex == -1) { + let newIncome = { + role: args[0].value, + income: args[1].value, + } + + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push: {"server.incomeRoles":newIncome}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + }); + } else { + client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID, "server.incomeRoles.role": args[0].value}, + {$set: {"server.incomeRoles.$.income": args[1].value}}, function(err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED"); + + return interaction.send({ embeds: [embed] }); + } + }); + } + + return interaction.send(`Set <@&${args[0].value}>'s income to $${args[1].value}`); + }, + }, +} \ No newline at end of file diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index b22dec2..35961d0 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -122,7 +122,7 @@ class QuarksBot extends Client { let serverID = GuildId; let customChannelStatus, allowedChannels; let actionChannel, tweetChannel; - let startingBalance; + let startingBalance, incomeRoles; let guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild); // If guild not found, generate guild default @@ -135,6 +135,7 @@ class QuarksBot extends Client { actionChannel: null, tweetChannel: null, startingBalance: 1000.00, + incomeRoles: [], } } this.dbo.collection("guilds").insertOne(newGuild, function(err, res) { @@ -145,12 +146,14 @@ class QuarksBot extends Client { actionChannel = newGuild.server.actionChannel; tweetChannel = newGuild.server.tweetChannel; startingBalance = newGuild.server.startingBalance; + incomeRoles = newGuild.server.incomeRoles; } else { customChannelStatus = guild.server.hasCustomChannels; allowedChannels = guild.server.allowedChannels; actionChannel = guild.server.actionChannel; tweetChannel = guild.server.tweetChannel; startingBalance = guild.server.startingBalance; + incomeRoles = guild.server.incomeRoles; } let guildData = { serverID: serverID, @@ -158,7 +161,8 @@ class QuarksBot extends Client { allowedChannels: allowedChannels, actionChannel: actionChannel, tweetChannel: tweetChannel, - startingBalance: startingBalance + startingBalance: startingBalance, + incomeRoles: incomeRoles, } return guildData; }