Updated guild command formatting
This commit is contained in:
@@ -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: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "This command is currently under development",
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: interaction.guild!.name + " | " + devMessage,
|
||||
icon_url: interaction.guild!.iconURL() || undefined
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
} as Command
|
||||
|
||||
@@ -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: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your uuid...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const uuid = await getUUID(query)
|
||||
if (!uuid) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That player doen't exist!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your player data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const player = await getPlayer(uuid)
|
||||
if (!player) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That player has never joined the server!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
guild = await getGuild(uuid, "player")
|
||||
if (!guild) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That player is not in a guild!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if (type === "name") {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
guild = await getGuild(query, "name")
|
||||
if (!guild) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That guild doesn't exist!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if (type === "id") {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
guild = await getGuild(query, "id")
|
||||
if (!guild) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That guild doesn't exist!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -142,66 +120,35 @@ 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: [
|
||||
{
|
||||
embeds: [{
|
||||
title: "**Info on** " + guildName,
|
||||
description:
|
||||
"**Guild Name: **`" +
|
||||
guildName +
|
||||
"`\n" +
|
||||
"**Guild Tag: **`" +
|
||||
guildTag +
|
||||
"`\n" +
|
||||
"**Guild Level: **`" +
|
||||
guildLvl +
|
||||
"`\n" +
|
||||
"**Guild Owner: **`" +
|
||||
guildOwnerName +
|
||||
"`",
|
||||
description: "**Guild Name: **`" + guildName + "`\n" +
|
||||
"**Guild Tag: **`" + guildTag + "`\n" +
|
||||
"**Guild Level: **`" + guildLvl + "`\n" +
|
||||
"**Guild Owner: **`" + guildOwnerName + "`",
|
||||
fields: [
|
||||
{
|
||||
name: "**Guild Ranks**",
|
||||
@@ -210,15 +157,9 @@ export default async function guildInfo(
|
||||
{
|
||||
name: "**GEXP**",
|
||||
value:
|
||||
"**➺ Total weekly GEXP:** `" +
|
||||
totalGuildMembersWeeklyXP +
|
||||
"`\n" +
|
||||
"**➺ Daily avarage:** `" +
|
||||
averageGuildMembersWeeklyXP +
|
||||
"`\n" +
|
||||
"**➺ Total GEXP:** `" +
|
||||
guildExp +
|
||||
"`"
|
||||
"**➺ Total weekly GEXP:** `" + totalGuildMembersWeeklyXP + "`\n" +
|
||||
"**➺ Daily avarage:** `" + averageGuildMembersWeeklyXP + "`\n" +
|
||||
"**➺ Total GEXP:** `" + guildExp + "`"
|
||||
},
|
||||
{
|
||||
name: "**Guild Created**",
|
||||
@@ -230,7 +171,6 @@ export default async function guildInfo(
|
||||
text: interaction.guild!.name + " | " + devMessage,
|
||||
icon_url: interaction.guild!.iconURL() || undefined
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,51 +2,42 @@ 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: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your uuid...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const uuid = await getUUID(ign)
|
||||
if (!uuid) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "This user does not exist",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your player data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const head = await getHeadURL(ign)
|
||||
const player = await getPlayer(uuid)
|
||||
if (!player) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "This user never logged on to hypixel",
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
@@ -56,8 +47,7 @@ export default async function guildMember(
|
||||
text: interaction.guild!.name + " | " + devMessage,
|
||||
icon_url: interaction.guild!.iconURL() || undefined
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
@@ -80,19 +70,16 @@ export default async function guildMember(
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const guild = await getGuild(uuid)
|
||||
if (!guild) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "This user is not in a guild",
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
@@ -102,8 +89,7 @@ export default async function guildMember(
|
||||
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,29 +120,18 @@ 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: [
|
||||
{
|
||||
embeds: [{
|
||||
title: rank + displayName + guildTag,
|
||||
description:
|
||||
"**Guild Name:** `" +
|
||||
guildName +
|
||||
"`\n" +
|
||||
"**Guild Rank:** `" +
|
||||
guildRank +
|
||||
"`\n",
|
||||
description: "**Guild Name:** `" + guildName + "`\n" +
|
||||
"**Guild Rank:** `" + guildRank + "`\n",
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
url: head!
|
||||
@@ -186,12 +144,8 @@ export default async function guildMember(
|
||||
{
|
||||
name: "**Weekly GEXP**",
|
||||
value:
|
||||
"**➺ Total:** `" +
|
||||
totalWeeklyGexp +
|
||||
"`\n" +
|
||||
"**➺ Daily avarage:** `" +
|
||||
averageWeeklyGexp +
|
||||
"`"
|
||||
"**➺ Total:** `" + totalWeeklyGexp + "`\n" +
|
||||
"**➺ Daily avarage:** `" + averageWeeklyGexp + "`"
|
||||
},
|
||||
{
|
||||
name: "**Join date**",
|
||||
@@ -202,7 +156,6 @@ export default async function guildMember(
|
||||
text: interaction.guild!.name + " | " + devMessage,
|
||||
icon_url: interaction.guild!.iconURL() || undefined
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "You can't use this command in DMs!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (type === "ign") {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your uuid...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const uuid = await getUUID(query)
|
||||
if (!uuid) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That player doen't exist!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your player data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
const player = await getPlayer(uuid)
|
||||
if (!player) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That player has never joined the server!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
guild = await getGuild(uuid, "player")
|
||||
if (!guild) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That player is not in a guild!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if (type === "name") {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
guild = await getGuild(query, "name")
|
||||
if (!guild) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "That guild doesn't exist!",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
return
|
||||
}
|
||||
} else if (type === "id") {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
embeds: [{
|
||||
description: "Fetching your guild data...",
|
||||
color: embedColor
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
|
||||
guild = await getGuild(query, "id")
|
||||
if (!guild) {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
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 => {
|
||||
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
|
||||
)
|
||||
}).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 +
|
||||
"...",
|
||||
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...",
|
||||
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: [
|
||||
{
|
||||
embeds: [{
|
||||
title: "Top members of " + guildName,
|
||||
description:
|
||||
"**Total daily GEXP:** `" +
|
||||
gexpToday +
|
||||
"`\n" +
|
||||
"**Average guild memeber GEXP:** `" +
|
||||
averageGuildMemberGEXP +
|
||||
"`",
|
||||
description: "**Total daily GEXP:** `" + gexpToday + "`\n" +
|
||||
"**Average guild memeber GEXP:** `" + averageGuildMemberGEXP + "`",
|
||||
color: embedColor,
|
||||
fields: newList,
|
||||
footer: {
|
||||
text:
|
||||
interaction.guild!.name +
|
||||
" | " +
|
||||
devMessage +
|
||||
cacheStatusText,
|
||||
text: interaction.guild!.name + " | " + devMessage + cacheStatusText,
|
||||
icon_url: interaction.guild!.iconURL() || undefined
|
||||
}
|
||||
}
|
||||
]
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user