diff --git a/commands/verify.js b/commands/verify.js index 46fd44f..5c469fa 100644 --- a/commands/verify.js +++ b/commands/verify.js @@ -1,173 +1,172 @@ -const { SlashCommandBuilder } = require('discord.js'); -const env = require('dotenv').config(); +const { SlashCommandBuilder } = require("discord.js"); +const env = require("dotenv").config(); const hypixelApiKey = process.env.HYPIXELAPIKEY; -const fetch = require('axios'); -const { color, hypixelGuildID } = require('../config/options.json'); -const verify = require('../schemas/verifySchema.js') -const mongoose = require('mongoose'); -const { gm, manager, moderator, beast, member, trialmember, guildRole, guildStaff, defaultMember } = require('../config/roles.json'); - +const fetch = require("axios"); +const { color, hypixelGuildID } = require("../config/options.json"); +const verify = require("../schemas/verifySchema.js"); +const mongoose = require("mongoose"); +const { gm, manager, moderator, beast, member, trialmember, guildRole, guildStaff, defaultMember } = require("../config/roles.json"); module.exports = { - name: 'verify', - description: 'Verify yourself as a member of the server.', - type: 'slash', + name: "verify", + description: "Verify yourself as a member of the server.", + type: "slash", - data: new SlashCommandBuilder() - .setName('verify') - .setDescription('Verify yourself as a member of the server.') - .addStringOption(option => - option - .setName('ign') - .setDescription('Your in-game name.')) - .setDMPermission(false), + data: new SlashCommandBuilder() + .setName("verify") + .setDescription("Verify yourself as a member of the server.") + .addStringOption((option) => option.setName("ign").setDescription("Your in-game name.")) + .setDMPermission(false), - async execute(interaction) { + async execute(interaction) { + await interaction.deferReply(); - await interaction.deferReply(); + const user1 = interaction.user; + const user = await interaction.guild.members.fetch(user1.id); - const user1 = interaction.user; - const user = await interaction.guild.members.fetch(user1.id); + const fullUsername = user.user.username + "#" + user.user.discriminator; + const ign = interaction.options.getString("ign"); + const mojang = "https://api.mojang.com/users/profiles/minecraft/"; + const slothPixel = "https://api.slothpixel.me/api/players/"; + const guildAPI = "https://api.slothpixel.me/api/guilds/"; + const minotar = "https://minotar.net/helm/"; + const embedColor = Number(color.replace("#", "0x")); - const fullUsername = user.user.username + "#" + user.user.discriminator - const ign = interaction.options.getString('ign'); - const mojang = "https://api.mojang.com/users/profiles/minecraft/" - const slothPixel = "https://api.slothpixel.me/api/players/"; - const guildAPI = "https://api.slothpixel.me/api/guilds/" - const minotar = "https://minotar.net/helm/"; - const embedColor = Number(color.replace("#", "0x")); + const verifyData = await verify.findOne({ userID: user.id }); - const verifyData = await verify.findOne({ userID: user.id }) + if (verifyData) { + interaction.editReply("You are already verified."); + return; + } - if (verifyData) { - interaction.editReply('You are already verified.') - return - } + if (!ign) { + interaction.editReply("Please provide a player's IGN."); + return; + } - if (!ign) { - interaction.editReply('Please provide a player\'s IGN.') - return - } + try { + await fetch(mojang + ign); + } catch (err) { + interaction.editReply("That player doesn't exist. [Mojang]"); + return; + } - try { - await fetch(mojang + ign); - } catch (err) { - interaction.editReply('That player doesn\'t exist. [Mojang]') - return - } + const userCheck = await fetch(mojang + ign); + const userUUID = userCheck.data.id; - const userCheck = await fetch(mojang + ign); - const userUUID = userCheck.data.id; + try { + await fetch(slothPixel + userUUID); + } catch (err) { + interaction.editReply("That player doesn't exist. [Hypixel]"); + return; + } - try { - await fetch(slothPixel + userUUID); - } catch (err) { - interaction.editReply('That player doesn\'t exist. [Hypixel]') - return - } + const hypixelCheck = await fetch(slothPixel + userUUID); + const head = minotar + ign; - const hypixelCheck = await fetch(slothPixel + userUUID); - const head = minotar + ign; - - if (hypixelCheck.data.links.DISCORD !== fullUsername) { - interaction.editReply({ - embeds: [{ + if (hypixelCheck.data.links.DISCORD !== fullUsername) { + interaction.editReply({ + embeds: [ + { description: " The discord tag for `" + userCheck.data.name + "` is not `" + fullUsername + "`. Please link your discord account to your hypixel account.", color: embedColor - }] - }) - return - } - - try { - const guildCheck = await fetch(guildAPI + userUUID); - var responseGuildID = guildCheck.data.id; - } catch (err) { - var responseGuildID = null; - } + } + ] + }); + return; + } - if (responseGuildID !== hypixelGuildID) { + try { + const guildCheck = await fetch(guildAPI + userUUID); + var responseGuildID = guildCheck.data.id; + } catch (err) { + var responseGuildID = null; + } - await user.roles.add(defaultMember, "Verification") + if (responseGuildID !== hypixelGuildID) { + await user.roles.add(defaultMember, "Verification"); - await interaction.editReply({ - embeds: [{ - title: interaction.guild.name, - description: " You have successfully verified `" + fullUsername + "` with the account `" + hypixelCheck.data.username + "`.", - color: embedColor, - thumbnail: { - url: head - }, - footer: { - icon_url: interaction.guild.iconURL(), - text: interaction.guild.name + " | Developed by Taken#0002" - } - }] - }); - return - } + await interaction.editReply({ + embeds: [ + { + title: interaction.guild.name, + description: " You have successfully verified `" + fullUsername + "` with the account `" + hypixelCheck.data.username + "`.", + color: embedColor, + thumbnail: { + url: head + }, + footer: { + icon_url: interaction.guild.iconURL(), + text: interaction.guild.name + " | Developed by Taken#0002" + } + } + ] + }); + return; + } - const guildCheck = await fetch(guildAPI + userUUID); - const GuildMembers = await guildCheck.data.members; - const guildRank = GuildMembers.find(member => member.uuid === hypixelCheck.data.uuid).rank; + const guildCheck = await fetch(guildAPI + userUUID); + const GuildMembers = await guildCheck.data.members; + const guildRank = GuildMembers.find((member) => member.uuid === hypixelCheck.data.uuid).rank; - if (guildRank === "Guild Master" && responseGuildID === hypixelGuildID) { - await user.roles.add(gm, "Verification"); - await user.roles.add(guildRole, "Verification") - await user.roles.add(guildStaff, "Verification") - } + if (guildRank === "Guild Master" && responseGuildID === hypixelGuildID) { + await user.roles.add(gm, "Verification"); + await user.roles.add(guildRole, "Verification"); + await user.roles.add(guildStaff, "Verification"); + } - if (guildRank === "Manager" && responseGuildID === hypixelGuildID) { - await user.roles.add(manager, "Verification"); - await user.roles.add(guildRole, "Verification") - await user.roles.add(guildStaff, "Verification") - } + if (guildRank === "Manager" && responseGuildID === hypixelGuildID) { + await user.roles.add(manager, "Verification"); + await user.roles.add(guildRole, "Verification"); + await user.roles.add(guildStaff, "Verification"); + } - if (guildRank === "Moderator" && responseGuildID === hypixelGuildID) { - await user.roles.add(moderator, "Verification"); - await user.roles.add(guildRole, "Verification") - await user.roles.add(guildStaff, "Verification") - } - - if (guildRank === "Beast" && responseGuildID === hypixelGuildID) { - await user.roles.add(beast, "Verification"); - await user.roles.add(guildRole, "Verification") - } + if (guildRank === "Moderator" && responseGuildID === hypixelGuildID) { + await user.roles.add(moderator, "Verification"); + await user.roles.add(guildRole, "Verification"); + await user.roles.add(guildStaff, "Verification"); + } - if (guildRank === "Member" && responseGuildID === hypixelGuildID) { - await user.roles.add(member, "Verification"); - await user.roles.add(guildRole, "Verification") - } + if (guildRank === "Beast" && responseGuildID === hypixelGuildID) { + await user.roles.add(beast, "Verification"); + await user.roles.add(guildRole, "Verification"); + } - if (guildRank === "Trial Member" && responseGuildID === hypixelGuildID) { - await user.roles.add(trialmember, "Verification"); - await user.roles.add(guildRole, "Verification") - } + if (guildRank === "Member" && responseGuildID === hypixelGuildID) { + await user.roles.add(member, "Verification"); + await user.roles.add(guildRole, "Verification"); + } - await user.roles.add(defaultMember, "Verification") + if (guildRank === "Trial Member" && responseGuildID === hypixelGuildID) { + await user.roles.add(trialmember, "Verification"); + await user.roles.add(guildRole, "Verification"); + } - const newVerify = new verify({ - _id: new mongoose.Types.ObjectId(), - userID: user.id, - uuid: userUUID - }) + await user.roles.add(defaultMember, "Verification"); - await newVerify.save() + const newVerify = new verify({ + _id: new mongoose.Types.ObjectId(), + userID: user.id, + uuid: userUUID + }); - await interaction.editReply({ - embeds: [{ - title: interaction.guild.name, - description: "You have successfully verified `" + fullUsername + "` with the account `" + hypixelCheck.data.username + "`.", - color: embedColor, - thumbnail: { - url: head - }, - footer: { - icon_url: interaction.guild.iconURL(), - text: interaction.guild.name + " | Developed by Taken#0002" - } - }] - }); + await newVerify.save(); - } -}; \ No newline at end of file + await interaction.editReply({ + embeds: [ + { + title: interaction.guild.name, + description: "You have successfully verified `" + fullUsername + "` with the account `" + hypixelCheck.data.username + "`.", + color: embedColor, + thumbnail: { + url: head + }, + footer: { + icon_url: interaction.guild.iconURL(), + text: interaction.guild.name + " | Developed by Taken#0002" + } + } + ] + }); + } +}; diff --git a/index.js b/index.js index 251556c..4ba6057 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,17 @@ for (const file of modalFiles) { console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`); } } + +client.on(Events.InteractionCreate, async interaction => { + + if (interaction.isCommand()) { + console.log(interaction.user.username + "#" + interaction.user.discriminator + " ran " + interaction.commandName); + } else if (interaction.isButton()) { + console.log(interaction.user.username + "#" + interaction.user.discriminator + " clicked " + interaction.customId); + } + +}); + client.on(Events.ClientReady, () => { console.log("Logged in as " + client.user.tag + "!"); const channel = client.channels.cache.get(botLogChannel);