Updated guild command formatting
This commit is contained in:
@@ -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
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user