add/remove channels with allowed channels

This commit is contained in:
SowinskiBraeden committed 2022-07-06 12:00:02 -07:00
1 parent 8a5986a620
commit 250061756b
3 files changed
+116 -12

No files matched your search

+1 -1
View File
@@ -62,7 +62,7 @@ module.exports = {
} }
newBalance = banking.account.balance + args[0].value; 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) { client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{"account.balance":newBalance,"account.cash":newCash}}, function(err, res) {
if (err) { if (err) {
+93 -9
View File
@@ -11,14 +11,34 @@ module.exports = {
SlashCommand: { SlashCommand: {
options: [ options: [
{ {
name: "channel-type", name: "action",
description: "What the channel is used for", description: "remove action channel",
value: "channel-type", value: "action",
type: 3, 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, required: true,
choices: [ },
{ name: "action", value: "action" }, { name: "tweet", value: "tweet" }, ]
],
}, },
], ],
/** /**
@@ -33,7 +53,66 @@ module.exports = {
return interaction.send(`You are not allowed to use the bot in this channel.`); 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; let query;
if (channelType == "action") { if (channelType == "action") {
query = { query = {
@@ -83,7 +162,12 @@ module.exports = {
} else if (queryString=='no') { } else if (queryString=='no') {
action = 'kept'; 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; return;
}, },
+22 -2
View File
@@ -17,12 +17,12 @@ module.exports = {
type: 3, type: 3,
required: true, required: true,
choices: [ choices: [
{ name: "action", value: "action" }, { name: "tweet", value: "tweet" }, { name: "action", value: "action" }, { name: "tweet", value: "tweet" }, { name: "allowed", value: "allowed" },
], ],
}, },
{ {
name: "channel", name: "channel",
description: "Channel to send tweets", description: "Channel to send actions/tweets",
value: "channel", value: "channel",
type: 7, type: 7,
required: true, required: true,
@@ -49,6 +49,26 @@ module.exports = {
if (channel.deleted) return interaction.send(`Connot set deleted channel to ${channelType} channel.`); 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); 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; let channelSetting, query;
if (channelType == "action") { if (channelType == "action") {
channelSetting = guild.server.actionChannel; channelSetting = guild.server.actionChannel;