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

@@ -1,9 +1,17 @@
import { getUUID, getIGN, getPlayer, getGuild, guildLevel } from "../../utils/Hypixel"
import {
getUUID,
getIGN,
getPlayer,
getGuild,
guildLevel,
} from "../../utils/Hypixel"
import { color, devMessage } from "../../../config/options.json"
import { ChatInputCommandInteraction } from "discord.js"
import { GuildData } from "../../interfaces/Guild"
async function guildInfo(interaction: ChatInputCommandInteraction): Promise<void> {
async function guildInfo(
interaction: ChatInputCommandInteraction,
): Promise<void> {
await interaction.deferReply()
const query = interaction.options.getString("query")!
@@ -13,91 +21,111 @@ async function guildInfo(interaction: ChatInputCommandInteraction): Promise<void
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
}
@@ -119,62 +147,105 @@ async function guildInfo(interaction: ChatInputCommandInteraction): Promise<void
const guildCreatedMinute = guildCreated.getMinutes()
const guildCreatedSecond = guildCreated.getSeconds()
const guildCreatedTime = guildCreatedDate + "." +
guildCreatedMonth + "." +
guildCreatedYear + " " +
guildCreatedHour + ":" +
guildCreatedMinute + ":" +
const guildCreatedTime =
guildCreatedDate +
"." +
guildCreatedMonth +
"." +
guildCreatedYear +
" " +
guildCreatedHour +
":" +
guildCreatedMinute +
":" +
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 guildRanksUnsorted = guild!.ranks.sort((a, b) => b.priority - a.priority)
const guildRanks = guildRanksUnsorted.map((r) => "**➺ " + r.name + "** `[" + r.tag + "]`").join("\n")
const guildRanksUnsorted = guild!.ranks.sort(
(a, b) => b.priority - a.priority,
)
const guildRanks = guildRanksUnsorted
.map(r => "**➺ " + r.name + "** `[" + r.tag + "]`")
.join("\n")
const allGuildMembersWeeklyXP = guildMembers.map(member => member.expHistory)
const guildMembersWeeklyXP = allGuildMembersWeeklyXP.map((member) => {
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,
)
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 })
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
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: footerText + " | " + devMessage,
icon_url: footerIcon!,
},
{
name: "**GEXP**",
value: "**➺ Total weekly GEXP:** `" + totalGuildMembersWeeklyXP + "`\n" +
"**➺ Daily avarage:** `" + averageGuildMembersWeeklyXP + "`\n" +
"**➺ Total GEXP:** `" + guildExp + "`"
},
{
name: "**Guild Created**",
value: "**➺ **`" + guildCreatedTime + "`"
}
],
color: embedColor,
footer: {
text: footerText + " | " + devMessage,
icon_url: footerIcon!
}
}]
},
],
})
}
export = guildInfo
export = guildInfo

View File

@@ -2,17 +2,21 @@ import { getUUID, getPlayer, getGuild, getHeadURL } from "../../utils/Hypixel"
import { color, devMessage } from "../../../config/options.json"
import { ChatInputCommandInteraction } from "discord.js"
async function guildMember(interaction: ChatInputCommandInteraction): Promise<void> {
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)
@@ -29,10 +33,12 @@ async function guildMember(interaction: ChatInputCommandInteraction): Promise<vo
}
await interaction.editReply({
embeds: [{
description: "Fetching your player data...",
color: embedColor
}]
embeds: [
{
description: "Fetching your player data...",
color: embedColor,
},
],
})
const head = await getHeadURL(ign)
@@ -48,7 +54,9 @@ async function guildMember(interaction: ChatInputCommandInteraction): Promise<vo
},
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL({ forceStatic: false })!
icon_url: interaction.guild!.iconURL({
forceStatic: false,
})!,
},
},
],
@@ -74,26 +82,32 @@ async function guildMember(interaction: ChatInputCommandInteraction): Promise<vo
}
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!,
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({
forceStatic: false,
})!,
},
},
footer: {
text: interaction.guild!.name + " | " + devMessage,
icon_url: interaction.guild!.iconURL({ forceStatic: false })!,
},
}],
],
})
return
}
@@ -102,17 +116,34 @@ async function guildMember(interaction: ChatInputCommandInteraction): Promise<vo
const guildTag = " [" + guild.tag + "]" ?? ""
const guildMembers = guild.members
const guildMember = guildMembers.find((member) => member.uuid === uuid)
const guildMember = guildMembers.find(member => member.uuid === uuid)
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"
const allDaysGexp = Object.keys(memberGexp).map(key => {
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)
@@ -124,46 +155,67 @@ async function guildMember(interaction: ChatInputCommandInteraction): Promise<vo
const guildMemberJoinSeconds = guildMemberJoinTime.getSeconds()
const guildMemberJoin =
guildMemberJoinDate + "." +
guildMemberJoinMonth + "." +
guildMemberJoinYear + " " +
guildMemberJoinHours + ":" +
guildMemberJoinMinutes + ":" +
guildMemberJoinDate +
"." +
guildMemberJoinMonth +
"." +
guildMemberJoinYear +
" " +
guildMemberJoinHours +
":" +
guildMemberJoinMinutes +
":" +
guildMemberJoinSeconds
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 })
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,
},
{
name: "**Weekly GEXP**",
value:
"**➺ Total:** `" +
totalWeeklyGexp +
"`\n" +
"**➺ Daily avarage:** `" +
averageWeeklyGexp +
"`",
},
{
name: "**Join date**",
value: "**➺ **`" + guildMemberJoin + "`",
},
],
footer: {
text: footerText + " | " + devMessage,
icon_url: footerIcon!,
},
},
fields: [
{
name: "**Daily GEXP**",
value: expValue,
},
{
name: "**Weekly GEXP**",
value: "**➺ Total:** `" + totalWeeklyGexp + "`\n" +
"**➺ Daily avarage:** `" + averageWeeklyGexp + "`",
},
{
name: "**Join date**",
value: "**➺ **`" + guildMemberJoin + "`",
},
],
footer: {
text: footerText + " | " + devMessage,
icon_url: footerIcon!
},
}],
],
})
}
export = guildMember
export = guildMember

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