Updated guild command formatting
This commit is contained in:
@@ -33,9 +33,7 @@ export = {
|
|||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("query")
|
.setName("query")
|
||||||
.setDescription(
|
.setDescription("The query to search for. [Default: player]")
|
||||||
"The query to search for. [Default: player]"
|
|
||||||
)
|
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
@@ -56,9 +54,7 @@ export = {
|
|||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
option
|
option
|
||||||
.setName("query")
|
.setName("query")
|
||||||
.setDescription(
|
.setDescription("The query to search for. [Default: player]")
|
||||||
"The query to search for. [Default: player]"
|
|
||||||
)
|
|
||||||
.setRequired(true)
|
.setRequired(true)
|
||||||
)
|
)
|
||||||
.addStringOption(option =>
|
.addStringOption(option =>
|
||||||
@@ -74,9 +70,7 @@ export = {
|
|||||||
.addNumberOption(option =>
|
.addNumberOption(option =>
|
||||||
option
|
option
|
||||||
.setName("amount")
|
.setName("amount")
|
||||||
.setDescription(
|
.setDescription("The amount of guild members to show. [Default: 10]")
|
||||||
"The amount of guild members to show. [Default: 10]"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.setDMPermission(false),
|
.setDMPermission(false),
|
||||||
@@ -101,16 +95,14 @@ export = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await interaction.reply({
|
await interaction.reply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "This command is currently under development",
|
||||||
description: "This command is currently under development",
|
color: embedColor,
|
||||||
color: embedColor,
|
footer: {
|
||||||
footer: {
|
text: interaction.guild!.name + " | " + devMessage,
|
||||||
text: interaction.guild!.name + " | " + devMessage,
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
icon_url: interaction.guild!.iconURL() || undefined
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} as Command
|
} as Command
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ import { color, devMessage } from "config/options.json"
|
|||||||
import { ChatInputCommandInteraction } from "discord.js"
|
import { ChatInputCommandInteraction } from "discord.js"
|
||||||
import { GuildData } from "interfaces"
|
import { GuildData } from "interfaces"
|
||||||
|
|
||||||
export default async function guildInfo(
|
export default async function guildInfo(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
interaction: ChatInputCommandInteraction
|
|
||||||
): Promise<void> {
|
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
|
|
||||||
const query = interaction.options.getString("query")!
|
const query = interaction.options.getString("query")!
|
||||||
@@ -15,111 +13,91 @@ export default async function guildInfo(
|
|||||||
|
|
||||||
if (type === "ign") {
|
if (type === "ign") {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your uuid...",
|
||||||
description: "Fetching your uuid...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const uuid = await getUUID(query)
|
const uuid = await getUUID(query)
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That player doen't exist!",
|
||||||
description: "That player doen't exist!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your player data...",
|
||||||
description: "Fetching your player data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const player = await getPlayer(uuid)
|
const player = await getPlayer(uuid)
|
||||||
if (!player) {
|
if (!player) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That player has never joined the server!",
|
||||||
description: "That player has never joined the server!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
guild = await getGuild(uuid, "player")
|
guild = await getGuild(uuid, "player")
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That player is not in a guild!",
|
||||||
description: "That player is not in a guild!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if (type === "name") {
|
} else if (type === "name") {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
guild = await getGuild(query, "name")
|
guild = await getGuild(query, "name")
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That guild doesn't exist!",
|
||||||
description: "That guild doesn't exist!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if (type === "id") {
|
} else if (type === "id") {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
guild = await getGuild(query, "id")
|
guild = await getGuild(query, "id")
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That guild doesn't exist!",
|
||||||
description: "That guild doesn't exist!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -142,95 +120,57 @@ export default async function guildInfo(
|
|||||||
const guildCreatedSecond = guildCreated.getSeconds()
|
const guildCreatedSecond = guildCreated.getSeconds()
|
||||||
|
|
||||||
const guildCreatedTime =
|
const guildCreatedTime =
|
||||||
guildCreatedDate +
|
guildCreatedDate + "." +
|
||||||
"." +
|
guildCreatedMonth + "." +
|
||||||
guildCreatedMonth +
|
guildCreatedYear + " " +
|
||||||
"." +
|
guildCreatedHour + ":" +
|
||||||
guildCreatedYear +
|
guildCreatedMinute + ":" +
|
||||||
" " +
|
|
||||||
guildCreatedHour +
|
|
||||||
":" +
|
|
||||||
guildCreatedMinute +
|
|
||||||
":" +
|
|
||||||
guildCreatedSecond
|
guildCreatedSecond
|
||||||
|
|
||||||
const guildOwner = guildMembers.find(m => m.rank === "Guild Master")!.uuid
|
const guildOwner = guildMembers.find(m => m.rank === "Guild Master")!.uuid
|
||||||
const guildOwnerName = await getIGN(guildOwner)
|
const guildOwnerName = await getIGN(guildOwner)
|
||||||
const guildRanksUnsorted = guild!.ranks.sort(
|
const guildRanksUnsorted = guild!.ranks.sort((a, b) => b.priority - a.priority
|
||||||
(a, b) => b.priority - a.priority
|
|
||||||
)
|
)
|
||||||
const guildRanks = guildRanksUnsorted
|
const guildRanks = guildRanksUnsorted.map(r => "**➺ " + r.name + "** `[" + r.tag + "]`").join("\n")
|
||||||
.map(r => "**➺ " + r.name + "** `[" + r.tag + "]`")
|
|
||||||
.join("\n")
|
|
||||||
|
|
||||||
const allGuildMembersWeeklyXP = guildMembers.map(
|
const allGuildMembersWeeklyXP = guildMembers.map(member => member.expHistory)
|
||||||
member => member.expHistory
|
const guildMembersWeeklyXP = allGuildMembersWeeklyXP.map(member => { return Object.values(member).reduce((a, b) => a + b, 0) })
|
||||||
)
|
|
||||||
const guildMembersWeeklyXP = allGuildMembersWeeklyXP.map(member => {
|
|
||||||
return Object.values(member).reduce((a, b) => a + b, 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
const totalGuildMembersWeeklyXPUnformatted = guildMembersWeeklyXP.reduce(
|
const totalGuildMembersWeeklyXPUnformatted = guildMembersWeeklyXP.reduce((a, b) => a + b, 0)
|
||||||
(a, b) => a + b,
|
const totalGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(totalGuildMembersWeeklyXPUnformatted)
|
||||||
0
|
|
||||||
)
|
|
||||||
const totalGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(
|
|
||||||
totalGuildMembersWeeklyXPUnformatted
|
|
||||||
)
|
|
||||||
|
|
||||||
const averageGuildMembersWeeklyXPUnformatted = Math.round(
|
const averageGuildMembersWeeklyXPUnformatted = Math.round(totalGuildMembersWeeklyXPUnformatted / 7)
|
||||||
totalGuildMembersWeeklyXPUnformatted / 7
|
const averageGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(averageGuildMembersWeeklyXPUnformatted)
|
||||||
)
|
|
||||||
const averageGuildMembersWeeklyXP = new Intl.NumberFormat("en-US").format(
|
|
||||||
averageGuildMembersWeeklyXPUnformatted
|
|
||||||
)
|
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
title: "**Info on** " + guildName,
|
||||||
title: "**Info on** " + guildName,
|
description: "**Guild Name: **`" + guildName + "`\n" +
|
||||||
description:
|
"**Guild Tag: **`" + guildTag + "`\n" +
|
||||||
"**Guild Name: **`" +
|
"**Guild Level: **`" + guildLvl + "`\n" +
|
||||||
guildName +
|
"**Guild Owner: **`" + guildOwnerName + "`",
|
||||||
"`\n" +
|
fields: [
|
||||||
"**Guild Tag: **`" +
|
{
|
||||||
guildTag +
|
name: "**Guild Ranks**",
|
||||||
"`\n" +
|
value: guildRanks
|
||||||
"**Guild Level: **`" +
|
},
|
||||||
guildLvl +
|
{
|
||||||
"`\n" +
|
name: "**GEXP**",
|
||||||
"**Guild Owner: **`" +
|
value:
|
||||||
guildOwnerName +
|
"**➺ Total weekly GEXP:** `" + totalGuildMembersWeeklyXP + "`\n" +
|
||||||
"`",
|
"**➺ Daily avarage:** `" + averageGuildMembersWeeklyXP + "`\n" +
|
||||||
fields: [
|
"**➺ Total GEXP:** `" + guildExp + "`"
|
||||||
{
|
},
|
||||||
name: "**Guild Ranks**",
|
{
|
||||||
value: guildRanks
|
name: "**Guild Created**",
|
||||||
},
|
value: "**➺ **`" + guildCreatedTime + "`"
|
||||||
{
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
color: embedColor,
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild!.name + " | " + devMessage,
|
||||||
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,62 +2,52 @@ import { getUUID, getPlayer, getGuild, getHeadURL } from "utils/Hypixel"
|
|||||||
import { color, devMessage } from "config/options.json"
|
import { color, devMessage } from "config/options.json"
|
||||||
import { ChatInputCommandInteraction } from "discord.js"
|
import { ChatInputCommandInteraction } from "discord.js"
|
||||||
|
|
||||||
export default async function guildMember(
|
export default async function guildMember(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
interaction: ChatInputCommandInteraction
|
|
||||||
): Promise<void> {
|
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
|
|
||||||
const ign = interaction.options.getString("ign")!
|
const ign = interaction.options.getString("ign")!
|
||||||
const embedColor = Number(color.replace("#", "0x"))
|
const embedColor = Number(color.replace("#", "0x"))
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your uuid...",
|
||||||
description: "Fetching your uuid...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const uuid = await getUUID(ign)
|
const uuid = await getUUID(ign)
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "This user does not exist",
|
||||||
description: "This user does not exist",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your player data...",
|
||||||
description: "Fetching your player data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const head = await getHeadURL(ign)
|
const head = await getHeadURL(ign)
|
||||||
const player = await getPlayer(uuid)
|
const player = await getPlayer(uuid)
|
||||||
if (!player) {
|
if (!player) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "This user never logged on to hypixel",
|
||||||
description: "This user never logged on to hypixel",
|
color: embedColor,
|
||||||
color: embedColor,
|
thumbnail: {
|
||||||
thumbnail: {
|
url: head!
|
||||||
url: head!
|
},
|
||||||
},
|
footer: {
|
||||||
footer: {
|
text: interaction.guild!.name + " | " + devMessage,
|
||||||
text: interaction.guild!.name + " | " + devMessage,
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
icon_url: interaction.guild!.iconURL() || undefined
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -80,30 +70,26 @@ export default async function guildMember(
|
|||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const guild = await getGuild(uuid)
|
const guild = await getGuild(uuid)
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "This user is not in a guild",
|
||||||
description: "This user is not in a guild",
|
color: embedColor,
|
||||||
color: embedColor,
|
thumbnail: {
|
||||||
thumbnail: {
|
url: head!
|
||||||
url: head!
|
},
|
||||||
},
|
footer: {
|
||||||
footer: {
|
text: interaction.guild!.name + " | " + devMessage,
|
||||||
text: interaction.guild!.name + " | " + devMessage,
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
icon_url: interaction.guild!.iconURL() || undefined
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -116,30 +102,13 @@ export default async function guildMember(
|
|||||||
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 (
|
return ("**➺ " + key + ":** " + "`" + new Intl.NumberFormat("en-US").format(memberGexp[key]) + "`" + "\n")
|
||||||
"**➺ " +
|
|
||||||
key +
|
|
||||||
":** " +
|
|
||||||
"`" +
|
|
||||||
new Intl.NumberFormat("en-US").format(memberGexp[key]) +
|
|
||||||
"`" +
|
|
||||||
"\n"
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
const expValue = allDaysGexp.join("")
|
const expValue = allDaysGexp.join("")
|
||||||
const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce(
|
const totalWeeklyGexpUnformatted = Object.values(memberGexp).reduce((a, b) => a + b, 0)
|
||||||
(a, b) => a + b,
|
const totalWeeklyGexp = new Intl.NumberFormat("en-US").format(totalWeeklyGexpUnformatted)
|
||||||
0
|
const averageWeeklyGexpUnformatted = Math.round(totalWeeklyGexpUnformatted / 7)
|
||||||
)
|
const averageWeeklyGexp = new Intl.NumberFormat("en-US").format(averageWeeklyGexpUnformatted)
|
||||||
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 guildMemberJoinMS = guildMember!.joined
|
||||||
const guildMemberJoinTime = new Date(guildMemberJoinMS)
|
const guildMemberJoinTime = new Date(guildMemberJoinMS)
|
||||||
@@ -151,58 +120,42 @@ export default async function guildMember(
|
|||||||
const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds()
|
const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds()
|
||||||
|
|
||||||
const guildMemberJoin =
|
const guildMemberJoin =
|
||||||
guildMemberJoinDate +
|
guildMemberJoinDate + "." +
|
||||||
"." +
|
guildMemberJoinMonth + "." +
|
||||||
guildMemberJoinMonth +
|
guildMemberJoinYear + " " +
|
||||||
"." +
|
guildMemberJoinHours + ":" +
|
||||||
guildMemberJoinYear +
|
guildMemberJoinMinutes + ":" +
|
||||||
" " +
|
|
||||||
guildMemberJoinHours +
|
|
||||||
":" +
|
|
||||||
guildMemberJoinMinutes +
|
|
||||||
":" +
|
|
||||||
guildMemberJoinSeconds
|
guildMemberJoinSeconds
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
title: rank + displayName + guildTag,
|
||||||
title: rank + displayName + guildTag,
|
description: "**Guild Name:** `" + guildName + "`\n" +
|
||||||
description:
|
"**Guild Rank:** `" + guildRank + "`\n",
|
||||||
"**Guild Name:** `" +
|
color: embedColor,
|
||||||
guildName +
|
thumbnail: {
|
||||||
"`\n" +
|
url: head!
|
||||||
"**Guild Rank:** `" +
|
},
|
||||||
guildRank +
|
fields: [
|
||||||
"`\n",
|
{
|
||||||
color: embedColor,
|
name: "**Daily GEXP**",
|
||||||
thumbnail: {
|
value: expValue
|
||||||
url: head!
|
|
||||||
},
|
},
|
||||||
fields: [
|
{
|
||||||
{
|
name: "**Weekly GEXP**",
|
||||||
name: "**Daily GEXP**",
|
value:
|
||||||
value: expValue
|
"**➺ Total:** `" + totalWeeklyGexp + "`\n" +
|
||||||
},
|
"**➺ Daily avarage:** `" + averageWeeklyGexp + "`"
|
||||||
{
|
},
|
||||||
name: "**Weekly GEXP**",
|
{
|
||||||
value:
|
name: "**Join date**",
|
||||||
"**➺ Total:** `" +
|
value: "**➺ **`" + guildMemberJoin + "`"
|
||||||
totalWeeklyGexp +
|
|
||||||
"`\n" +
|
|
||||||
"**➺ Daily avarage:** `" +
|
|
||||||
averageWeeklyGexp +
|
|
||||||
"`"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "**Join date**",
|
|
||||||
value: "**➺ **`" + guildMemberJoin + "`"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
footer: {
|
|
||||||
text: interaction.guild!.name + " | " + devMessage,
|
|
||||||
icon_url: interaction.guild!.iconURL() || undefined
|
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
footer: {
|
||||||
|
text: interaction.guild!.name + " | " + devMessage,
|
||||||
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import { GuildData } from "interfaces"
|
|||||||
import Illegitimate from "utils/Illegitimate"
|
import Illegitimate from "utils/Illegitimate"
|
||||||
const redis = Illegitimate.redis
|
const redis = Illegitimate.redis
|
||||||
|
|
||||||
export default async function guildTop(
|
export default async function guildTop(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||||
interaction: ChatInputCommandInteraction
|
|
||||||
): Promise<void> {
|
|
||||||
await interaction.deferReply()
|
await interaction.deferReply()
|
||||||
|
|
||||||
const query = interaction.options.getString("query")!
|
const query = interaction.options.getString("query")!
|
||||||
@@ -18,123 +16,101 @@ export default async function guildTop(
|
|||||||
|
|
||||||
if (interaction.channel!.type === ChannelType.DM) {
|
if (interaction.channel!.type === ChannelType.DM) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "You can't use this command in DMs!",
|
||||||
description: "You can't use this command in DMs!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "ign") {
|
if (type === "ign") {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your uuid...",
|
||||||
description: "Fetching your uuid...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const uuid = await getUUID(query)
|
const uuid = await getUUID(query)
|
||||||
if (!uuid) {
|
if (!uuid) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That player doen't exist!",
|
||||||
description: "That player doen't exist!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your player data...",
|
||||||
description: "Fetching your player data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const player = await getPlayer(uuid)
|
const player = await getPlayer(uuid)
|
||||||
if (!player) {
|
if (!player) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That player has never joined the server!",
|
||||||
description: "That player has never joined the server!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
guild = await getGuild(uuid, "player")
|
guild = await getGuild(uuid, "player")
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That player is not in a guild!",
|
||||||
description: "That player is not in a guild!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if (type === "name") {
|
} else if (type === "name") {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
guild = await getGuild(query, "name")
|
guild = await getGuild(query, "name")
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That guild doesn't exist!",
|
||||||
description: "That guild doesn't exist!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if (type === "id") {
|
} else if (type === "id") {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching your guild data...",
|
||||||
description: "Fetching your guild data...",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
guild = await getGuild(query, "id")
|
guild = await getGuild(query, "id")
|
||||||
if (!guild) {
|
if (!guild) {
|
||||||
interaction.editReply({
|
interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "That guild doesn't exist!",
|
||||||
description: "That guild doesn't exist!",
|
color: embedColor
|
||||||
color: embedColor
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -146,21 +122,13 @@ export default async function guildTop(
|
|||||||
|
|
||||||
const cachedData = await redis.get("guildTop+" + guildId)
|
const cachedData = await redis.get("guildTop+" + guildId)
|
||||||
|
|
||||||
const gexpTodayUnformatted = guildMembers
|
const gexpTodayUnformatted = guildMembers.map(member => {
|
||||||
.map(member => {
|
return member.expHistory[Object.keys(member.expHistory)[0]]
|
||||||
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(
|
const averageGuildMemberGEXPUnformatted = Math.floor(gexpTodayUnformatted / guildMembers.length)
|
||||||
gexpTodayUnformatted / guildMembers.length
|
const averageGuildMemberGEXP = new Intl.NumberFormat("en-US").format(averageGuildMemberGEXPUnformatted)
|
||||||
)
|
|
||||||
const averageGuildMemberGEXP = new Intl.NumberFormat("en-US").format(
|
|
||||||
averageGuildMemberGEXPUnformatted
|
|
||||||
)
|
|
||||||
|
|
||||||
const allMembersDailyGEXP = guildMembers.map(member => {
|
const allMembersDailyGEXP = guildMembers.map(member => {
|
||||||
return {
|
return {
|
||||||
@@ -184,24 +152,15 @@ export default async function guildTop(
|
|||||||
let guildData: GuildTopData = []
|
let guildData: GuildTopData = []
|
||||||
const fieldsValueRaw: string[] = []
|
const fieldsValueRaw: string[] = []
|
||||||
const allMembersSorted = allMembersDailyGEXP.sort((a, b) => b.gexp - a.gexp)
|
const allMembersSorted = allMembersDailyGEXP.sort((a, b) => b.gexp - a.gexp)
|
||||||
const allMembersSortedUUIDArray = allMembersSorted.map(member => {
|
const allMembersSortedUUIDArray = allMembersSorted.map(member => { return member.uuid })
|
||||||
return member.uuid
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!cachedData) {
|
if (!cachedData) {
|
||||||
cacheStatus = false
|
cacheStatus = false
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching the top " + amount + " members of " + guildName + "...",
|
||||||
description:
|
color: embedColor
|
||||||
"Fetching the top " +
|
}]
|
||||||
amount +
|
|
||||||
" members of " +
|
|
||||||
guildName +
|
|
||||||
"...",
|
|
||||||
color: embedColor
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let i = 0; i < allMembersSortedUUIDArray.length; i++) {
|
for (let i = 0; i < allMembersSortedUUIDArray.length; i++) {
|
||||||
@@ -214,26 +173,14 @@ export default async function guildTop(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
await redis.set(
|
await redis.set("guildTop+" + guildId, JSON.stringify(guildData), "EX", 60 * 30)
|
||||||
"guildTop+" + guildId,
|
|
||||||
JSON.stringify(guildData),
|
|
||||||
"EX",
|
|
||||||
60 * 30
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
cacheStatus = true
|
cacheStatus = true
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
description: "Fetching the top " + amount + " members of " + guildName + "using cache...",
|
||||||
description:
|
color: embedColor
|
||||||
"Fetching the top " +
|
}]
|
||||||
amount +
|
|
||||||
" members of " +
|
|
||||||
guildName +
|
|
||||||
"using cache...",
|
|
||||||
color: embedColor
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
guildData = JSON.parse(cachedData)
|
guildData = JSON.parse(cachedData)
|
||||||
}
|
}
|
||||||
@@ -243,18 +190,14 @@ export default async function guildTop(
|
|||||||
|
|
||||||
for (let i = 0; i < amount; i++) {
|
for (let i = 0; i < amount; i++) {
|
||||||
const gexp = new Intl.NumberFormat("en-US").format(topMembers[i].gexp)
|
const gexp = new Intl.NumberFormat("en-US").format(topMembers[i].gexp)
|
||||||
const ign = guildData.find(
|
const ign = guildData.find(member => member.uuid === topMembers[i].uuid)?.ign
|
||||||
member => member.uuid === topMembers[i].uuid
|
|
||||||
)?.ign
|
|
||||||
|
|
||||||
const position = i + 1
|
const position = i + 1
|
||||||
|
|
||||||
fieldsValueRaw.push("**#" + position + " " + ign + ":** `" + gexp + "`")
|
fieldsValueRaw.push("**#" + position + " " + ign + ":** `" + gexp + "`")
|
||||||
}
|
}
|
||||||
|
|
||||||
const list = Array.from({ length: sliceSize }, (_, i) =>
|
const list = Array.from({ length: sliceSize }, (_, i) => fieldsValueRaw.slice(i * sliceSize, (i + 1) * sliceSize))
|
||||||
fieldsValueRaw.slice(i * sliceSize, (i + 1) * sliceSize)
|
|
||||||
)
|
|
||||||
const newList: NewList = []
|
const newList: NewList = []
|
||||||
|
|
||||||
list.forEach((item, index) => {
|
list.forEach((item, index) => {
|
||||||
@@ -270,27 +213,16 @@ export default async function guildTop(
|
|||||||
const cacheStatusText = cacheStatus ? " | [Cache]" : ""
|
const cacheStatusText = cacheStatus ? " | [Cache]" : ""
|
||||||
|
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
embeds: [{
|
||||||
{
|
title: "Top members of " + guildName,
|
||||||
title: "Top members of " + guildName,
|
description: "**Total daily GEXP:** `" + gexpToday + "`\n" +
|
||||||
description:
|
"**Average guild memeber GEXP:** `" + averageGuildMemberGEXP + "`",
|
||||||
"**Total daily GEXP:** `" +
|
color: embedColor,
|
||||||
gexpToday +
|
fields: newList,
|
||||||
"`\n" +
|
footer: {
|
||||||
"**Average guild memeber GEXP:** `" +
|
text: interaction.guild!.name + " | " + devMessage + cacheStatusText,
|
||||||
averageGuildMemberGEXP +
|
icon_url: interaction.guild!.iconURL() || undefined
|
||||||
"`",
|
|
||||||
color: embedColor,
|
|
||||||
fields: newList,
|
|
||||||
footer: {
|
|
||||||
text:
|
|
||||||
interaction.guild!.name +
|
|
||||||
" | " +
|
|
||||||
devMessage +
|
|
||||||
cacheStatusText,
|
|
||||||
icon_url: interaction.guild!.iconURL() || undefined
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
}]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user