const { MessageEmbed, Guild } = require('discord.js'); module.exports = { name: "settings", debug: false, description: "configure your server settings", usage: "[opt] [action] [value]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: ["MANAGE_GUILD"], }, SlashCommand: { options: [ { name: "allowed_channels", description: "set channels you're allowed to use the bot in", value: "allowed_channels", type: 1, options: [ { name: "add_or_remove", description: "add/remove channel", value: "add_or_remove", type: 3, required: true, choices: [ { name: "add", value: "add" }, { name: "remove", value: "remove" }, ] }, { name: "channel", description: "the channel to configure", value: "channel", type: 7, required: true, } ] }, { name: "action_channel", description: "set the channel to be used for /me commands", value: "action_channel", type: 1, options: [ { name: "add_or_remove", description: "add/remove channel", value: "add_or_remove", type: 3, required: true, choices: [ { name: "set", value: "set" }, { name: "remove", value: "remove" }, ] }, { name: "channel", description: "the channel to configure", value: "channel", type: 7, required: true, } ] }, { name: "tweet_channel", description: "set the channel to be used for /tweet commands", value: "tweet_channel", type: 1, options: [ { name: "add_or_remove", description: "add/remove channel", value: "add_or_remove", type: 3, required: true, choices: [ { name: "set", value: "set" }, { name: "remove", value: "remove" }, ] }, { name: "channel", description: "the channel to configure", value: "channel", type: 7, required: true, } ] }, { name: "starting_balance", description: "set the starting balance", value: "starting_balance", type: 1, options: [{ name: "amount", description: "the amount to set the starting balance", value: 1000.00, type: 10, required: true, }] }, { name: "set_income_role", description: "add/update a role to earn income on /work command", value: "set_income_role", type: 1, 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, } ], }, { name: "remove_income_role", description: "remove a role from earning income", value: "remove_income_role", type: 1, options: [ { name: "role", description: "role to remove", value: "role", type: 8, required: true, }, ], }, { name: "view", description: "view current settings configuration", value: "view", type: 1, } ], /** * * @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[0].name == 'allowed_channels') { const channelid = args[0].options[1].value; if (args[0].options[0].value == 'add') { const channel = client.channels.cache.get(channelid); const errorEmbed = new MessageEmbed().setColor("RED") let error = false; if (!channel) errorEmbed.setDescription(`**Error Notice:** Cannot find that channel.`); if (channel.type=="voice") errorEmbed.setDescriptions(`**Error Notice:** Cannot add voice channel to allowed channels.`); if (channel.deleted) errorEmbed.setDescription(`**Error Notice":** Cannot add deleted channel to allowed channels.`); if (error) return interaction.send({ embeds: [errorEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push:{"server.allowedChannels": channelid}}, function (err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); const successEmbed = new MessageEmbed() .setColor("GREEN") .setDescription(`**Success:** Set <#${channelid}> as an allowed channel.`); return interaction.send({ embeds: [successEmbed] }); } else if (args[0].options[0].value == 'remove') { const embed = new MessageEmbed() .setDescription(`**Error Notice:** <#${channelid}> 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) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); const prompt = new MessageEmbed() .setTitle(`Are you sure you want to remove this channel from allowed channels?`) .setColor(client.config.EmbedColor) const opt = new MessageActionRow() .addComponents( new MessageButton() .setCustomId(`yes`) .setLabel("Yes") .setStyle("DANGER"), new MessageButton() .setCustomId(`no`) .setLabel("No") .setStyle("SUCCESS") ) interaction.send({ embeds: [prompt], components: [opt] }); client.once("interactionCreate", ButtonInteraction => { const 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); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); } else if (queryString=='no') action = 'kept'; const successEmbed = new MessageEmbed() .setColor("GREEN") .setTitle(`Successfully ${action} channel.`) return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); }); return; } } else if (args[0].name == 'action_channel') { const channelid = args[0].options[1].value; if (args[0].options[0].value == 'set') { const guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); const channelSetting = guild.server.actionChannel; const presetEmbed = new MessageEmbed() .setColor(client.config.EmbedColor) .setDescription(`The channel <#${channelid}> has already been set for actions.`) if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.actionChannel":channelid}},function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); const successEmbed = new MessageEmbed() .setColor("GREEN") .setTitle(`Successfully set <#${channelid}> for actions.`) return interaction.send({ embeds: [successEmbed] }); } else if (args[0].options[0].value == 'remove') { const prompt = new MessageEmbed() .setTitle(`Are you sure you want to stop using this channel for actions?`) .setColor(client.config.EmbedColor) const opt = new MessageActionRow() .addComponents( new MessageButton() .setCustomId(`yes`) .setLabel("Yes") .setStyle("DANGER"), new MessageButton() .setCustomId(`no`) .setLabel("No") .setStyle("SUCCESS") ) interaction.send({ embeds: [prompt], components: [opt] }); client.once("interactionCreate", ButtonInteraction => { const queryString = ButtonInteraction.customId; 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) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); } else if (queryString=='no') action = 'kept'; const successEmbed = new MessageEmbed() .setColor("GREEN") .setTitle(`Successfully ${action} channel.`) return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); }); return; } } else if (args[0].name == 'tweet_channel') { const channelid = args[0].options[1].value; if (args[0].options[0].value == 'set') { const guild = await client.dbo.collection("guilds").findOne({"server.serverID":interaction.guild.id}).then(guild => guild); const channelSetting = guild.server.tweetChannel; const presetEmbed = new MessageEmbed() .setColor(client.config.EmbedColor) .setDescription(`The channel <#${channelid}> has already been set for tweets.`) if (channelSetting == channelid) return interaction.send({ embeds: [presetEmbed] }); client.dbo.collection("guilds").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.actionChannel":channelid}},function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); const successEmbed = new MessageEmbed() .setColor("GREEN") .setTitle(`Successfully set <#${channelid}> for actions.`) return interaction.send({ embeds: [successEmbed] }); } else if (args[0].options[0].value == 'remove') { const prompt = new MessageEmbed() .setTitle(`Are you sure you want to stop using this channel for tweets?`) .setColor(client.config.EmbedColor) const opt = new MessageActionRow() .addComponents( new MessageButton() .setCustomId(`yes`) .setLabel("Yes") .setStyle("DANGER"), new MessageButton() .setCustomId(`no`) .setLabel("No") .setStyle("SUCCESS") ) interaction.send({ embeds: [prompt], components: [opt] }); client.once("interactionCreate", ButtonInteraction => { const 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) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); } else if (queryString=='no') action = 'kept'; const successEmbed = new MessageEmbed() .setColor("GREEN") .setTitle(`Successfully ${action} channel.`) return ButtonInteraction.update({ content: '', embeds: [successEmbed], components: [] }); }); return; } } else if (args[0].name == 'starting_balance') { client.dbo.collection("guilds").updateOne({"server.serverID": GuildDB.serverID}, {"server.startingBalance":args[0].options[0].value}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); let successEmbed = new MessageEmbed() .setColor('GREEN') .setDescription(`Successfully set $${args[0].options[0].value.toFixed(2)} as starting balance`); return interaction.send({ embeds: [successEmbed] }); } else if (args[0].name == 'set_income_role') { if (args[0].options[1].value <= 0) { let embed = new MessageEmbed() .setDescriptions('**Error Notice:** Amount cannot be $0 or less than $0.') .setColor("RED"); return interaction.send({ embeds: [embed] }); } const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[0].value); if (searchIndex == -1) { const newIncome = { role: args[0].options[0].value, income: args[0].options[1].value, } client.dbo.collection("guilds").updateOne({"server.serverID":GuildDB.serverID}, {$push: {"server.incomeRoles":newIncome}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); } else { client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID, "server.incomeRoles.role": args[0].options[0].value}, {$set: {"server.incomeRoles.$.income": args[0].options[1].value}}, function(err, res) { if (err) { client.log(err); const embed = new MessageEmbed() .setDescriptions(`**Internal Error:** ${err}\nContact the Developers`) .setColor("RED") return interaction.send({ embeds: [embed] }); } }); } const successEmbed = new MessageEmbed() .setDescription(`Successfully updated <@&${args[0].options[0].value}>'s income to $${args[0].options[1].value}`) .setColor('GREEN'); return interaction.send({ embeds: [successEmbed] }); } else if (args[0].name == 'remove_income_role') { const searchIndex = GuildDB.incomeRoles.findIndex((role) => role.role==args[0].options[0].value); if (searchIndex == -1) { const errorEmbed = new MessageEmbed() .setDescription('**Error Notice:** Role not found') .setColor("RED"); return interaction.send({ embeds: [errorEmbed] }); } else { client.dbo.collection("guilds").updateOne({"server.serverID":Guild.serverID}, {$pull: {"server.incomeRoles": args[0].options[0].value}}, 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() .setTitle('Success') .setDescription(`Successfully remoed <@&${args[0].options[0].value}> from income roles.`) .setColor('GREEN'); return interaction.send({ embeds: [successEmbed] }); } else if (args[0].name == 'view') { const tweetChannel = client.exists(GuildDB.tweetChannel) ? `\n╚➤ <#${GuildDB.tweetChannel}>` : ''; const tweetColor = client.exists(GuildDB.tweetChannel) ? '+ ' : '- '; const actionChannel = client.exists(GuildDB.actionChannel) ? `\n╚➤ <#${GuildDB.actionChannel}>` : ''; const actionColor = client.exists(GuildDB.actionChannel) ? '+ ' : '- '; const channelsInfo = GuildDB.customChannelStatus ? '\n╚➤ \`/channels\` to view' : ''; const channelColor = GuildDB.customChannelStatus ? '+ ' : '- '; const incomeInfo = GuildDB.incomeRoleStatus ? '\n╚➤ \`/work-roles\` to view' : ''; const incomeColor = GuildDB.incomeRoleStatus ? '+ ' : '- '; const settingsEmbed = new MessageEmbed() .setColor(client.config.EmbedColor) .setTitle('Current Guild Configurations') .addFields( { name: 'Guild ID', value: `\`\`\`arm\n${GuildDB.serverID}\`\`\``, inline: true }, { name: 'Has Income Roles?', value: `\`\`\`diff\n${incomeColor}${GuildDB.incomeRoleStatus}\`\`\`${incomeInfo}`, inline: true }, { name: 'Has Allowed Channels?', value: `\`\`\`diff\n${channelColor}${GuildDB.customChannelStatus}\`\`\`${channelsInfo}`, inline: true }, { name: 'Has Tweet Channel?', value: `\`\`\`diff\n${tweetColor}${client.exists(GuildDB.tweetChannel)}\`\`\`${tweetChannel}`, inline: true }, { name: 'Has Action Channel?', value: `\`\`\`diff\n${actionColor}${client.exists(GuildDB.actionChannel)}\`\`\`${actionChannel}`, inline: true }, { name: 'Starting Balance', value: `\`\`\`arm\n$${GuildDB.startingBalance}\`\`\``, inline: true }, ); return interaction.send({ embeds: [settingsEmbed] }); } }, }, }