Merge branch 'dev' into 'main'

Dev

See merge request illegitimate/illegitimate-bot!54
This commit is contained in:
2023-11-16 22:44:58 +00:00
10 changed files with 289 additions and 222 deletions

View File

@@ -1,9 +1,7 @@
const { SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits } = require("discord.js");
const { SlashCommandBuilder } = require("discord.js");
const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require("../config/reqs.json");
const hypixelApiKey = process.env.HYPIXELAPIKEY;
const { color } = require("../config/options.json");
const fetch = require("axios");
const { hypixelLevel, bedwarsLevel, skywarsLevel } = require("../utils/utils.js");
const { hypixelLevel, bedwarsLevel, skywarsLevel, getUUID, getPlayer, getGuild, getHeadURL } = require("../utils/utils.js");
module.exports = {
name: "check",
@@ -25,21 +23,15 @@ module.exports = {
await interaction.deferReply({});
const ign = interaction.options.getString("ign");
const mojang = "https://api.mojang.com/users/profiles/minecraft/";
const hypixel = "https://api.hypixel.net/player"
const guildAPI = "https://api.hypixel.net/guild"
const minotar = "https://minotar.net/helm/";
const embedColor = Number(color.replace("#", "0x"));
const head = minotar + ign;
if (!ign) {
await interaction.editReply("Please provide a player's IGN.");
return;
}
try {
var userCheck = await fetch(mojang + ign);
} catch (error) {
const uuid = await getUUID(ign);
if (!uuid) {
interaction.editReply({
embeds: [
{ description: "That player doesn't exist.", color: embedColor }
@@ -48,12 +40,9 @@ module.exports = {
return;
}
const uuid = userCheck.data.id;
const player = hypixel + "?key=" + hypixelApiKey + "&uuid=" + uuid
const stats = await fetch(player);
if (!stats.data.player) {
const head = await getHeadURL(ign);
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
embeds: [{
description: "That player hasn't played Hypixel before.",
@@ -63,8 +52,8 @@ module.exports = {
return;
}
const rank2 = stats.data.player.newPackageRank;
const monthlyRank = stats.data.player.monthlyPackageRank;
const rank2 = player.newPackageRank;
const monthlyRank = player.monthlyPackageRank;
if (rank2 === 'VIP') {
var rank = "[VIP] "
@@ -78,52 +67,50 @@ module.exports = {
var rank = "[MVP++] "
}
const guild = guildAPI + "?key=" + hypixelApiKey + "&player=" + uuid
const guildCheck = await fetch(guild);
if (!guildCheck.data.guild) {
const guild = await getGuild(uuid)
if (!guild) {
var guildName = "None";
} else {
var guildName = guildCheck.data.guild.name;
var guildName = guild.name;
}
if (!guildCheck.data.guild) {
if (!guild) {
var guildTag = ""
} else if (!guildCheck.data.guild.tag) {
} else if (!guild.tag) {
var guildTag = ""
} else {
var guildTag = " [" + guildCheck.data.guild.tag + "]"
var guildTag = " [" + guild.tag + "]"
}
//bedwars level
const hsbwexp = stats.data.player.stats.Bedwars.Experience;
const hsbwexp = player.stats.Bedwars.Experience;
const hsbwstars = bedwarsLevel(hsbwexp);
// bedwars fkdr
const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars;
const hsbwfk = player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = player.stats.Bedwars.final_deaths_bedwars;
const hsbwfkdr = hsbwfk / hsbwfd;
// bedwars wins
const hsbwwins = stats.data.player.stats.Bedwars.wins_bedwars;
const hsbwwins = player.stats.Bedwars.wins_bedwars;
// skywars level
const hsswexp = stats.data.player.stats.SkyWars.skywars_experience;
const hsswexp = player.stats.SkyWars.skywars_experience;
const hsswstars = skywarsLevel(hsswexp);
// skywars kdr
const hsswkills = stats.data.player.stats.SkyWars.kills;
const hsswdeaths = stats.data.player.stats.SkyWars.deaths;
const hsswkills = player.stats.SkyWars.kills;
const hsswdeaths = player.stats.SkyWars.deaths;
const hsswkd = hsswkills / hsswdeaths;
//skywars wins
const hsswwins = stats.data.player.stats.SkyWars.wins;
const hsswwins = player.stats.SkyWars.wins;
// dueks kdr
const hsduelskills = stats.data.player.stats.Duels.kills
const hsduelsdeaths = stats.data.player.stats.Duels.deaths
const hsduelskills = player.stats.Duels.kills
const hsduelsdeaths = player.stats.Duels.deaths
const hsduelskd = hsduelskills / hsduelsdeaths
// duels wins
const hsduelswins = stats.data.player.stats.Duels.wins;
const hsduelswins = player.stats.Duels.wins;
// duels wlr
const hsduelslosses = stats.data.player.stats.Duels.losses;
const hsduelslosses = player.stats.Duels.losses;
const hsduelswlr = hsduelswins / hsduelslosses;
// network level
const hypixelExp = stats.data.player.networkExp;
const hypixelExp = player.networkExp;
const level = hypixelLevel(hypixelExp);
if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) {
@@ -152,12 +139,14 @@ module.exports = {
await interaction.editReply({
embeds: [{
title: rank + stats.data.player.displayname + guildTag,
title: rank + player.displayname + guildTag,
description: "**Network Level:** `" +
level.toFixed(2).toString() + "`\n" +
"**Current Guild:** `" + guildName + "`",
color: embedColor,
thumbnail: { url: head },
thumbnail: {
url: head
},
footer: {
text: interaction.guild.name + " | Developed by @Taken#0002",
icon_url: interaction.guild.iconURL()

View File

@@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require('discord.js')
const { color } = require('../config/options.json')
const { guildMember } = require('./guild/member.js')
const { guildInfo } = require('./guild/info.js')
module.exports = {
name: 'guild',
@@ -21,6 +22,17 @@ module.exports = {
.setRequired(true)
)
)
.addSubcommand(subcommand =>
subcommand
.setName('info')
.setDescription('Get info about a guild.')
.addStringOption(option =>
option
.setName('ign')
.setDescription('The IGN of a member.')
.setRequired(true)
)
)
.setDMPermission(false),
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
@@ -37,6 +49,11 @@ module.exports = {
return
}
if (subcommand === 'info') {
await guildInfo(interaction)
return
}
await interaction.editReply({
embeds: [{
description: "This command is currently under development",

103
commands/guild/info.js Normal file
View File

@@ -0,0 +1,103 @@
const { getUUID, getIGN, getPlayer, getGuild, guildLevel } = require("../../utils/utils.js")
const { color } = require("../../config/options.json");
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
async function guildInfo(interaction) {
const ign = interaction.options.getString("ign");
const embedColor = Number(color.replace("#", "0x"));
const uuid = await getUUID(ign)
if (!uuid) {
interaction.editReply({
embeds: [{
description: "That player doen't exist!",
color: embedColor
}]
})
return
}
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
embeds: [{
description: "That player has never joined the server!",
color: embedColor
}]
})
return
}
const guild = await getGuild(uuid)
if (!guild) {
interaction.editReply({
embeds: [{
description: "That player is not in a guild!",
color: embedColor
}]
})
return
}
const guildName = guild.name;
const guildCreatedMS = guild.created;
const guildCreated = new Date(guildCreatedMS);
const guildTag = guild.tag;
const guildExp = guild.exp;
const guildLvl = guildLevel(guildExp);
const guildMembers = guild.members
const guildCreatedDate = guildCreated.getDate()
const guildCreatedMonth = guildCreated.getMonth() + 1
const guildCreatedYear = guildCreated.getFullYear()
const guildCreatedHour = guildCreated.getHours()
const guildCreatedMinute = guildCreated.getMinutes()
const guildCreatedSecond = guildCreated.getSeconds()
const guildCreatedTime = guildCreatedDate + "." +
guildCreatedMonth + "." +
guildCreatedYear + " " +
guildCreatedHour + ":" +
guildCreatedMinute + ":" +
guildCreatedSecond
const guildOwner = guildMembers.find((m) => m.rank === "Guild Master").uuid
const guildOwnerName = await getIGN(guildOwner)
const guildRanks = guild.ranks.map((r) => "**➺ " + r.name + "** `[" + r.tag + "]`").join("\n")
const guildMembersDailyXP = Object.values(guildMembers).map((m) => m.expHistory[Object.keys(m.expHistory)[0]])
const totalGuildMembersDailyXP = guildMembersDailyXP.reduce((a, b) => a + b, 0)
await interaction.editReply({
embeds: [{
title: "**Info on** " + guildName,
description: "**Guild Name: **`" + guildName + "`\n" +
"**Guild Tag: **`" + guildTag + "`\n" +
"**Guild Level: **`" + guildLvl + "`\n" +
"**Guild Owner: **`" + guildOwnerName + "`",
fields: [
{
name: "**Guild Ranks**",
value: guildRanks
},
{
name: "**GEXP**",
value: "**➺ Total weekly GEXP:** `" + totalGuildMembersDailyXP + "`"
},
{
name: "**Guild Created**",
value: "**➺ **`" + guildCreatedTime + "`"
}
],
color: embedColor,
footer: {
text: interaction.guild.name + " | Developed by taken.lua",
icon_url: interaction.guild.iconURL({ dynamic: true })
}
}]
})
}
module.exports = { guildInfo }

View File

@@ -1,24 +1,15 @@
const { guildLevel } = require("../../utils/utils.js");
const { getUUID, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js");
const { color } = require("../../config/options.json");
const apikey = process.env.HYPIXELAPIKEY;
const fetch = require("axios");
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
async function guildMember(interaction) {
const ign = interaction.options.getString("ign");
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 mojangReq = await fetch(mojang + ign);
var uuid = mojangReq.data.id;
} catch (err) {
return interaction.editReply({
const uuid = await getUUID(ign);
if (!uuid) {
interaction.editReply({
embeds: [
{
description: "This user does not exist",
@@ -32,15 +23,9 @@ async function guildMember(interaction) {
});
}
const head = minotar + ign;
const player = await fetch(hypixel, {
params: {
key: apikey,
uuid: uuid,
},
});
if (!player.data.player) {
const head = await getHeadURL(ign);
const player = await getPlayer(uuid);
if (!player) {
await interaction.editReply({
embeds: [
{
@@ -58,9 +43,9 @@ async function guildMember(interaction) {
});
}
const serverRank = player.data.player.newPackageRank;
const monthlyRank = player.data.player.monthlyPackageRank;
const displayName = player.data.player.displayname;
const serverRank = player.newPackageRank;
const monthlyRank = player.monthlyPackageRank;
const displayName = player.displayname;
if (serverRank === "VIP") {
var rank = "[VIP] ";
@@ -74,14 +59,8 @@ async function guildMember(interaction) {
var rank = "[MVP++] ";
}
const guildCheck = await fetch(guild, {
params: {
key: apikey,
player: uuid,
},
});
if (!guildCheck.data.guild) {
const guild = await getGuild(uuid);
if (!guild) {
await interaction.editReply({
embeds: [
{
@@ -99,34 +78,10 @@ async function guildMember(interaction) {
});
}
const guildCreationMS = guildCheck.data.guild.created;
const guildCreationTime = new Date(guildCreationMS);
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 guildName = guild.name;
const guildTag = " [" + guild.tag + "]" ?? "";
const guildCreation =
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 guildMembers = guild.members;
const guildMember = guildMembers.find((member) => member.uuid === uuid);
const guildRank = guildMember.rank;
const memberGexp = guildMember.expHistory;
@@ -147,29 +102,19 @@ async function guildMember(interaction) {
const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds();
const guildMemberJoin =
guildMemberJoinDate +
"." +
guildMemberJoinMonth +
"." +
guildMemberJoinYear +
" " +
guildMemberJoinHours +
":" +
guildMemberJoinMinutes +
":" +
guildMemberJoinDate + "." +
guildMemberJoinMonth + "." +
guildMemberJoinYear + " " +
guildMemberJoinHours + ":" +
guildMemberJoinMinutes + ":" +
guildMemberJoinSeconds;
await interaction.editReply({
embeds: [
{
title: rank + displayName + guildTag,
description:
"**Guild Name:** `" +
guildName +
"`\n" +
"**Guild Rank:** `" +
guildRank +
"`\n",
description: "**Guild Name:** `" + guildName + "`\n" +
"**Guild Rank:** `" + guildRank + "`\n",
color: embedColor,
thumbnail: {
url: head,
@@ -181,13 +126,8 @@ async function guildMember(interaction) {
},
{
name: "**Weekly GEXP**",
value:
"**➺ Total:** `" +
totalWeeklyGexp +
"`\n" +
"**➺ Daily avarage:** `" +
averageWeeklyGexp +
"`",
value: "**➺ Total:** `" + totalWeeklyGexp + "`\n" +
"**➺ Daily avarage:** `" + averageWeeklyGexp + "`",
},
{
name: "**Join date**",

View File

@@ -1,9 +1,7 @@
const { color } = require('../../config/options.json');
const fetch = require('axios');
const guildapp = require('../../schemas/guildAppSchema.js');
const { bwfkdr, bwstars, bwwins, swstars, duelswins, duelswlr } = require('../../config/reqs.json');
const hypixelApiKey = process.env.HYPIXELAPIKEY;
const { hypixelLevel, bedwarsLevel, skywarsLevel } = require("../../utils/utils.js");
const { hypixelLevel, bedwarsLevel, skywarsLevel, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js");
module.exports = {
name: 'checkstats',
@@ -19,24 +17,12 @@ module.exports = {
const message = interaction.message;
const embed = message.embeds[0];
const applicantId = embed.footer.text.split(" ")[1]
const guildappdata = await guildapp.findOne({ userID: applicantId })
const uuid = guildappdata.uuid;
const mojang = "https://api.mojang.com/user/profile/"
const hypixel = "https://api.hypixel.net/player"
const guildAPI = "https://api.hypixel.net/guild"
const minotar = "https://minotar.net/helm/";
const embedColor = Number(color.replace("#", "0x"));
const userCheck = await fetch(mojang + uuid);
const ign = userCheck.data.name;
const head = minotar + ign;
const player = hypixel + "?key=" + hypixelApiKey + "&uuid=" + uuid
const stats = await fetch(player);
if (!stats.data.player) {
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
embeds: [{
description: "That player hasn't played Hypixel before.",
@@ -46,8 +32,10 @@ module.exports = {
return;
}
const rank2 = stats.data.player.newPackageRank;
const monthlyRank = stats.data.player.monthlyPackageRank;
const ign = player.playername
const head = await getHeadURL(ign)
const rank2 = player.newPackageRank;
const monthlyRank = player.monthlyPackageRank;
if (rank2 === 'VIP') {
var rank = "[VIP] "
@@ -61,52 +49,50 @@ module.exports = {
var rank = "[MVP++] "
}
const guild = guildAPI + "?key=" + hypixelApiKey + "&player=" + uuid
const guildCheck = await fetch(guild);
if (!guildCheck.data.guild) {
const guild = await getGuild(uuid)
if (!guild) {
var guildName = "None";
} else {
var guildName = guildCheck.data.guild.name;
var guildName = guild.name;
}
if (!guildCheck.data.guild) {
if (!guild) {
var guildTag = ""
} else if (!guildCheck.data.guild.tag) {
} else if (!guild.tag) {
var guildTag = ""
} else {
var guildTag = " [" + guildCheck.data.guild.tag + "]"
var guildTag = " [" + guild.tag + "]"
}
//bedwars level
const hsbwexp = stats.data.player.stats.Bedwars.Experience;
const hsbwexp = player.stats.Bedwars.Experience;
const hsbwstars = bedwarsLevel(hsbwexp);
// bedwars fkdr
const hsbwfk = stats.data.player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = stats.data.player.stats.Bedwars.final_deaths_bedwars;
const hsbwfk = player.stats.Bedwars.final_kills_bedwars;
const hsbwfd = player.stats.Bedwars.final_deaths_bedwars;
const hsbwfkdr = hsbwfk / hsbwfd;
// bedwars wins
const hsbwwins = stats.data.player.stats.Bedwars.wins_bedwars;
const hsbwwins = player.stats.Bedwars.wins_bedwars;
// skywars level
const hsswexp = stats.data.player.stats.SkyWars.skywars_experience;
const hsswexp = player.stats.SkyWars.skywars_experience;
const hsswstars = skywarsLevel(hsswexp);
// skywars kdr
const hsswkills = stats.data.player.stats.SkyWars.kills;
const hsswdeaths = stats.data.player.stats.SkyWars.deaths;
const hsswkills = player.stats.SkyWars.kills;
const hsswdeaths = player.stats.SkyWars.deaths;
const hsswkd = hsswkills / hsswdeaths;
//skywars wins
const hsswwins = stats.data.player.stats.SkyWars.wins;
const hsswwins = player.stats.SkyWars.wins;
// dueks kdr
const hsduelskills = stats.data.player.stats.Duels.kills
const hsduelsdeaths = stats.data.player.stats.Duels.deaths
const hsduelskills = player.stats.Duels.kills
const hsduelsdeaths = player.stats.Duels.deaths
const hsduelskd = hsduelskills / hsduelsdeaths
// duels wins
const hsduelswins = stats.data.player.stats.Duels.wins;
const hsduelswins = player.stats.Duels.wins;
// duels wlr
const hsduelslosses = stats.data.player.stats.Duels.losses;
const hsduelslosses = player.stats.Duels.losses;
const hsduelswlr = hsduelswins / hsduelslosses;
// network level
const hypixelExp = stats.data.player.networkExp;
const hypixelExp = player.networkExp;
const level = hypixelLevel(hypixelExp);
if (hsbwstars < bwstars || hsbwfkdr < bwfkdr || hsbwwins < bwwins) {
@@ -129,7 +115,7 @@ module.exports = {
await interaction.editReply({
embeds: [{
title: rank + stats.data.player.displayname + guildTag,
title: rank + player.displayname + guildTag,
description: "**Network Level:** `" +
level.toFixed(2).toString() + "`\n" +
"**Current Guild:** `" + guildName + "`",

View File

@@ -69,9 +69,7 @@ module.exports = {
.setDescription("The application has been denied by <@" + interaction.user.id + ">.\n" +
"**Reason:** `" + reason + "`")
.setColor(embedColor)
.setThumbnail({
url: applicant.avatarURL() ?? guild.iconURL()
})
.setThumbnail(guild.iconURL())
.setFooter({
iconURL: guild.iconURL(),
text: "ID: " + applicant.id

View 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
}

View File

@@ -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 }

View File

@@ -44,5 +44,13 @@ function guildLevel(exp) {
// If changed here, also change in for loop above
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 }

View File

@@ -1,11 +1,18 @@
const { skywarsLevel } = require('./functions/skywars.js')
const { bedwarsLevel } = require('./functions/bedwars.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 = {
skywarsLevel,
bedwarsLevel,
hypixelLevel,
guildLevel
guildLevel,
scaledGEXP,
getUUID,
getIGN,
getPlayer,
getGuild,
getHeadURL
}