From 9e701cbaee6910d7357274ca97b8f007d0d0e111 Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 7 Jun 2023 10:28:00 -0700 Subject: [PATCH] 6.11.0 unlink gamertag feature --- commands/admin-gamertag-unlink.js | 111 ++++++++++++++++++++++++++++++ commands/gamertag-unlink.js | 96 ++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 commands/admin-gamertag-unlink.js create mode 100644 commands/gamertag-unlink.js diff --git a/commands/admin-gamertag-unlink.js b/commands/admin-gamertag-unlink.js new file mode 100644 index 0000000..d4240db --- /dev/null +++ b/commands/admin-gamertag-unlink.js @@ -0,0 +1,111 @@ +const { EmbedBuilder } = require('discord.js'); +const bitfieldCalculator = require('discord-bitfield-calculator'); + +module.exports = { + name: "admin-gamertag-link", + debug: false, + global: false, + description: "Disconnect a users gamertag for them", + usage: "[cmd] [opt]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + options: [{ + name: "user", + description: "User to link gamertag to", + value: "user", + type: 6, + required: true, + }], + SlashCommand: { + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + + const permissions = bitfieldCalculator.permissions(interaction.member.permissions); + let canUseCommand = false; + + if (permissions.includes("MANAGE_GUILD")) canUseCommand = true; + if (GuildDB.hasBotAdmin && interaction.member.roles.filter(e => GuildDB.botAdminRoles.indexOf(e) !== -1).length > 0) canUseCommand = true; + if (!canUseCommand) return interaction.send({ content: 'You don\'t have the permissions to use this command.' }); + + if (!client.exists(GuildDB.playerstats)) { + GuildDB.playerstats = [{}]; + client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, { + $set: { + "server.playerstats": [] + } + }, function (err, res) { + if (err) return client.sendInternalError(interaction, err); + }); + } + + let playerStat = GuildDB.playerstats.find(stat => stat.discordID == args[0].value ); + if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** <@${args[0].value}> has no gamertag linked.`)] }); + + const warnGTOverwrite = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Notice:**\n> This action will unlink the gamertag \` ${playerStat.gamertag} \` from the user <@${playerStat.discordID}>. Are you sure you would like to continue?`) + + const opt = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(`AdminUnlinkGamertag-yes-${args[0].value}-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId(`AdminUnlinkGamertag-no-${args[0].value}-${interaction.member.user.id}`) + .setLabel("No") + .setStyle(ButtonStyle.Secondary) + ) + + return interaction.send({ embeds: [warnGTOverwrite], components: [opt] }); + + }, + }, + + Interactions: { + + AdminUnlinkGamertag: { + run: async(client, interaction, GuildDB) => { + if (!interaction.customId.endsWith(interaction.member.user.id)) + return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); + + if (interaction.customId.split('-')[1]=='yes') { + let playerStat = GuildDB.playerstats.find(stat => stat.gamertag == interaction.customId.split('-')[2]); + + playerStat.discordID = ""; + + let playerStatIndex = GuildDB.playerstats.indexOf(playerStat); + GuildDB.playerstats[playerStatIndex] = playerStat; + + client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, { + $set: { + 'server.playerstats': GuildDB.playerstats, + } + }); + + let connectedEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`Successfully unlinked \` ${playerStat.gamertag} \` from <@${interaction.customId.split('-')[2]}>.`); + + return interaction.update({ embeds: [connectedEmbed], components: [] }); + + } else { + const cancel = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription('**Canceled**\n> The gamertag unlink will not processed.'); + + return interaction.update({ embeds: [cancel], components: [] }); + } + } + } + + } +} \ No newline at end of file diff --git a/commands/gamertag-unlink.js b/commands/gamertag-unlink.js new file mode 100644 index 0000000..ee3dd9f --- /dev/null +++ b/commands/gamertag-unlink.js @@ -0,0 +1,96 @@ +const { EmbedBuilder } = require('discord.js'); + +module.exports = { + name: "gamertag-unlink", + debug: false, + global: false, + description: "Disconnect gamertag", + usage: "[cmd] [opt]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + SlashCommand: { + /** + * + * @param {require("../structures/QuarksBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + run: async (client, interaction, args, { GuildDB }) => { + + if (!client.exists(GuildDB.playerstats)) { + GuildDB.playerstats = [{}]; + client.dbo.collection("guilds").updateOne({ "server.serverID": GuildDB.serverID }, { + $set: { + "server.playerstats": [] + } + }, function (err, res) { + if (err) return client.sendInternalError(interaction, err); + }); + } + + let playerStat = GuildDB.playerstats.find(stat => stat.discordID == interaction.user.member.id); + if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**No Gamertag Linked** It Appears your don't have a gamertag linked to your account.`)] }); + + const warnGTOverwrite = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Notice:**\n> Are you sure you want to unlink your gamertag? This will limit some automatic features.`); + + const opt = new ActionRowBuilder() + .addComponents( + new ButtonBuilder() + .setCustomId(`UnlinkGamertag-yes-${interaction.member.user.id}`) + .setLabel("Yes") + .setStyle(ButtonStyle.Success), + new ButtonBuilder() + .setCustomId(`UnlinkGamertag-no-${interaction.member.user.id}`) + .setLabel("No") + .setStyle(ButtonStyle.Secondary) + ) + + return interaction.send({ embeds: [warnGTOverwrite], components: [opt] }); + } + }, + }, + + Interactions: { + + UnlinkGamertag: { + run: async(client, interaction, GuildDB) => { + if (!interaction.customId.endsWith(interaction.member.user.id)) + return interaction.reply({ content: 'This interaction is not for you', flags: (1 << 6) }); + + if (interaction.customId.split('-')[1]=='yes') { + let playerStat = GuildDB.playerstats.find(stat => stat.discordID == interaction.member.user.id); + + playerStat.discordID = ""; + + let playerStatIndex = GuildDB.playerstats.indexOf(playerStat); + GuildDB.playerstats[playerStatIndex] = playerStat; + + client.dbo.collection("guilds").updateOne({ 'server.serverID': GuildDB.serverID }, { + $set: { + 'server.playerstats': GuildDB.playerstats, + } + }); + + let connectedEmbed = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`Successfully unlinked \` ${playerStat.gamertag} \` as your gamertag.`); + + return interaction.update({ embeds: [connectedEmbed], components: [] }); + + } else { + const cancel = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription('**Canceled**\n> The gamertag unlink will not processed.'); + + return interaction.update({ embeds: [cancel], components: [] }); + } + } + } + + } +} \ No newline at end of file diff --git a/package.json b/package.json index fd6b537..2269972 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "6.10.3", + "version": "6.11.0", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": {