From 9d9c23e8ccc03fcf83c9bcc0d95b65db818c1614 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Sun, 3 Jul 2022 19:12:09 -0700 Subject: [PATCH] bug fixes/remove tweet channel --- commands/help.js | 10 +----- commands/me.js | 9 +---- commands/removeTweetChannel.js | 61 ++++++++++++++++++++++++++++++++++ commands/setTweetChannel.js | 46 +++++++++++++++++++++++++ commands/tweet.js | 9 +---- structures/QuarksBot.js | 52 +++++++++++++++-------------- 6 files changed, 137 insertions(+), 50 deletions(-) create mode 100644 commands/removeTweetChannel.js create mode 100644 commands/setTweetChannel.js diff --git a/commands/help.js b/commands/help.js index 3a5bfff..d45e077 100644 --- a/commands/help.js +++ b/commands/help.js @@ -8,14 +8,6 @@ module.exports = { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, - /** - * - * @param {require("../structures/LinesPoliceCadBot")} client - * @param {import("discord.js").Message} message - * @param {string[]} args - * @param {*} param3 - */ - SlashCommand: { options: [ { @@ -28,7 +20,7 @@ module.exports = { ], /** * - * @param {require("../structures/LinesPoliceCadBot")} client + * @param {require("../structures/QuarksBot")} client * @param {import("discord.js").Message} message * @param {string[]} args * @param {*} param3 diff --git a/commands/me.js b/commands/me.js index f5434d2..6911bda 100644 --- a/commands/me.js +++ b/commands/me.js @@ -8,13 +8,6 @@ module.exports = { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, - /** - * - * @param {require("../structures/LinesPoliceCadBot")} client - * @param {import("discord.js").MessageCreate} message - * @param {string[]} args - * @param {*} param3 - */ SlashCommand: { options: [ { @@ -27,7 +20,7 @@ module.exports = { ], /** * - * @param {require("../structures/LinesPoliceCadBot")} client + * @param {require("../structures/QuarksBot")} client * @param {import("discord.js").MessageCreate} message * @param {string[]} args * @param {*} param3 diff --git a/commands/removeTweetChannel.js b/commands/removeTweetChannel.js new file mode 100644 index 0000000..96020ca --- /dev/null +++ b/commands/removeTweetChannel.js @@ -0,0 +1,61 @@ +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 => { + if (ButtonInteraction.message.interaction && + ButtonInteraction.message.interaction.commandName!='removetweetchannel') return; + 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/setTweetChannel.js b/commands/setTweetChannel.js new file mode 100644 index 0000000..92dbb6e --- /dev/null +++ b/commands/setTweetChannel.js @@ -0,0 +1,46 @@ +const { MessageEmbed } = require('discord.js'); + +module.exports = { + name: "settweetchannel", + 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 add to allowed channles", + 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 preferred channel.`); + if (channel.deleted) return interaction.send(`Connot set deleted channel to preferred 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 diff --git a/commands/tweet.js b/commands/tweet.js index df67317..5156971 100644 --- a/commands/tweet.js +++ b/commands/tweet.js @@ -8,13 +8,6 @@ module.exports = { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], }, - /** - * - * @param {require("../structures/LinesPoliceCadBot")} client - * @param {import("discord.js").MessageCreate} message - * @param {string[]} args - * @param {*} param3 - */ SlashCommand: { options: [ { @@ -27,7 +20,7 @@ module.exports = { ], /** * - * @param {require("../structures/LinesPoliceCadBot")} client + * @param {require("../structures/QuarksBot")} client * @param {import("discord.js").MessageCreate} message * @param {string[]} args * @param {*} param3 diff --git a/structures/QuarksBot.js b/structures/QuarksBot.js index 51c680b..282c25c 100644 --- a/structures/QuarksBot.js +++ b/structures/QuarksBot.js @@ -27,32 +27,34 @@ class QuarksBot extends Client { this.Ready = false; this.ws.on("INTERACTION_CREATE", async (interaction) => { - client.log("Interaction") - let GuildDB = await this.GetGuild(interaction.guild_id); - - const command = interaction.data.name.toLowerCase(); - const args = interaction.data.options; + if (interaction.type!=3) { + client.log("Interaction") + let GuildDB = await this.GetGuild(interaction.guild_id); - //Easy to send respnose so ;) - interaction.guild = await this.guilds.fetch(interaction.guild_id); - interaction.send = async (message) => { - return await this.api - .interactions(interaction.id, interaction.token) - .callback.post({ - data: { - type: 4, - data: - typeof message == "string" - ? { content: message } - : message.type && message.type === "rich" - ? { embeds: [message] } - : message, - }, - }); - }; - let cmd = client.commands.get(command); - if (cmd.SlashCommand && cmd.SlashCommand.run) - cmd.SlashCommand.run(this, interaction, args, { GuildDB }); + const command = interaction.data.name.toLowerCase(); + const args = interaction.data.options; + + //Easy to send respnose so ;) + interaction.guild = await this.guilds.fetch(interaction.guild_id); + interaction.send = async (message) => { + return await this.api + .interactions(interaction.id, interaction.token) + .callback.post({ + data: { + type: 4, + data: + typeof message == "string" + ? { content: message } + : message.type && message.type === "rich" + ? { embeds: [message] } + : message, + }, + }); + }; + let cmd = client.commands.get(command); + if (cmd.SlashCommand && cmd.SlashCommand.run) + cmd.SlashCommand.run(this, interaction, args, { GuildDB }); + } }); const client = this;