From 2b93f57511b9b25465cb4e9acc8403cb1efebd9f Mon Sep 17 00:00:00 2001 From: Braeden Sowinski Date: Wed, 7 Jun 2023 11:08:16 -0700 Subject: [PATCH] update cmd usage and add lookup features --- commands/admin-gamertag-link.js | 2 +- commands/admin-gamertag-unlink.js | 2 +- commands/ban-player.js | 2 +- commands/factions.js | 2 +- commands/gamertag-link.js | 2 +- commands/gamertag-unlink.js | 2 +- commands/lookup-discord.js | 60 +++++++++++++++++++++++++++++++ commands/lookup-gamertag.js | 52 +++++++++++++++++++++++++++ package.json | 2 +- 9 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 commands/lookup-discord.js create mode 100644 commands/lookup-gamertag.js diff --git a/commands/admin-gamertag-link.js b/commands/admin-gamertag-link.js index b7919a8..f5f9a32 100644 --- a/commands/admin-gamertag-link.js +++ b/commands/admin-gamertag-link.js @@ -6,7 +6,7 @@ module.exports = { debug: false, global: false, description: "Connect a users gamertag for them", - usage: "[cmd] [opt]", + usage: "[user] [gamertag]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/admin-gamertag-unlink.js b/commands/admin-gamertag-unlink.js index 75d3832..1c60c5e 100644 --- a/commands/admin-gamertag-unlink.js +++ b/commands/admin-gamertag-unlink.js @@ -6,7 +6,7 @@ module.exports = { debug: false, global: false, description: "Disconnect a users gamertag for them", - usage: "[cmd] [opt]", + usage: "[user]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/ban-player.js b/commands/ban-player.js index 5248d9f..f585fff 100644 --- a/commands/ban-player.js +++ b/commands/ban-player.js @@ -7,7 +7,7 @@ module.exports = { debug: false, global: false, description: "Ban a player from the DayZ Server.", - usage: "", + usage: "[gamertag]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/factions.js b/commands/factions.js index 16846e1..6ba25dc 100644 --- a/commands/factions.js +++ b/commands/factions.js @@ -6,7 +6,7 @@ module.exports = { debug: false, global: false, description: "view the armband of a faction", - usage: "", + usage: "[role]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/gamertag-link.js b/commands/gamertag-link.js index b7ce0bc..5d68863 100644 --- a/commands/gamertag-link.js +++ b/commands/gamertag-link.js @@ -5,7 +5,7 @@ module.exports = { debug: false, global: false, description: "Connect DayZ account to gain server access", - usage: "[cmd] [opt]", + usage: "[gamertag]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/gamertag-unlink.js b/commands/gamertag-unlink.js index 181bf5d..82ed8ff 100644 --- a/commands/gamertag-unlink.js +++ b/commands/gamertag-unlink.js @@ -5,7 +5,7 @@ module.exports = { debug: false, global: false, description: "Disconnect gamertag", - usage: "[cmd] [opt]", + usage: "", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: [], diff --git a/commands/lookup-discord.js b/commands/lookup-discord.js new file mode 100644 index 0000000..2c59c03 --- /dev/null +++ b/commands/lookup-discord.js @@ -0,0 +1,60 @@ +const { EmbedBuilder } = require('discord.js'); +const bitfieldCalculator = require('discord-bitfield-calculator'); + +module.exports = { + name: "lookup-discord", + debug: false, + global: false, + description: "Search for a users discord from a gamertag", + usage: "[gamertag]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + options: [{ + name: "gamertag", + description: "Gamertag of player", + value: "gamertag", + type: 3, + 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 }) => { + + 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.gamertag == args[0].value ); + if (playerStat == undefined) return interaction.send({ embeds: [new EmbedBuilder().setColor(client.config.Colors.Yellow).setDescription(`**Not Found** This gamertag \` ${args[0].value} \` cannot be found, the gamertag may be incorrect or this player has not logged onto the server before for at least \` 5 minutes \`.`)] }); + + if (client.exists(playerStat.discordID)) { + const found = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Record Found**\n> The gamertag \` ${playerStat.gamertag} \` is currently linked to <@${playerStat.discordID}>.`) + + return interaction.send({ embeds: [found], components: [opt] }); + } + + let notFound = new EmbedBuilder() + .setColor(client.config.Colors.Default) + .setDescription(`**Record Not Found**\n/ The gamertag \` ${playerStat.gamertag} \` currently has no linked Discord account.`); + + return interaction.send({ embeds: [notFound] }) + }, + }, +} \ No newline at end of file diff --git a/commands/lookup-gamertag.js b/commands/lookup-gamertag.js new file mode 100644 index 0000000..60aca0f --- /dev/null +++ b/commands/lookup-gamertag.js @@ -0,0 +1,52 @@ +const { EmbedBuilder } = require('discord.js'); +const bitfieldCalculator = require('discord-bitfield-calculator'); + +module.exports = { + name: "lookup-gamertag", + debug: false, + global: false, + description: "Search for a users linked gamertag", + usage: "[user]", + permissions: { + channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], + member: [], + }, + options: [{ + name: "user", + description: "Discord User", + 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 }) => { + + 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** The user <@${args[0].value}> has not linked a gamertag.`)] }); + + const found = new EmbedBuilder() + .setColor(client.config.Colors.Yellow) + .setDescription(`**Record Found**\n> The user <@${playerStat.discordID}> has linked the gamertag \` ${playerStat.gamertag} \`.`) + + return interaction.send({ embeds: [found], components: [opt] }); + }, + }, +} \ No newline at end of file diff --git a/package.json b/package.json index 6822ddd..90594ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayz-armbands", - "version": "6.11.3", + "version": "6.12.1", "description": "A General Purpose Discord Bot for DayZ Servers.", "main": "index.js", "nodemonConfig": {