Added new functions
This commit is contained in:
@@ -1,24 +1,15 @@
|
|||||||
const { guildLevel } = require("../../utils/utils.js");
|
const { guildLevel, getUUID, getIGN, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js");
|
||||||
const { color } = require("../../config/options.json");
|
const { color } = require("../../config/options.json");
|
||||||
const apikey = process.env.HYPIXELAPIKEY;
|
|
||||||
const fetch = require("axios");
|
|
||||||
|
|
||||||
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
||||||
|
|
||||||
async function guildMember(interaction) {
|
async function guildMember(interaction) {
|
||||||
const ign = interaction.options.getString("ign");
|
const ign = interaction.options.getString("ign");
|
||||||
|
|
||||||
const embedColor = Number(color.replace("#", "0x"));
|
const embedColor = Number(color.replace("#", "0x"));
|
||||||
const mojang = "https://api.mojang.com/users/profiles/minecraft/";
|
|
||||||
const hypixel = "https://api.hypixel.net/player";
|
|
||||||
const guild = "https://api.hypixel.net/guild";
|
|
||||||
const minotar = "https://minotar.net/helm/";
|
|
||||||
|
|
||||||
try {
|
const uuid = await getUUID(ign);
|
||||||
const mojangReq = await fetch(mojang + ign);
|
if (!uuid) {
|
||||||
var uuid = mojangReq.data.id;
|
interaction.editReply({
|
||||||
} catch (err) {
|
|
||||||
return interaction.editReply({
|
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
description: "This user does not exist",
|
description: "This user does not exist",
|
||||||
@@ -32,15 +23,8 @@ async function guildMember(interaction) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const head = minotar + ign;
|
const player = await getPlayer(uuid);
|
||||||
const player = await fetch(hypixel, {
|
if (!player) {
|
||||||
params: {
|
|
||||||
key: apikey,
|
|
||||||
uuid: uuid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!player.data.player) {
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
@@ -74,14 +58,8 @@ async function guildMember(interaction) {
|
|||||||
var rank = "[MVP++] ";
|
var rank = "[MVP++] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
const guildCheck = await fetch(guild, {
|
const guild = await getGuild(uuid);
|
||||||
params: {
|
if (!guild) {
|
||||||
key: apikey,
|
|
||||||
player: uuid,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!guildCheck.data.guild) {
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
@@ -99,34 +77,10 @@ async function guildMember(interaction) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const guildCreationMS = guildCheck.data.guild.created;
|
const guildName = guild.name;
|
||||||
const guildCreationTime = new Date(guildCreationMS);
|
const guildTag = " [" + guild.tag + "]" ?? "";
|
||||||
const guildCreationDate = guildCreationTime.getDate();
|
|
||||||
const guildCreationMonth = guildCreationTime.getMonth() + 1;
|
|
||||||
const guildCreationYear = guildCreationTime.getFullYear();
|
|
||||||
const guildCreationHours = guildCreationTime.getHours();
|
|
||||||
const guildCreationMinutes = guildCreationTime.getMinutes();
|
|
||||||
const guildCreationSeconds = guildCreationTime.getSeconds();
|
|
||||||
|
|
||||||
const guildCreation =
|
const guildMembers = guild.members;
|
||||||
guildCreationDate +
|
|
||||||
"." +
|
|
||||||
guildCreationMonth +
|
|
||||||
"." +
|
|
||||||
guildCreationYear +
|
|
||||||
" " +
|
|
||||||
guildCreationHours +
|
|
||||||
":" +
|
|
||||||
guildCreationMinutes +
|
|
||||||
":" +
|
|
||||||
guildCreationSeconds;
|
|
||||||
|
|
||||||
const guildName = guildCheck.data.guild.name;
|
|
||||||
const guildTag = " [" + guildCheck.data.guild.tag + "]" ?? "";
|
|
||||||
const guildExp = guildCheck.data.guild.exp;
|
|
||||||
const guildLvl = guildLevel(guildExp);
|
|
||||||
|
|
||||||
const guildMembers = guildCheck.data.guild.members;
|
|
||||||
const guildMember = guildMembers.find((member) => member.uuid === uuid);
|
const guildMember = guildMembers.find((member) => member.uuid === uuid);
|
||||||
const guildRank = guildMember.rank;
|
const guildRank = guildMember.rank;
|
||||||
const memberGexp = guildMember.expHistory;
|
const memberGexp = guildMember.expHistory;
|
||||||
|
|||||||
67
utils/functions/account.js
Normal file
67
utils/functions/account.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
const fetch = require('axios')
|
||||||
|
const apikey = process.env.HYPIXELAPIKEY
|
||||||
|
const mojang = 'https://api.mojang.com/users/profiles/minecraft/'
|
||||||
|
const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/"
|
||||||
|
const hypixel = 'https://api.hypixel.net/player'
|
||||||
|
const guild = 'https://api.hypixel.net/guild'
|
||||||
|
const minotar = 'https://minotar.net/helm/'
|
||||||
|
|
||||||
|
async function getUUID(ign) {
|
||||||
|
try {
|
||||||
|
const req = await fetch(mojang + ign)
|
||||||
|
return req.data.id
|
||||||
|
} catch (err) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getIGN(uuid) {
|
||||||
|
try {
|
||||||
|
const req = await fetch(mojanguuid + uuid)
|
||||||
|
return req.data.name
|
||||||
|
} catch (err) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getPlayer(uuid) {
|
||||||
|
const playerReq = await fetch(hypixel, {
|
||||||
|
params: {
|
||||||
|
key: apikey,
|
||||||
|
uuid: uuid
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!playerReq.data.player) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return playerReq.data.player
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getGuild(uuid) {
|
||||||
|
const guildReq = await fetch(guild, {
|
||||||
|
params: {
|
||||||
|
key: apikey,
|
||||||
|
player: uuid
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!guildReq.data.guild) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return guildReq.data.guild
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getHeadURL(ign) {
|
||||||
|
return minotar + ign
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getUUID,
|
||||||
|
getIGN,
|
||||||
|
getPlayer,
|
||||||
|
getGuild,
|
||||||
|
getHeadURL
|
||||||
|
}
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
|
||||||
*/
|
|
||||||
function getLevel(exp) {
|
|
||||||
const EXP_NEEDED = [
|
|
||||||
100000,
|
|
||||||
150000,
|
|
||||||
250000,
|
|
||||||
500000,
|
|
||||||
750000,
|
|
||||||
1000000,
|
|
||||||
1250000,
|
|
||||||
1500000,
|
|
||||||
2000000,
|
|
||||||
2500000,
|
|
||||||
2500000,
|
|
||||||
2500000,
|
|
||||||
2500000,
|
|
||||||
2500000,
|
|
||||||
3000000,
|
|
||||||
];
|
|
||||||
|
|
||||||
let level = 0;
|
|
||||||
|
|
||||||
// Increments by one from zero to the level cap
|
|
||||||
for (let i = 0; i <= 1000; i += 1) {
|
|
||||||
// need is the required exp to get to the next level
|
|
||||||
let need = 0;
|
|
||||||
if (i >= EXP_NEEDED.length) {
|
|
||||||
need = EXP_NEEDED[EXP_NEEDED.length - 1];
|
|
||||||
} else { need = EXP_NEEDED[i]; }
|
|
||||||
|
|
||||||
// If the required exp to get to the next level isn't met returns
|
|
||||||
// the current level plus progress towards the next (unused exp/need)
|
|
||||||
// Otherwise increments the level and substracts the used exp from exp var
|
|
||||||
if ((exp - need) < 0) {
|
|
||||||
return Math.round((level + (exp / need)) * 100) / 100;
|
|
||||||
}
|
|
||||||
level += 1;
|
|
||||||
exp -= need;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Returns the level cap - currently 1000
|
|
||||||
// If changed here, also change in for loop above
|
|
||||||
return 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = { getLevel }
|
|
||||||
@@ -44,5 +44,13 @@ function guildLevel(exp) {
|
|||||||
// If changed here, also change in for loop above
|
// If changed here, also change in for loop above
|
||||||
return 1000;
|
return 1000;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Code used from the hypixel-guild-bot project https://github.com/SimplyNo/hypixel-guild-bot
|
||||||
|
*/
|
||||||
|
function scaledGEXP(input) {
|
||||||
|
if (input <= 200000) return Number(input);
|
||||||
|
if (input <= 700000) return Number(Math.round(((input - 200000) / 10) + 200000));
|
||||||
|
if (input > 700000) return Number(Math.round(((input - 700000) / 33) + 250000));
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = { guildLevel }
|
module.exports = { guildLevel, scaledGEXP }
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
const { skywarsLevel } = require('./functions/skywars.js')
|
const { skywarsLevel } = require('./functions/skywars.js')
|
||||||
const { bedwarsLevel } = require('./functions/bedwars.js')
|
const { bedwarsLevel } = require('./functions/bedwars.js')
|
||||||
const { hypixelLevel } = require('./functions/hypixel.js')
|
const { hypixelLevel } = require('./functions/hypixel.js')
|
||||||
const { guildLevel } = require('./functions/guild.js')
|
const { guildLevel, scaledGEXP } = require('./functions/guild.js')
|
||||||
|
const { getUUID, getIGN, getPlayer, getGuild, getHeadURL } = require('./functions/account.js')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
skywarsLevel,
|
skywarsLevel,
|
||||||
bedwarsLevel,
|
bedwarsLevel,
|
||||||
hypixelLevel,
|
hypixelLevel,
|
||||||
guildLevel
|
guildLevel,
|
||||||
|
scaledGEXP,
|
||||||
|
getUUID,
|
||||||
|
getIGN,
|
||||||
|
getPlayer,
|
||||||
|
getGuild,
|
||||||
|
getHeadURL
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user