Replaced clang format with prettuier (sadly)

This commit is contained in:
2023-12-28 16:47:52 +01:00
parent ca5bbd0b81
commit 117140fe9d
99 changed files with 13519 additions and 12011 deletions

View File

@@ -4,7 +4,9 @@ import { ChannelType, ChatInputCommandInteraction } from "discord.js"
import { redis } from "../../utils/Redis"
import { GuildData } from "../../interfaces/Guild"
async function guildTop(interaction: ChatInputCommandInteraction): Promise<void> {
async function guildTop(
interaction: ChatInputCommandInteraction,
): Promise<void> {
await interaction.deferReply()
const query = interaction.options.getString("query")!
@@ -15,101 +17,123 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
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
}
@@ -121,18 +145,26 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
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) => {
const allMembersDailyGEXP = guildMembers.map(member => {
return {
uuid: member.uuid,
gexp: member.expHistory[Object.keys(member.expHistory)[0]]
gexp: member.expHistory[Object.keys(member.expHistory)[0]],
}
})
@@ -144,8 +176,8 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
amount = 1
}
type GuildTopData = { ign: string, gexp: string }[]
type NewList = { name: string, value: string, inline: boolean }[]
type GuildTopData = { ign: string; gexp: string }[]
type NewList = { name: string; value: string; inline: boolean }[]
let cacheStatus: boolean
let guildData: GuildTopData = []
@@ -155,14 +187,21 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
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 < allMembersSorted.length; i++) {
const ign = await getIGN(allMembersSorted[i].uuid) as string
const ign = (await getIGN(allMembersSorted[i].uuid)) as string
const gexpUnformatted = allMembersSorted[i].gexp
const gexp = new Intl.NumberFormat("en-US").format(gexpUnformatted)
@@ -172,14 +211,26 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
})
}
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)
}
@@ -196,7 +247,9 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
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) => {
@@ -205,27 +258,38 @@ async function guildTop(interaction: ChatInputCommandInteraction): Promise<void>
newList[index] = {
name: "",
value: item.join("\n"),
inline: true
inline: true,
}
})
const footerText = interaction.guild ? interaction.guild.name : interaction.user.username
const footerIcon = interaction.guild ? interaction.guild.iconURL({ forceStatic: false }) : interaction.user.avatarURL({ forceStatic: false })
const footerText = interaction.guild
? interaction.guild.name
: interaction.user.username
const footerIcon = interaction.guild
? interaction.guild.iconURL({ forceStatic: false })
: interaction.user.avatarURL({ forceStatic: false })
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: footerText + " | " + devMessage + cacheStatusText,
icon_url: footerIcon!
}
}]
embeds: [
{
title: "Top members of " + guildName,
description:
"**Total daily GEXP:** `" +
gexpToday +
"`\n" +
"**Average guild memeber GEXP:** `" +
averageGuildMemberGEXP +
"`",
color: embedColor,
fields: newList,
footer: {
text: footerText + " | " + devMessage + cacheStatusText,
icon_url: footerIcon!,
},
},
],
})
}
export = guildTop
export = guildTop