Finishing update and verify
This commit is contained in:
162
commands/update.js
Normal file
162
commands/update.js
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { hypixelApiKey } = require('../config.json');
|
||||||
|
const fetch = require('axios');
|
||||||
|
const verify = require('../schemas/verifySchema.js')
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
const { color } = require('../config.json');
|
||||||
|
const { gm, manager, moderator, beast, member, trialmember } = require('../options.json');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'update',
|
||||||
|
description: 'Update your guild rank.',
|
||||||
|
type: 'slash',
|
||||||
|
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('update')
|
||||||
|
.setDescription('Update your guild rank.')
|
||||||
|
.addStringOption(option =>
|
||||||
|
option
|
||||||
|
.setName('user')
|
||||||
|
.setDescription('The user you want to update.'))
|
||||||
|
.setDMPermission(false),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
|
||||||
|
const verifyData = await verify.findOne({ userID: user.id })
|
||||||
|
const memberRoles = interaction.member.roles.cache;
|
||||||
|
const roleManage = interaction.member.roles;
|
||||||
|
|
||||||
|
if (!verifyData) {
|
||||||
|
interaction.reply('You are not verified.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interaction.options.getUser('user') && !memberRoles.has(moderator || manager || gm)) {
|
||||||
|
await interaction.reply({ content: "Only moderators can update other users", ephemeral: true })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = interaction.options.getUser('user') ?? interaction.user;
|
||||||
|
|
||||||
|
|
||||||
|
const slothPixel = "https://api.slothpixel.me/api/players/";
|
||||||
|
const guildAPI = "https://api.slothpixel.me/api/guilds/"
|
||||||
|
const mojangAPI = "https://api.mojang.com/user/profile/"
|
||||||
|
const minotar = "https://minotar.net/helm/";
|
||||||
|
|
||||||
|
const userCheck = await fetch(mojangAPI + verifyData.uuid);
|
||||||
|
const hypixelCheck = await fetch(slothPixel + verifyData.uuid);
|
||||||
|
const guildCheck = await fetch(guildAPI + verifyData.uuid);
|
||||||
|
const head = minotar + hypixelCheck.data.username;
|
||||||
|
|
||||||
|
const embedColor = Number(color.replace("#", "0x"));
|
||||||
|
const GuildMembers = await guildCheck.data.members;
|
||||||
|
const guildRank = GuildMembers.find(member => member.uuid === verifyData.uuid).rank;
|
||||||
|
|
||||||
|
if (guildRank === 'Guild Master') {
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
description: "You are the Guild Master. Due to security reasons, you cannot update your rank.",
|
||||||
|
color: embedColor,
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild.name + " | Developed by @Taken#0002",
|
||||||
|
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === 'Manager') {
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
description: "You are a Manager. Due to security reasons, you cannot update your rank.",
|
||||||
|
color: embedColor,
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild.name + " | Developed by @Taken#0002",
|
||||||
|
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === 'Moderator') {
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
description: "You are a Moderator. Due to security reasons, you cannot update your rank.",
|
||||||
|
color: embedColor,
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild.name + " | Developed by @Taken#0002",
|
||||||
|
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === 'Beast') {
|
||||||
|
await roleManage.add(beast)
|
||||||
|
await roleManage.remove(gm || manager || moderator || member || trialmember)
|
||||||
|
|
||||||
|
await verify.findOneAndUpdate({ userID: user.id }, { rank: guildRank })
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
description: "Your rank has been updated to `Beast`.",
|
||||||
|
color: embedColor,
|
||||||
|
thumbnail: {
|
||||||
|
url: head
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild.name + " | Developed by @Taken#0002",
|
||||||
|
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === 'Member') {
|
||||||
|
await roleManage.add(member)
|
||||||
|
await roleManage.remove(gm || manager || moderator || beast || trialmember)
|
||||||
|
|
||||||
|
await verify.findOneAndUpdate({ userID: user.id }, { rank: guildRank })
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
description: "Your rank has been updated to `Member`.",
|
||||||
|
color: embedColor,
|
||||||
|
thumbnail: {
|
||||||
|
url: head
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild.name + " | Developed by @Taken#0002",
|
||||||
|
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === 'Trial Member') {
|
||||||
|
await roleManage.add(trialmember)
|
||||||
|
await roleManage.remove(gm || manager || moderator || beast || member)
|
||||||
|
|
||||||
|
await verify.findOneAndUpdate({ userID: user.id }, { rank: guildRank })
|
||||||
|
interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
description: "Your rank has been updated to `Trial Member`.",
|
||||||
|
color: embedColor,
|
||||||
|
thumbnail: {
|
||||||
|
url: head
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild.name + " | Developed by @Taken#0002",
|
||||||
|
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
118
commands/verify.js
Normal file
118
commands/verify.js
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
|
const { hypixelApiKey } = require('../config.json');
|
||||||
|
const fetch = require('axios');
|
||||||
|
const { color } = require('../options.json');
|
||||||
|
const verify = require('../schemas/verifySchema.js')
|
||||||
|
const mongoose = require('mongoose');
|
||||||
|
const { gm, manager, moderator, beast, member, trialmember } = require('../options.json');
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
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),
|
||||||
|
|
||||||
|
async execute(interaction) {
|
||||||
|
|
||||||
|
const user = interaction.user;
|
||||||
|
const fullUsername = user.username + "#" + 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 userCheck = await fetch(mojang + ign);
|
||||||
|
const hypixelCheck = await fetch(slothPixel + ign);
|
||||||
|
const guildCheck = await fetch(guildAPI + ign);
|
||||||
|
const head = minotar + ign;
|
||||||
|
|
||||||
|
const GuildMembers = await guildCheck.data.members;
|
||||||
|
|
||||||
|
const guildRank = GuildMembers.find(member => member.uuid === hypixelCheck.data.uuid).rank;
|
||||||
|
|
||||||
|
if (!ign) {
|
||||||
|
interaction.reply('Please provide a player\'s IGN.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!userCheck.data.id) {
|
||||||
|
interaction.reply('That player doesn\'t exist. [Mojang]')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hypixelCheck.data.uuid) {
|
||||||
|
interaction.reply('That player doesn\'t exist. [Hypixel]')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildCheck.data.id !== "5a353a170cf2e529044f2935") {
|
||||||
|
interaction.reply('You are not a member of the guild.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hypixelCheck.data.links.DISCORD !== fullUsername) {
|
||||||
|
interaction.reply('Your Discord tag does not match your in-game tag.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const verifyData = await verify.findOne({ userID: user.id })
|
||||||
|
|
||||||
|
if (verifyData) {
|
||||||
|
interaction.reply('You are already verified.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === "Guild Master") {
|
||||||
|
await user.roles.add(gm);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === "Manager") {
|
||||||
|
await user.roles.add(manager);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === "Moderator") {
|
||||||
|
await user.roles.add(moderator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === "Beast") {
|
||||||
|
await user.roles.add(beast);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === "Member") {
|
||||||
|
await user.roles.add(member);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (guildRank === "Trial Member") {
|
||||||
|
await user.roles.add(trialmember);
|
||||||
|
}
|
||||||
|
|
||||||
|
// write to database using verifySchema
|
||||||
|
const newVerify = new verify({
|
||||||
|
_id: new mongoose.Types.ObjectId(),
|
||||||
|
userID: user.id,
|
||||||
|
uuid: hypixelCheck.data.uuid,
|
||||||
|
rank: guildRank
|
||||||
|
})
|
||||||
|
await newVerify.save()
|
||||||
|
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [{
|
||||||
|
title: interaction.guild.name,
|
||||||
|
description: "You have successfully verified `" + fullUsername + "` with the account `" + hypixelCheck.data.username + "`.",
|
||||||
|
color: embedColor,
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
{
|
{
|
||||||
"color": "#eeaadb"
|
"color": "#eeaadb",
|
||||||
|
"gm": "",
|
||||||
|
"manager": "",
|
||||||
|
"moderator": "",
|
||||||
|
"beast": "",
|
||||||
|
"member": "",
|
||||||
|
"trialmember": ""
|
||||||
}
|
}
|
||||||
10
schemas/verifySchema.js
Normal file
10
schemas/verifySchema.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
const { Schema, model } = require('mongoose');
|
||||||
|
|
||||||
|
const verifySchema = new Schema({
|
||||||
|
_id: Schema.Types.ObjectId,
|
||||||
|
userID: { type: String, required: true },
|
||||||
|
uuid: { type: String, required: true },
|
||||||
|
rank: { type: String, required: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = model('verify', verifySchema, 'verify');
|
||||||
Reference in New Issue
Block a user