Merge branch 'dev' into 'main'
Added guild member command and added credits to other code See merge request illegitimate/illegitimate-bot!51
This commit is contained in:
198
commands/guild.js
Normal file
198
commands/guild.js
Normal file
@@ -0,0 +1,198 @@
|
||||
const { SlashCommandBuilder } = require('discord.js')
|
||||
const { guildLevel } = require('../utils/utils.js')
|
||||
const { color } = require('../config/options.json')
|
||||
const apikey = process.env.HYPIXELAPIKEY
|
||||
const fetch = require('axios')
|
||||
|
||||
module.exports = {
|
||||
name: 'guild',
|
||||
description: 'Subcommands for guilds',
|
||||
type: 'slash',
|
||||
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('guild')
|
||||
.setDescription('Subcommands for guilds')
|
||||
.addSubcommand(subcommand =>
|
||||
subcommand
|
||||
.setName('member')
|
||||
.setDescription('Get info about a guild memeber')
|
||||
.addStringOption(option =>
|
||||
option
|
||||
.setName('ign')
|
||||
.setDescription('The IGN of the player.')
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.setDMPermission(false),
|
||||
|
||||
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
||||
|
||||
async execute(interaction) {
|
||||
|
||||
await interaction.deferReply()
|
||||
|
||||
const subcommand = interaction.options.getSubcommand()
|
||||
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"
|
||||
|
||||
if (subcommand === "member") {
|
||||
|
||||
const ign = interaction.options.getString('ign')
|
||||
|
||||
try {
|
||||
const mojangReq = await fetch(mojang + ign)
|
||||
var uuid = mojangReq.data.id
|
||||
} catch (err) {
|
||||
return interaction.editReply({
|
||||
embeds: [{
|
||||
description: "This user does not exist",
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: interaction.guild.name + " | Developed by taken.lua",
|
||||
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
const player = await fetch(hypixel, {
|
||||
params: {
|
||||
key: apikey,
|
||||
uuid: uuid
|
||||
}
|
||||
})
|
||||
|
||||
if (!player.data.player) {
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: "This user does not exist",
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: interaction.guild.name + " | Developed by taken.lua",
|
||||
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
const serverRank = player.data.player.newPackageRank
|
||||
const monthlyRank = player.data.player.monthlyPackageRank
|
||||
const displayName = player.data.player.displayname
|
||||
|
||||
if (serverRank === 'VIP') {
|
||||
var rank = "[VIP] "
|
||||
} else if (serverRank === 'VIP_PLUS') {
|
||||
var rank = "[VIP+] "
|
||||
} else if (serverRank === 'MVP') {
|
||||
var rank = "[MVP] "
|
||||
} else if (serverRank === 'MVP_PLUS' && monthlyRank === 'NONE') {
|
||||
var rank = "[MVP+] "
|
||||
} else if (serverRank === 'MVP_PLUS' && monthlyRank === 'SUPERSTAR') {
|
||||
var rank = "[MVP++] "
|
||||
}
|
||||
|
||||
const guildCheck = await fetch(guild, {
|
||||
params: {
|
||||
key: apikey,
|
||||
player: uuid
|
||||
}
|
||||
})
|
||||
|
||||
if (!guildCheck.data.guild) {
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: "This user is not in a guild",
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: interaction.guild.name + " | Developed by taken.lua",
|
||||
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
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 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 guildMember = guildMembers.find(member => member.uuid === uuid)
|
||||
const guildRank = guildMember.rank
|
||||
const memberGexp = guildMember.expHistory
|
||||
const allDaysGexp = Object.keys(memberGexp).map(key => {
|
||||
return "**➺ " + key + ":** " + "`" + memberGexp[key] + "`" + "\n"
|
||||
})
|
||||
const expValue = allDaysGexp.join("")
|
||||
|
||||
const guildMemberJoinMS = guildMember.joined
|
||||
const guildMemberJoinTime = new Date(guildMemberJoinMS)
|
||||
const guildMemberJoinDate = guildMemberJoinTime.getDate()
|
||||
const guildMemberJoinMonth = guildMemberJoinTime.getMonth() + 1
|
||||
const guildMemberJoinYear = guildMemberJoinTime.getFullYear()
|
||||
const guildMemberJoinHours = guildMemberJoinTime.getHours()
|
||||
const guildMemberJoinMinutes = guildMemberJoinTime.getMinutes()
|
||||
const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds()
|
||||
|
||||
const guildMemberJoin = guildMemberJoinDate + "." +
|
||||
guildMemberJoinMonth + "." +
|
||||
guildMemberJoinYear + " " +
|
||||
guildMemberJoinHours + ":" +
|
||||
guildMemberJoinMinutes + ":" +
|
||||
guildMemberJoinSeconds
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
title: rank + displayName + guildTag,
|
||||
description: "**Guild Name:** `" + guildName + "`\n" +
|
||||
"**Guild Rank:** `" + guildRank + "`\n",
|
||||
color: embedColor,
|
||||
fields: [
|
||||
{
|
||||
name: "**Daily GEXP**",
|
||||
value: expValue
|
||||
},
|
||||
{
|
||||
name: "**Join date**",
|
||||
value: "`" + guildMemberJoin + "`"
|
||||
}
|
||||
],
|
||||
footer: {
|
||||
text: interaction.guild.name + " | Developed by taken.lua",
|
||||
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||
}
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: "This command is currently under development",
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: interaction.guild.name + " | Developed by taken.lua",
|
||||
icon_url: interaction.guild.iconURL({ dynamic: true })
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@ const commands = [];
|
||||
|
||||
const commandFiles = [
|
||||
"../commands/config.js",
|
||||
"../commands/setup.js"
|
||||
"../commands/setup.js",
|
||||
"../commands/guild.js"
|
||||
]
|
||||
|
||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function getExpForLevel(level) {
|
||||
if (level == 0) return 0;
|
||||
|
||||
|
||||
48
utils/functions/getGuildLevel.js
Normal file
48
utils/functions/getGuildLevel.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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 }
|
||||
48
utils/functions/guild.js
Normal file
48
utils/functions/guild.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function guildLevel(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 = { guildLevel }
|
||||
@@ -1,3 +1,6 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
const BASE = 10000;
|
||||
const GROWTH = 2500;
|
||||
const HALF_GROWTH = 0.5 * GROWTH;
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function skywarsLevel(xp) {
|
||||
var xps = [0, 20, 70, 150, 250, 500, 1000, 2000, 3500, 6000, 10000, 15000];
|
||||
let exactLevel = 0
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
const { skywarsLevel } = require('./functions/skywars.js')
|
||||
const { bedwarsLevel } = require('./functions/bedwars.js')
|
||||
const { hypixelLevel } = require('./functions/hypixel.js')
|
||||
const { guildLevel } = require('./functions/guild.js')
|
||||
|
||||
module.exports = { skywarsLevel, bedwarsLevel, hypixelLevel }
|
||||
module.exports = {
|
||||
skywarsLevel,
|
||||
bedwarsLevel,
|
||||
hypixelLevel,
|
||||
guildLevel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user