From 1b3e3123657270caf9ab1adf954998c6feef9192 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 19 Nov 2023 19:32:46 +0100 Subject: [PATCH] Added uuid command and function to format uuids --- commands/uuid.js | 57 +++++++++++++++++++++++++++++++++++++++++ utils/functions/uuid.js | 5 ++++ utils/utils.js | 4 ++- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 commands/uuid.js create mode 100644 utils/functions/uuid.js diff --git a/commands/uuid.js b/commands/uuid.js new file mode 100644 index 0000000..89dca76 --- /dev/null +++ b/commands/uuid.js @@ -0,0 +1,57 @@ +const { SlashCommandBuilder } = require('discord.js') +const { color } = require('../config/options.json') +const { getUUID, getIGN, getHeadURL, formatUuid } = require('../utils/utils.js') + +module.exports = { + name: 'uuid', + description: 'Get a player\'s UUID', + type: 'slash', + dev: true, + + data: new SlashCommandBuilder() + .setName('uuid') + .setDescription('Get a player\'s UUID') + .addStringOption(option => option + .setName('ign') + .setDescription('Player\'s name') + .setRequired(true) + ), + + /** @param { import('discord.js').ChatInputCommandInteraction } interaction */ + + async execute(interaction) { + + await interaction.deferReply() + + const ign = interaction.options.getString('ign') + const uuid = await getUUID(ign) + const formattedUuid = formatUuid(uuid) + const newIgn = await getIGN(uuid) + const head = await getHeadURL(ign) + const embedColor = Number(color.replace('#', '0x')) + + if (!uuid) { + interaction.editReply({ + description: 'That player doesn\'t exist!', + color: embedColor + }) + return + } + + await interaction.editReply({ + embeds: [{ + title: newIgn, + description: "**UUID:** `" + uuid + "`\n" + + "**Formatted UUID:** `" + formattedUuid + "`", + color: embedColor, + thumbnail: { + url: head + }, + footer: { + text: interaction.guild.name + " | Developed by taken.lua", + icon_url: interaction.guild.iconURL({ dynamic: true }) + } + }] + }) + } +} diff --git a/utils/functions/uuid.js b/utils/functions/uuid.js new file mode 100644 index 0000000..e7c1ea8 --- /dev/null +++ b/utils/functions/uuid.js @@ -0,0 +1,5 @@ +function formatUuid(uuid) { + return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5') +} + +module.exports = { formatUuid } diff --git a/utils/utils.js b/utils/utils.js index efbf766..7e5d837 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,6 +1,7 @@ const { skywarsLevel } = require('./functions/skywars.js') const { bedwarsLevel } = require('./functions/bedwars.js') const { hypixelLevel } = require('./functions/hypixel.js') +const { formatUuid } = require('./functions/uuid.js') const { guildLevel, scaledGEXP } = require('./functions/guild.js') const { getUUID, getIGN, getPlayer, getGuild, getHeadURL } = require('./functions/account.js') @@ -14,5 +15,6 @@ module.exports = { getIGN, getPlayer, getGuild, - getHeadURL + getHeadURL, + formatUuid }