Merge branch 'dev' into 'main'

Dev

See merge request illegitimate/illegitimate-bot!121
This commit is contained in:
2023-12-04 23:18:33 +00:00
4 changed files with 104 additions and 46 deletions

View File

@@ -30,9 +30,19 @@ module.exports = {
.setDescription("Get info about a guild.")
.addStringOption(option =>
option
.setName("ign")
.setName("query")
.setDescription("The IGN of a member.")
.setRequired(true)
).
addStringOption(option =>
option
.setName("type")
.setDescription("The type of query.")
.addChoices(
{ name: "Guild Member", value: "ign" },
{ name: "Guild Name", value: "name" },
{ name: "Guild Id", value: "id" }
)
)
),

View File

@@ -5,68 +5,109 @@ const { color, devMessage } = require("../../../config/options.json")
async function guildInfo(interaction) {
const ign = interaction.options.getString("ign")
const query = interaction.options.getString("query")
const type = interaction.options.getString("type") || "ign"
const embedColor = Number(color.replace("#", "0x"))
let guild
await interaction.editReply({
embeds: [{
description: "Fetching your uuid...",
color: embedColor
}]
})
const uuid = await getUUID(ign)
if (!uuid) {
interaction.editReply({
if (type === "ign") {
await interaction.editReply({
embeds: [{
description: "That player doen't exist!",
description: "Fetching your uuid...",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [{
description: "Fetching your player data...",
color: embedColor
}]
})
const uuid = await getUUID(query)
if (!uuid) {
interaction.editReply({
embeds: [{
description: "That player doen't exist!",
color: embedColor
}]
})
return
}
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
await interaction.editReply({
embeds: [{
description: "That player has never joined the server!",
description: "Fetching your player data...",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [{
description: "Fetching your guild data...",
color: embedColor
}]
})
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({
await interaction.editReply({
embeds: [{
description: "That player is not in a guild!",
description: "Fetching your guild data...",
color: embedColor
}]
})
return
guild = await getGuild(uuid, "player")
if (!guild) {
interaction.editReply({
embeds: [{
description: "That player is not in a guild!",
color: embedColor
}]
})
return
}
} else if (type === "name") {
await interaction.editReply({
embeds: [{
description: "Fetching your guild data...",
color: embedColor
}]
})
guild = await getGuild(query, "name")
if (!guild) {
interaction.editReply({
embeds: [{
description: "That guild doesn't exist!",
color: embedColor
}]
})
return
}
} else if (type === "id") {
await interaction.editReply({
embeds: [{
description: "Fetching your guild data...",
color: embedColor
}]
})
guild = await getGuild(query, "id")
if (!guild) {
interaction.editReply({
embeds: [{
description: "That guild doesn't exist!",
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 guildExpUnformatted = guild.exp
const guildExp = new Intl.NumberFormat().format(guildExpUnformatted)
const guildLvl = guildLevel(guildExp)
const guildMembers = guild.members
@@ -89,7 +130,10 @@ async function guildInfo(interaction) {
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)
const totalGuildMembersDailyXPUnformatted = guildMembersDailyXP.reduce((a, b) => a + b, 0)
const totalGuildMembersDailyXP = new Intl.NumberFormat().format(totalGuildMembersDailyXPUnformatted)
const averageGuildMembersDailyXPUnformatted = Math.round(totalGuildMembersDailyXPUnformatted / 7)
const averageGuildMembersDailyXP = new Intl.NumberFormat().format(averageGuildMembersDailyXPUnformatted)
const footerText = interaction.guild ? interaction.guild.name : interaction.user.username
const footerIcon = interaction.guild ? interaction.guild.iconURL({ dynamic: true }) : interaction.user.avatarURL({ dynamic: true })
@@ -109,7 +153,7 @@ async function guildInfo(interaction) {
{
name: "**GEXP**",
value: "**➺ Total weekly GEXP:** `" + totalGuildMembersDailyXP + "`\n" +
"**➺ Daily avarage:** `" + Math.round(totalGuildMembersDailyXP / 7) + "`\n" +
"**➺ Daily avarage:** `" + averageGuildMembersDailyXP + "`\n" +
"**➺ Total GEXP:** `" + guildExp + "`"
},
{

View File

@@ -105,11 +105,13 @@ async function guildMember(interaction) {
const guildRank = guildMember.rank
const memberGexp = guildMember.expHistory
const allDaysGexp = Object.keys(memberGexp).map((key) => {
return "**➺ " + key + ":** " + "`" + memberGexp[key] + "`" + "\n"
return "**➺ " + key + ":** " + "`" + new Intl.NumberFormat().format(memberGexp[key]) + "`" + "\n"
})
const expValue = allDaysGexp.join("")
const totalWeeklyGexp = Object.values(memberGexp).reduce((a, b) => a + b, 0)
const averageWeeklyGexp = Math.round(totalWeeklyGexp / 7)
const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce((a, b) => a + b, 0)
const totalWeeklyGexp = new Intl.NumberFormat().format(totalWeeklyGexpUnformatted)
const averageWeeklyGexpUnformatted = Math.round(totalWeeklyGexpUnformatted / 7)
const averageWeeklyGexp = new Intl.NumberFormat().format(averageWeeklyGexpUnformatted)
const guildMemberJoinMS = guildMember.joined
const guildMemberJoinTime = new Date(guildMemberJoinMS)

View File

@@ -39,11 +39,13 @@ async function getPlayer(uuid) {
return playerReq.data.player
}
async function getGuild(uuid) {
async function getGuild(query, type) {
const reqType = type ? type : "player"
const guildReq = await fetch(guild, {
params: {
key: apikey,
player: uuid
[reqType]: query
}
})