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.") .setDescription("Get info about a guild.")
.addStringOption(option => .addStringOption(option =>
option option
.setName("ign") .setName("query")
.setDescription("The IGN of a member.") .setDescription("The IGN of a member.")
.setRequired(true) .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,9 +5,12 @@ const { color, devMessage } = require("../../../config/options.json")
async function guildInfo(interaction) { 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")) const embedColor = Number(color.replace("#", "0x"))
let guild
if (type === "ign") {
await interaction.editReply({ await interaction.editReply({
embeds: [{ embeds: [{
description: "Fetching your uuid...", description: "Fetching your uuid...",
@@ -15,7 +18,7 @@ async function guildInfo(interaction) {
}] }]
}) })
const uuid = await getUUID(ign) const uuid = await getUUID(query)
if (!uuid) { if (!uuid) {
interaction.editReply({ interaction.editReply({
embeds: [{ embeds: [{
@@ -51,7 +54,7 @@ async function guildInfo(interaction) {
}] }]
}) })
const guild = await getGuild(uuid) guild = await getGuild(uuid, "player")
if (!guild) { if (!guild) {
interaction.editReply({ interaction.editReply({
embeds: [{ embeds: [{
@@ -61,12 +64,50 @@ async function guildInfo(interaction) {
}) })
return 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 guildName = guild.name
const guildCreatedMS = guild.created const guildCreatedMS = guild.created
const guildCreated = new Date(guildCreatedMS) const guildCreated = new Date(guildCreatedMS)
const guildTag = guild.tag const guildTag = guild.tag
const guildExp = guild.exp const guildExpUnformatted = guild.exp
const guildExp = new Intl.NumberFormat().format(guildExpUnformatted)
const guildLvl = guildLevel(guildExp) const guildLvl = guildLevel(guildExp)
const guildMembers = guild.members 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 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 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 footerText = interaction.guild ? interaction.guild.name : interaction.user.username
const footerIcon = interaction.guild ? interaction.guild.iconURL({ dynamic: true }) : interaction.user.avatarURL({ dynamic: true }) const footerIcon = interaction.guild ? interaction.guild.iconURL({ dynamic: true }) : interaction.user.avatarURL({ dynamic: true })
@@ -109,7 +153,7 @@ async function guildInfo(interaction) {
{ {
name: "**GEXP**", name: "**GEXP**",
value: "**➺ Total weekly GEXP:** `" + totalGuildMembersDailyXP + "`\n" + value: "**➺ Total weekly GEXP:** `" + totalGuildMembersDailyXP + "`\n" +
"**➺ Daily avarage:** `" + Math.round(totalGuildMembersDailyXP / 7) + "`\n" + "**➺ Daily avarage:** `" + averageGuildMembersDailyXP + "`\n" +
"**➺ Total GEXP:** `" + guildExp + "`" "**➺ Total GEXP:** `" + guildExp + "`"
}, },
{ {

View File

@@ -105,11 +105,13 @@ async function guildMember(interaction) {
const guildRank = guildMember.rank const guildRank = guildMember.rank
const memberGexp = guildMember.expHistory const memberGexp = guildMember.expHistory
const allDaysGexp = Object.keys(memberGexp).map((key) => { 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 expValue = allDaysGexp.join("")
const totalWeeklyGexp = Object.values(memberGexp).reduce((a, b) => a + b, 0) const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce((a, b) => a + b, 0)
const averageWeeklyGexp = Math.round(totalWeeklyGexp / 7) 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 guildMemberJoinMS = guildMember.joined
const guildMemberJoinTime = new Date(guildMemberJoinMS) const guildMemberJoinTime = new Date(guildMemberJoinMS)

View File

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