Converted main codebase to typescript
Signed-off-by: Taken <taken@mairimashita.org>
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
const { getUUID, getIGN, getPlayer, getGuild, guildLevel } = require("../../utils/utils.js")
|
||||
const { color, devMessage } = require("../../../config/options.json")
|
||||
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"
|
||||
|
||||
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
||||
|
||||
async function guildInfo(interaction) {
|
||||
async function guildInfo(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||
await interaction.deferReply()
|
||||
|
||||
const query = interaction.options.getString("query")
|
||||
const query = interaction.options.getString("query")!
|
||||
const type = interaction.options.getString("type") || "ign"
|
||||
const embedColor = Number(color.replace("#", "0x"))
|
||||
let guild
|
||||
let guild: GuildData | null
|
||||
|
||||
if (type === "ign") {
|
||||
await interaction.editReply({
|
||||
@@ -103,14 +103,14 @@ async function guildInfo(interaction) {
|
||||
}
|
||||
}
|
||||
|
||||
const guildName = guild.name
|
||||
const guildCreatedMS = guild.created
|
||||
const guildName = guild!.name
|
||||
const guildCreatedMS = guild!.created
|
||||
const guildCreated = new Date(guildCreatedMS)
|
||||
const guildTag = guild.tag
|
||||
const guildExpUnformatted = guild.exp
|
||||
const guildTag = guild!.tag
|
||||
const guildExpUnformatted = guild!.exp
|
||||
const guildExp = new Intl.NumberFormat("en-US").format(guildExpUnformatted)
|
||||
const guildLvl = guildLevel(guildExpUnformatted)
|
||||
const guildMembers = guild.members
|
||||
const guildMembers = guild!.members
|
||||
|
||||
const guildCreatedDate = guildCreated.getDate()
|
||||
const guildCreatedMonth = guildCreated.getMonth() + 1
|
||||
@@ -126,9 +126,9 @@ async function guildInfo(interaction) {
|
||||
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 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)
|
||||
@@ -143,7 +143,7 @@ async function guildInfo(interaction) {
|
||||
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({ dynamic: true }) : interaction.user.avatarURL({ dynamic: true })
|
||||
const footerIcon = interaction.guild ? interaction.guild.iconURL({ forceStatic: false }) : interaction.user.avatarURL({ forceStatic: false })
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
@@ -171,10 +171,10 @@ async function guildInfo(interaction) {
|
||||
color: embedColor,
|
||||
footer: {
|
||||
text: footerText + " | " + devMessage,
|
||||
icon_url: footerIcon
|
||||
icon_url: footerIcon!
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { guildInfo }
|
||||
export = guildInfo
|
||||
@@ -1,12 +1,11 @@
|
||||
const { getUUID, getPlayer, getGuild, getHeadURL } = require("../../utils/utils.js")
|
||||
const { color, devMessage } = require("../../../config/options.json")
|
||||
import { getUUID, getPlayer, getGuild, getHeadURL } from "../../utils/Hypixel"
|
||||
import { color, devMessage } from "../../../config/options.json"
|
||||
import { ChatInputCommandInteraction } from "discord.js"
|
||||
|
||||
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
||||
|
||||
async function guildMember(interaction) {
|
||||
async function guildMember(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||
await interaction.deferReply()
|
||||
|
||||
const ign = interaction.options.getString("ign")
|
||||
const ign = interaction.options.getString("ign")!
|
||||
const embedColor = Number(color.replace("#", "0x"))
|
||||
|
||||
await interaction.editReply({
|
||||
@@ -45,11 +44,11 @@ async function guildMember(interaction) {
|
||||
description: "This user never logged on to hypixel",
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
url: head,
|
||||
url: head!,
|
||||
},
|
||||
footer: {
|
||||
text: interaction?.guild.name || interaction.user.username + " | " + devMessage,
|
||||
icon_url: interaction?.guild.iconURL({ dynamic: true }) || interaction.user.avatarURL({ dynamic: true }),
|
||||
text: interaction.guild!.name + " | " + devMessage,
|
||||
icon_url: interaction.guild!.iconURL({ forceStatic: false })!
|
||||
},
|
||||
},
|
||||
],
|
||||
@@ -88,11 +87,11 @@ async function guildMember(interaction) {
|
||||
description: "This user is not in a guild",
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
url: head,
|
||||
url: head!,
|
||||
},
|
||||
footer: {
|
||||
text: interaction.guild.name + " | " + devMessage,
|
||||
icon_url: interaction.guild.iconURL({ dynamic: true }),
|
||||
text: interaction.guild!.name + " | " + devMessage,
|
||||
icon_url: interaction.guild!.iconURL({ forceStatic: false })!,
|
||||
},
|
||||
}],
|
||||
})
|
||||
@@ -104,8 +103,8 @@ async function guildMember(interaction) {
|
||||
|
||||
const guildMembers = guild.members
|
||||
const guildMember = guildMembers.find((member) => member.uuid === uuid)
|
||||
const guildRank = guildMember.rank
|
||||
const memberGexp = guildMember.expHistory
|
||||
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"
|
||||
})
|
||||
@@ -115,7 +114,7 @@ async function guildMember(interaction) {
|
||||
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 guildMemberJoinDate = guildMemberJoinTime.getDate()
|
||||
const guildMemberJoinMonth = guildMemberJoinTime.getMonth() + 1
|
||||
@@ -133,7 +132,7 @@ async function guildMember(interaction) {
|
||||
guildMemberJoinSeconds
|
||||
|
||||
const footerText = interaction.guild ? interaction.guild.name : interaction.user.username
|
||||
const footerIcon = interaction.guild ? interaction.guild.iconURL({ dynamic: true }) : interaction.user.avatarURL({ dynamic: true })
|
||||
const footerIcon = interaction.guild ? interaction.guild.iconURL({ forceStatic: false }) : interaction.user.avatarURL({ forceStatic: false })
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
@@ -142,7 +141,7 @@ async function guildMember(interaction) {
|
||||
"**Guild Rank:** `" + guildRank + "`\n",
|
||||
color: embedColor,
|
||||
thumbnail: {
|
||||
url: head,
|
||||
url: head!,
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
@@ -161,10 +160,10 @@ async function guildMember(interaction) {
|
||||
],
|
||||
footer: {
|
||||
text: footerText + " | " + devMessage,
|
||||
icon_url: footerIcon
|
||||
icon_url: footerIcon!
|
||||
},
|
||||
}],
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { guildMember }
|
||||
export = guildMember
|
||||
@@ -1,20 +1,19 @@
|
||||
const { getUUID, getPlayer, getGuild, getIGN } = require("../../utils/utils.js")
|
||||
const { color, devMessage } = require("../../../config/options.json")
|
||||
const { ChannelType } = require("discord.js")
|
||||
const { redis } = require("../../utils/redis.js")
|
||||
import { getUUID, getPlayer, getGuild, getIGN } from "../../utils/Hypixel"
|
||||
import { color, devMessage } from "../../../config/options.json"
|
||||
import { ChannelType, ChatInputCommandInteraction } from "discord.js"
|
||||
import { redis } from "../../utils/Redis"
|
||||
import { GuildData } from "../../interfaces/Guild"
|
||||
|
||||
/** @param { import('discord.js').ChatInputCommandInteraction } interaction */
|
||||
|
||||
async function guildTop(interaction) {
|
||||
async function guildTop(interaction: ChatInputCommandInteraction): Promise<void> {
|
||||
await interaction.deferReply()
|
||||
|
||||
const query = interaction.options.getString("query")
|
||||
const query = interaction.options.getString("query")!
|
||||
const type = interaction.options.getString("type") || "ign"
|
||||
let amount = interaction.options.getNumber("amount") || 10
|
||||
const embedColor = Number(color.replace("#", "0x"))
|
||||
let guild
|
||||
let guild: GuildData | null
|
||||
|
||||
if (interaction.channel.type === ChannelType.DM) {
|
||||
if (interaction.channel!.type === ChannelType.DM) {
|
||||
interaction.editReply({
|
||||
embeds: [{
|
||||
description: "You can't use this command in DMs!",
|
||||
@@ -116,9 +115,9 @@ async function guildTop(interaction) {
|
||||
}
|
||||
}
|
||||
|
||||
const guildName = guild.name
|
||||
const guildMembers = guild.members
|
||||
const guildId = guild._id
|
||||
const guildName = guild!.name
|
||||
const guildMembers = guild!.members
|
||||
const guildId = guild!._id
|
||||
|
||||
const cachedData = await redis.get("guildTop+" + guildId)
|
||||
|
||||
@@ -145,9 +144,12 @@ async function guildTop(interaction) {
|
||||
amount = 1
|
||||
}
|
||||
|
||||
let cacheStatus
|
||||
let guildData = []
|
||||
const fieldsValueRaw = []
|
||||
type GuildTopData = { ign: string, gexp: string }[]
|
||||
type NewList = { name: string, value: string, inline: boolean }[]
|
||||
|
||||
let cacheStatus: boolean
|
||||
let guildData: GuildTopData = []
|
||||
const fieldsValueRaw: string[] = []
|
||||
const allMembersSorted = allMembersDailyGEXP.sort((a, b) => b.gexp - a.gexp)
|
||||
|
||||
if (!cachedData) {
|
||||
@@ -160,7 +162,7 @@ async function guildTop(interaction) {
|
||||
})
|
||||
|
||||
for (let i = 0; i < allMembersSorted.length; i++) {
|
||||
const ign = await getIGN(allMembersSorted[i].uuid)
|
||||
const ign = await getIGN(allMembersSorted[i].uuid) as string
|
||||
const gexpUnformatted = allMembersSorted[i].gexp
|
||||
const gexp = new Intl.NumberFormat("en-US").format(gexpUnformatted)
|
||||
|
||||
@@ -195,7 +197,7 @@ async function guildTop(interaction) {
|
||||
}
|
||||
|
||||
const list = Array.from({ length: sliceSize }, (_, i) => fieldsValueRaw.slice(i * sliceSize, (i + 1) * sliceSize))
|
||||
const newList = []
|
||||
const newList: NewList = []
|
||||
|
||||
list.forEach((item, index) => {
|
||||
if (item.length === 0) return
|
||||
@@ -208,7 +210,7 @@ async function guildTop(interaction) {
|
||||
})
|
||||
|
||||
const footerText = interaction.guild ? interaction.guild.name : interaction.user.username
|
||||
const footerIcon = interaction.guild ? interaction.guild.iconURL({ dynamic: true }) : interaction.user.avatarURL({ dynamic: true })
|
||||
const footerIcon = interaction.guild ? interaction.guild.iconURL({ forceStatic: false }) : interaction.user.avatarURL({ forceStatic: false })
|
||||
const cacheStatusText = cacheStatus ? " | [Cache]" : ""
|
||||
|
||||
await interaction.editReply({
|
||||
@@ -220,10 +222,10 @@ async function guildTop(interaction) {
|
||||
fields: newList,
|
||||
footer: {
|
||||
text: footerText + " | " + devMessage + cacheStatusText,
|
||||
icon_url: footerIcon
|
||||
icon_url: footerIcon!
|
||||
}
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { guildTop }
|
||||
export = guildTop
|
||||
Reference in New Issue
Block a user