From 1d0ea55e887bd6ba53312900e56f1494afd0386d Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Tue, 5 Jul 2022 18:29:47 -0700 Subject: [PATCH] simplify commands --- ...moveActionChannel.js => remove-channel.js} | 35 ++++++-- commands/removeTweetChannel.js | 59 -------------- commands/set-channel.js | 81 +++++++++++++++++++ commands/setActionChannel.js | 46 ----------- commands/setTweetChannel.js | 46 ----------- 5 files changed, 109 insertions(+), 158 deletions(-) rename commands/{removeActionChannel.js => remove-channel.js} (64%) delete mode 100644 commands/removeTweetChannel.js create mode 100644 commands/set-channel.js delete mode 100644 commands/setActionChannel.js delete mode 100644 commands/setTweetChannel.js diff --git a/commands/removeActionChannel.js b/commands/remove-channel.js similarity index 64% rename from commands/removeActionChannel.js rename to commands/remove-channel.js index 04e2c07..c8d7466 100644 --- a/commands/removeActionChannel.js +++ b/commands/remove-channel.js @@ -1,15 +1,26 @@ const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); module.exports = { - name: "removeactionchannel", - description: "Remove action channel", - usage: "", + name: "remove-channel", + description: "Remove channel", + usage: "[channel type]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: ["MANAGE_GUILD"], }, SlashCommand: { - options: [], + 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" }, + ], + }, + ], /** * * @param {require("../structures/QuarksBot")} client @@ -21,9 +32,12 @@ module.exports = { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } + + let channelType = args[0].value; + let query = "server.actionChannel" ? channelType == "action" : "server.tweetChannel"; let message = new MessageEmbed() - .setTitle('Are you sure you want to stop using this channel for actions?') + .setTitle(`Are you sure you want to stop using this channel for ${channelType}s?`) .setColor(client.config.EmbedColor) let row = new MessageActionRow() @@ -45,8 +59,15 @@ module.exports = { let action = '' if (queryString=='yes') { action = 'removed'; - client.dbo.collection("guilds").updateOne({"server.serverID":ButtonInteraction.guild.id},{$set:{"server.actionChannel":null}},function(err, res) { - if (err) throw err; + client.dbo.collection("guilds").updateOne({"server.serverID":ButtonInteraction.guild.id},{$set:{query: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') { action = 'kept'; diff --git a/commands/removeTweetChannel.js b/commands/removeTweetChannel.js deleted file mode 100644 index b4b3ba9..0000000 --- a/commands/removeTweetChannel.js +++ /dev/null @@ -1,59 +0,0 @@ -const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); - -module.exports = { - name: "removetweetchannel", - description: "Remove tweet channel", - usage: "", - permissions: { - channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], - member: ["MANAGE_GUILD"], - }, - SlashCommand: { - options: [], - /** - * - * @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.`); - } - - let message = new MessageEmbed() - .setTitle('Are you sure you want to stop using this channel for tweets?') - .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":ButtonInteraction.guild.id},{$set:{"server.tweetChannel":null}},function(err, res) { - if (err) throw err; - }); - } else if (queryString=='no') { - action = 'kept'; - } - return ButtonInteraction.update({ content: `Successfully ${action} channel.`, embeds: [], components: [] }); - }); - return; - }, - }, -} \ No newline at end of file diff --git a/commands/set-channel.js b/commands/set-channel.js new file mode 100644 index 0000000..158dfc0 --- /dev/null +++ b/commands/set-channel.js @@ -0,0 +1,81 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "set-channel", + description: "set a channel", + usage: "[channel type] [channel]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: ["MANAGE_GUILD"], + }, + 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: "channel", + description: "Channel to send tweets", + value: "channel", + type: 7, + 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.`); + } + + let channelType = args[0].value; + let channelid = args[1].value; + let channel = client.channels.cache.get(channelid); + + if (!channel) return interaction.send(`Cannot find that channel.`); + if (channel.type=="voice") return interaction.send(`Connot set voice 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 channelSetting, query; + if (channelType == "action") { + channelSetting = guild.server.actionChannel; + query = "server.actionChannel" + } else if (channelType == "tweet") { + channelSetting = guild.server.tweetChannel; + query = "server.tweetChannel" + } + + if (channelSetting == channelid) return interaction.send(`The channel <#${args[1].value}> has already been set for ${channelType}s.`); + client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{query: 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 <#${args[0].value}> for ${channelType}.`); + + return interaction.send({ embeds: [successEmbed] }); + }); + }, + }, +} \ No newline at end of file diff --git a/commands/setActionChannel.js b/commands/setActionChannel.js deleted file mode 100644 index a7e9466..0000000 --- a/commands/setActionChannel.js +++ /dev/null @@ -1,46 +0,0 @@ -const { MessageEmbed } = require('discord.js'); - -module.exports = { - name: "actionchannel", - description: "Select a channel to send actions", - usage: "[channel]", - permissions: { - channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], - member: ["MANAGE_GUILD"], - }, - SlashCommand: { - options: [ - { - name: "channel", - description: "Channel to send action messages", - value: "channel", - type: 7, - 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.`); - } - - let channelid = args[0].value; - let channel = client.channels.cache.get(channelid); - if (!channel) return interaction.send(`Cannot find that channel.`); - if (channel.type=="voice") return interaction.send(`Connot set voice channel to actions channel.`); - if (channel.deleted) return interaction.send(`Connot set deleted channel to actions channel.`); - let guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); - if (client.exists(guild.server.actionChannel)&&guild.server.actionChannel==channelid) return interaction.send(`The channel <#${args[0].value}> has already been set for actions.`); - client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.actionChannel":channelid}},function(err, res) { - if (err) throw err; - return interaction.send(`Successfully set <#${args[0].value}> for tweets.`); - }); - }, - }, -} \ No newline at end of file diff --git a/commands/setTweetChannel.js b/commands/setTweetChannel.js deleted file mode 100644 index 67ca51f..0000000 --- a/commands/setTweetChannel.js +++ /dev/null @@ -1,46 +0,0 @@ -const { MessageEmbed } = require('discord.js'); - -module.exports = { - name: "tweetchannel", - description: "Select a channel to send tweets", - usage: "[channel]", - permissions: { - channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], - member: ["MANAGE_GUILD"], - }, - SlashCommand: { - options: [ - { - name: "channel", - description: "Channel to send tweets", - value: "channel", - type: 7, - 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.`); - } - - let channelid = args[0].value; - let channel = client.channels.cache.get(channelid); - if (!channel) return interaction.send(`Cannot find that channel.`); - if (channel.type=="voice") return interaction.send(`Connot set voice channel to tweets channel.`); - if (channel.deleted) return interaction.send(`Connot set deleted channel to tweets channel.`); - let guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); - if (client.exists(guild.server.tweetChannel)&&guild.server.tweetChannel==channelid) return interaction.send(`The channel <#${args[0].value}> has already been set for tweets.`); - client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.tweetChannel":channelid}},function(err, res) { - if (err) throw err; - return interaction.send(`Successfully set <#${args[0].value}> for tweets.`); - }); - }, - }, -} \ No newline at end of file