From bc5454678821d52c3bace6386a293229d72dd150 Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 4 Dec 2023 23:59:33 +0100 Subject: [PATCH 1/3] Added support for guild nameds and ids as input --- src/utils/functions/account.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils/functions/account.js b/src/utils/functions/account.js index 23e1032..6f81d16 100644 --- a/src/utils/functions/account.js +++ b/src/utils/functions/account.js @@ -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 } }) From 4c29b8dd475a0e9ff1c7d454ecf41bf16cda7a2a Mon Sep 17 00:00:00 2001 From: Taken Date: Tue, 5 Dec 2023 00:00:08 +0100 Subject: [PATCH 2/3] Updated guild info command to query name and id as well --- src/commands/guild.js | 14 ++++- src/commands/guild/info.js | 114 +++++++++++++++++++++++++------------ 2 files changed, 89 insertions(+), 39 deletions(-) diff --git a/src/commands/guild.js b/src/commands/guild.js index edb3ed6..80499ee 100644 --- a/src/commands/guild.js +++ b/src/commands/guild.js @@ -7,7 +7,7 @@ module.exports = { name: "guild", description: "Subcommands for guilds", type: "slash", - dev: false, + dev: true, public: true, data: new SlashCommandBuilder() @@ -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" } + ) ) ), diff --git a/src/commands/guild/info.js b/src/commands/guild/info.js index 5da89fe..d878790 100644 --- a/src/commands/guild/info.js +++ b/src/commands/guild/info.js @@ -5,61 +5,101 @@ 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 From 9df2d7b859601c7b7d39c04169c57fa86dc94450 Mon Sep 17 00:00:00 2001 From: Taken Date: Tue, 5 Dec 2023 00:17:23 +0100 Subject: [PATCH 3/3] Updated guild commands to foemat large numbers --- src/commands/guild.js | 2 +- src/commands/guild/info.js | 10 +++++++--- src/commands/guild/member.js | 8 +++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/commands/guild.js b/src/commands/guild.js index 80499ee..d1b2ba6 100644 --- a/src/commands/guild.js +++ b/src/commands/guild.js @@ -7,7 +7,7 @@ module.exports = { name: "guild", description: "Subcommands for guilds", type: "slash", - dev: true, + dev: false, public: true, data: new SlashCommandBuilder() diff --git a/src/commands/guild/info.js b/src/commands/guild/info.js index d878790..799146a 100644 --- a/src/commands/guild/info.js +++ b/src/commands/guild/info.js @@ -106,7 +106,8 @@ async function guildInfo(interaction) { 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 @@ -129,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 }) @@ -149,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 + "`" }, { diff --git a/src/commands/guild/member.js b/src/commands/guild/member.js index 2636aa2..fb5b15f 100644 --- a/src/commands/guild/member.js +++ b/src/commands/guild/member.js @@ -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)