Updated guild command formatting

This commit is contained in:
2024-01-19 22:05:39 +01:00
parent 3eed20e788
commit f34923e2c5
4 changed files with 237 additions and 420 deletions

View File

@@ -33,9 +33,7 @@ export = {
.addStringOption(option =>
option
.setName("query")
.setDescription(
"The query to search for. [Default: player]"
)
.setDescription("The query to search for. [Default: player]")
.setRequired(true)
)
.addStringOption(option =>
@@ -56,9 +54,7 @@ export = {
.addStringOption(option =>
option
.setName("query")
.setDescription(
"The query to search for. [Default: player]"
)
.setDescription("The query to search for. [Default: player]")
.setRequired(true)
)
.addStringOption(option =>
@@ -74,9 +70,7 @@ export = {
.addNumberOption(option =>
option
.setName("amount")
.setDescription(
"The amount of guild members to show. [Default: 10]"
)
.setDescription("The amount of guild members to show. [Default: 10]")
)
)
.setDMPermission(false),
@@ -101,16 +95,14 @@ export = {
}
await interaction.reply({
embeds: [
{
description: "This command is currently under development",
color: embedColor,
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
embeds: [{
description: "This command is currently under development",
color: embedColor,
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
]
}]
})
}
} as Command

View File

@@ -3,9 +3,7 @@ import { color, devMessage } from "config/options.json"
import { ChatInputCommandInteraction } from "discord.js"
import { GuildData } from "interfaces"
export default async function guildInfo(
interaction: ChatInputCommandInteraction
): Promise<void> {
export default async function guildInfo(interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.deferReply()
const query = interaction.options.getString("query")!
@@ -15,111 +13,91 @@ export default async function guildInfo(
if (type === "ign") {
await interaction.editReply({
embeds: [
{
description: "Fetching your uuid...",
color: embedColor
}
]
embeds: [{
description: "Fetching your uuid...",
color: embedColor
}]
})
const uuid = await getUUID(query)
if (!uuid) {
interaction.editReply({
embeds: [
{
description: "That player doen't exist!",
color: embedColor
}
]
embeds: [{
description: "That player doen't exist!",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [
{
description: "Fetching your player data...",
color: embedColor
}
]
embeds: [{
description: "Fetching your player data...",
color: embedColor
}]
})
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
embeds: [
{
description: "That player has never joined the server!",
color: embedColor
}
]
embeds: [{
description: "That player has never joined the server!",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [
{
description: "Fetching your guild data...",
color: embedColor
}
]
embeds: [{
description: "Fetching your guild data...",
color: embedColor
}]
})
guild = await getGuild(uuid, "player")
if (!guild) {
interaction.editReply({
embeds: [
{
description: "That player is not in a guild!",
color: embedColor
}
]
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
}
]
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
}
]
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
}
]
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
}
]
embeds: [{
description: "That guild doesn't exist!",
color: embedColor
}]
})
return
}
@@ -142,95 +120,57 @@ export default async function guildInfo(
const guildCreatedSecond = guildCreated.getSeconds()
const guildCreatedTime =
guildCreatedDate +
"." +
guildCreatedMonth +
"." +
guildCreatedYear +
" " +
guildCreatedHour +
":" +
guildCreatedMinute +
":" +
guildCreatedDate + "." +
guildCreatedMonth + "." +
guildCreatedYear + " " +
guildCreatedHour + ":" +
guildCreatedMinute + ":" +
guildCreatedSecond
const guildOwner = guildMembers.find(m => m.rank === "Guild Master")!.uuid
const guildOwnerName = await getIGN(guildOwner)
const guildRanksUnsorted = guild!.ranks.sort(
(a, b) => b.priority - a.priority
const guildRanksUnsorted = guild!.ranks.sort((a, b) => b.priority - a.priority
)
const guildRanks = guildRanksUnsorted
.map(r => "**➺ " + r.name + "** `[" + r.tag + "]`")
.join("\n")
const guildRanks = guildRanksUnsorted.map(r => "**➺ " + r.name + "** `[" + r.tag + "]`").join("\n")
const allGuildMembersWeeklyXP = guildMembers.map(
member => member.expHistory
)
const guildMembersWeeklyXP = allGuildMembersWeeklyXP.map(member => {
return Object.values(member).reduce((a, b) => a + b, 0)
})
const allGuildMembersWeeklyXP = guildMembers.map(member => member.expHistory)
const guildMembersWeeklyXP = allGuildMembersWeeklyXP.map(member => { return Object.values(member).reduce((a, b) => a + b, 0) })
const totalGuildMembersWeeklyXPUnformatted = guildMembersWeeklyXP.reduce(
(a, b) => a + b,
0
)
const totalGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(
totalGuildMembersWeeklyXPUnformatted
)
const totalGuildMembersWeeklyXPUnformatted = guildMembersWeeklyXP.reduce((a, b) => a + b, 0)
const totalGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(totalGuildMembersWeeklyXPUnformatted)
const averageGuildMembersWeeklyXPUnformatted = Math.round(
totalGuildMembersWeeklyXPUnformatted / 7
)
const averageGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(
averageGuildMembersWeeklyXPUnformatted
)
const averageGuildMembersWeeklyXPUnformatted = Math.round(totalGuildMembersWeeklyXPUnformatted / 7)
const averageGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(averageGuildMembersWeeklyXPUnformatted)
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:** `" +
totalGuildMembersWeeklyXP +
"`\n" +
"**➺ Daily avarage:** `" +
averageGuildMembersWeeklyXP +
"`\n" +
"**➺ Total GEXP:** `" +
guildExp +
"`"
},
{
name: "**Guild Created**",
value: "**➺ **`" + guildCreatedTime + "`"
}
],
color: embedColor,
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
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:** `" + totalGuildMembersWeeklyXP + "`\n" +
"**➺ Daily avarage:** `" + averageGuildMembersWeeklyXP + "`\n" +
"**➺ Total GEXP:** `" + guildExp + "`"
},
{
name: "**Guild Created**",
value: "**➺ **`" + guildCreatedTime + "`"
}
],
color: embedColor,
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
]
}]
})
}

View File

@@ -2,62 +2,52 @@ import { getUUID, getPlayer, getGuild, getHeadURL } from "utils/Hypixel"
import { color, devMessage } from "config/options.json"
import { ChatInputCommandInteraction } from "discord.js"
export default async function guildMember(
interaction: ChatInputCommandInteraction
): Promise<void> {
export default async function guildMember(interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.deferReply()
const ign = interaction.options.getString("ign")!
const embedColor = Number(color.replace("#", "0x"))
await interaction.editReply({
embeds: [
{
description: "Fetching your uuid...",
color: embedColor
}
]
embeds: [{
description: "Fetching your uuid...",
color: embedColor
}]
})
const uuid = await getUUID(ign)
if (!uuid) {
interaction.editReply({
embeds: [
{
description: "This user does not exist",
color: embedColor
}
]
embeds: [{
description: "This user does not exist",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [
{
description: "Fetching your player data...",
color: embedColor
}
]
embeds: [{
description: "Fetching your player data...",
color: embedColor
}]
})
const head = await getHeadURL(ign)
const player = await getPlayer(uuid)
if (!player) {
await interaction.editReply({
embeds: [
{
description: "This user never logged on to hypixel",
color: embedColor,
thumbnail: {
url: head!
},
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
embeds: [{
description: "This user never logged on to hypixel",
color: embedColor,
thumbnail: {
url: head!
},
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
]
}]
})
return
}
@@ -80,30 +70,26 @@ export default async function guildMember(
}
await interaction.editReply({
embeds: [
{
description: "Fetching your guild data...",
color: embedColor
}
]
embeds: [{
description: "Fetching your guild data...",
color: embedColor
}]
})
const guild = await getGuild(uuid)
if (!guild) {
await interaction.editReply({
embeds: [
{
description: "This user is not in a guild",
color: embedColor,
thumbnail: {
url: head!
},
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
embeds: [{
description: "This user is not in a guild",
color: embedColor,
thumbnail: {
url: head!
},
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
]
}]
})
return
}
@@ -116,30 +102,13 @@ export default async function guildMember(
const guildRank = guildMember!.rank
const memberGexp = guildMember!.expHistory
const allDaysGexp = Object.keys(memberGexp).map(key => {
return (
"**➺ " +
key +
":** " +
"`" +
new Intl.NumberFormat("en-US").format(memberGexp[key]) +
"`" +
"\n"
)
return ("**➺ " + key + ":** " + "`" + new Intl.NumberFormat("en-US").format(memberGexp[key]) + "`" + "\n")
})
const expValue = allDaysGexp.join("")
const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce(
(a, b) => a + b,
0
)
const totalWeeklyGexp = new Intl.NumberFormat("en-US").format(
totalWeeklyGexpUnformatted
)
const averageWeeklyGexpUnformatted = Math.round(
totalWeeklyGexpUnformatted / 7
)
const averageWeeklyGexp = new Intl.NumberFormat("en-US").format(
averageWeeklyGexpUnformatted
)
const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce((a, b) => a + b, 0)
const totalWeeklyGexp = new Intl.NumberFormat("en-US").format(totalWeeklyGexpUnformatted)
const averageWeeklyGexpUnformatted = Math.round(totalWeeklyGexpUnformatted / 7)
const averageWeeklyGexp = new Intl.NumberFormat("en-US").format(averageWeeklyGexpUnformatted)
const guildMemberJoinMS = guildMember!.joined
const guildMemberJoinTime = new Date(guildMemberJoinMS)
@@ -151,58 +120,42 @@ export default async function guildMember(
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",
color: embedColor,
thumbnail: {
url: head!
embeds: [{
title: rank + displayName + guildTag,
description: "**Guild Name:** `" + guildName + "`\n" +
"**Guild Rank:** `" + guildRank + "`\n",
color: embedColor,
thumbnail: {
url: head!
},
fields: [
{
name: "**Daily GEXP**",
value: expValue
},
fields: [
{
name: "**Daily GEXP**",
value: expValue
},
{
name: "**Weekly GEXP**",
value:
"**➺ Total:** `" +
totalWeeklyGexp +
"`\n" +
"**➺ Daily avarage:** `" +
averageWeeklyGexp +
"`"
},
{
name: "**Join date**",
value: "**➺ **`" + guildMemberJoin + "`"
}
],
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
{
name: "**Weekly GEXP**",
value:
"**➺ Total:** `" + totalWeeklyGexp + "`\n" +
"**➺ Daily avarage:** `" + averageWeeklyGexp + "`"
},
{
name: "**Join date**",
value: "**➺ **`" + guildMemberJoin + "`"
}
],
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL() || undefined
}
]
}]
})
}

View File

@@ -5,9 +5,7 @@ import { GuildData } from "interfaces"
import Illegitimate from "utils/Illegitimate"
const redis = Illegitimate.redis
export default async function guildTop(
interaction: ChatInputCommandInteraction
): Promise<void> {
export default async function guildTop(interaction: ChatInputCommandInteraction): Promise<void> {
await interaction.deferReply()
const query = interaction.options.getString("query")!
@@ -18,123 +16,101 @@ export default async function guildTop(
if (interaction.channel!.type === ChannelType.DM) {
interaction.editReply({
embeds: [
{
description: "You can't use this command in DMs!",
color: embedColor
}
]
embeds: [{
description: "You can't use this command in DMs!",
color: embedColor
}]
})
return
}
if (type === "ign") {
await interaction.editReply({
embeds: [
{
description: "Fetching your uuid...",
color: embedColor
}
]
embeds: [{
description: "Fetching your uuid...",
color: embedColor
}]
})
const uuid = await getUUID(query)
if (!uuid) {
interaction.editReply({
embeds: [
{
description: "That player doen't exist!",
color: embedColor
}
]
embeds: [{
description: "That player doen't exist!",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [
{
description: "Fetching your player data...",
color: embedColor
}
]
embeds: [{
description: "Fetching your player data...",
color: embedColor
}]
})
const player = await getPlayer(uuid)
if (!player) {
interaction.editReply({
embeds: [
{
description: "That player has never joined the server!",
color: embedColor
}
]
embeds: [{
description: "That player has never joined the server!",
color: embedColor
}]
})
return
}
await interaction.editReply({
embeds: [
{
description: "Fetching your guild data...",
color: embedColor
}
]
embeds: [{
description: "Fetching your guild data...",
color: embedColor
}]
})
guild = await getGuild(uuid, "player")
if (!guild) {
interaction.editReply({
embeds: [
{
description: "That player is not in a guild!",
color: embedColor
}
]
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
}
]
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
}
]
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
}
]
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
}
]
embeds: [{
description: "That guild doesn't exist!",
color: embedColor
}]
})
return
}
@@ -146,21 +122,13 @@ export default async function guildTop(
const cachedData = await redis.get("guildTop+" + guildId)
const gexpTodayUnformatted = guildMembers
.map(member => {
return member.expHistory[Object.keys(member.expHistory)[0]]
})
.reduce((a, b) => a + b, 0)
const gexpToday = new Intl.NumberFormat("en-US").format(
gexpTodayUnformatted
)
const gexpTodayUnformatted = guildMembers.map(member => {
return member.expHistory[Object.keys(member.expHistory)[0]]
}).reduce((a, b) => a + b, 0)
const gexpToday = new Intl.NumberFormat("en-US").format(gexpTodayUnformatted)
const averageGuildMemberGEXPUnformatted = Math.floor(
gexpTodayUnformatted / guildMembers.length
)
const averageGuildMemberGEXP = new Intl.NumberFormat("en-US").format(
averageGuildMemberGEXPUnformatted
)
const averageGuildMemberGEXPUnformatted = Math.floor(gexpTodayUnformatted / guildMembers.length)
const averageGuildMemberGEXP = new Intl.NumberFormat("en-US").format(averageGuildMemberGEXPUnformatted)
const allMembersDailyGEXP = guildMembers.map(member => {
return {
@@ -184,24 +152,15 @@ export default async function guildTop(
let guildData: GuildTopData = []
const fieldsValueRaw: string[] = []
const allMembersSorted = allMembersDailyGEXP.sort((a, b) => b.gexp - a.gexp)
const allMembersSortedUUIDArray = allMembersSorted.map(member => {
return member.uuid
})
const allMembersSortedUUIDArray = allMembersSorted.map(member => { return member.uuid })
if (!cachedData) {
cacheStatus = false
await interaction.editReply({
embeds: [
{
description:
"Fetching the top " +
amount +
" members of " +
guildName +
"...",
color: embedColor
}
]
embeds: [{
description: "Fetching the top " + amount + " members of " + guildName + "...",
color: embedColor
}]
})
for (let i = 0; i < allMembersSortedUUIDArray.length; i++) {
@@ -214,26 +173,14 @@ export default async function guildTop(
})
}
await redis.set(
"guildTop+" + guildId,
JSON.stringify(guildData),
"EX",
60 * 30
)
await redis.set("guildTop+" + guildId, JSON.stringify(guildData), "EX", 60 * 30)
} else {
cacheStatus = true
await interaction.editReply({
embeds: [
{
description:
"Fetching the top " +
amount +
" members of " +
guildName +
"using cache...",
color: embedColor
}
]
embeds: [{
description: "Fetching the top " + amount + " members of " + guildName + "using cache...",
color: embedColor
}]
})
guildData = JSON.parse(cachedData)
}
@@ -243,18 +190,14 @@ export default async function guildTop(
for (let i = 0; i < amount; i++) {
const gexp = new Intl.NumberFormat("en-US").format(topMembers[i].gexp)
const ign = guildData.find(
member => member.uuid === topMembers[i].uuid
)?.ign
const ign = guildData.find(member => member.uuid === topMembers[i].uuid)?.ign
const position = i + 1
fieldsValueRaw.push("**#" + position + " " + ign + ":** `" + gexp + "`")
}
const list = Array.from({ length: sliceSize }, (_, i) =>
fieldsValueRaw.slice(i * sliceSize, (i + 1) * sliceSize)
)
const list = Array.from({ length: sliceSize }, (_, i) => fieldsValueRaw.slice(i * sliceSize, (i + 1) * sliceSize))
const newList: NewList = []
list.forEach((item, index) => {
@@ -270,27 +213,16 @@ export default async function guildTop(
const cacheStatusText = cacheStatus ? " | [Cache]" : ""
await interaction.editReply({
embeds: [
{
title: "Top members of " + guildName,
description:
"**Total daily GEXP:** `" +
gexpToday +
"`\n" +
"**Average guild memeber GEXP:** `" +
averageGuildMemberGEXP +
"`",
color: embedColor,
fields: newList,
footer: {
text:
interaction.guild!.name +
" | " +
devMessage +
cacheStatusText,
icon_url: interaction.guild!.iconURL() || undefined
}
embeds: [{
title: "Top members of " + guildName,
description: "**Total daily GEXP:** `" + gexpToday + "`\n" +
"**Average guild memeber GEXP:** `" + averageGuildMemberGEXP + "`",
color: embedColor,
fields: newList,
footer: {
text: interaction.guild!.name + " | " + devMessage + cacheStatusText,
icon_url: interaction.guild!.iconURL() || undefined
}
]
}]
})
}