diff --git a/commands/deposit.js b/commands/deposit.js index 1dd2fdc..c52e82c 100644 --- a/commands/deposit.js +++ b/commands/deposit.js @@ -62,7 +62,7 @@ module.exports = { } newBalance = banking.account.balance + args[0].value; - newCash = Math.abs(banking.account.cash - args[0].value); + newCash = Math.abs(banking.account.cash.toFixed(2) - args[0].value); client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{"account.balance":newBalance,"account.cash":newCash}}, function(err, res) { if (err) { diff --git a/commands/remove-channel.js b/commands/remove-channel.js index 83b84ea..5622e27 100644 --- a/commands/remove-channel.js +++ b/commands/remove-channel.js @@ -11,14 +11,34 @@ module.exports = { SlashCommand: { options: [ { - name: "channel-type", - description: "What the channel is used for", - value: "channel-type", - type: 3, - required: true, - choices: [ - { name: "action", value: "action" }, { name: "tweet", value: "tweet" }, - ], + name: "action", + description: "remove action channel", + value: "action", + type: 1, + required: false, + }, + { + name: "tweet", + description: "remove tweet channel", + value: "tweet", + type: 1, + required: false, + }, + { + name: "allowed", + description: "remove an allowed channel", + value: "allowed", + type: 1, + required: false, + options: [ + { + name: "channel", + description: "Channel to send add to allowed channels", + value: "channel", + type: 7, + required: true, + }, + ] }, ], /** @@ -33,7 +53,66 @@ module.exports = { return interaction.send(`You are not allowed to use the bot in this channel.`); } - let channelType = args[0].value; + if (args[0].name == 'allowed') { + let channelid = args[0].options[0].value; + + let embed = new MessageEmbed() + .setTitle('Channel is not in allowed Channels') + .setColor("RED") + + if (!GuildDB.allowedChannels.includes(channelid)) return interaction.send({ embeds: [embed] }); + + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": channelid}}, function (err, res) { + + }); + + let message = new MessageEmbed() + .setTitle(`Are you sure you want to remove this channel from allowed channels?`) + .setColor(client.config.EmbedColor) + + let row = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId(`yes`) + .setLabel("Yes") + .setStyle("DANGER"), + new MessageButton() + .setCustomId(`no`) + .setLabel("No") + .setStyle("SUCCESS") + ) + + interaction.send({ embeds: [message], components: [row] }); + + client.once("interactionCreate", ButtonInteraction => { + let queryString = ButtonInteraction.customId; + let action = '' + if (queryString=='yes') { + action = 'removed'; + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$pull:{"server.allowedChannels": channelid}}, 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') { + action = 'kept'; + } + + let successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} channel.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); + }); + return; + } + + let channelType = args[0].name; let query; if (channelType == "action") { query = { @@ -83,7 +162,12 @@ module.exports = { } else if (queryString=='no') { action = 'kept'; } - return ButtonInteraction.update({ content: `Successfully ${action} channel.`, embeds: [], components: [] }); + + let successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle(`Successfully ${action} channel.`) + + return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); }); return; }, diff --git a/commands/set-channel.js b/commands/set-channel.js index 13c107d..1929cd7 100644 --- a/commands/set-channel.js +++ b/commands/set-channel.js @@ -17,12 +17,12 @@ module.exports = { type: 3, required: true, choices: [ - { name: "action", value: "action" }, { name: "tweet", value: "tweet" }, + { name: "action", value: "action" }, { name: "tweet", value: "tweet" }, { name: "allowed", value: "allowed" }, ], }, { name: "channel", - description: "Channel to send tweets", + description: "Channel to send actions/tweets", value: "channel", type: 7, required: true, @@ -49,6 +49,26 @@ module.exports = { if (channel.deleted) return interaction.send(`Connot set deleted channel to ${channelType} channel.`); let guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); + if (channelType == "allowed") { + client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push:{"server.allowedChannels": channelid}}, function (err, res) { + if (err) { + client.log(err); + let embed = new MessageEmbed() + .setTitle(err) + .setColor("RED") + + return interaction.send({ embeds: [embed] }); + } + }); + + let successEmbed = new MessageEmbed() + .setColor("GREEN") + .setTitle("Success") + .setDescription(`Successfully set <#${channelid}> as an allowed channel.`); + + return interaction.send({ embeds: [successEmbed] }); + } + let channelSetting, query; if (channelType == "action") { channelSetting = guild.server.actionChannel;