Converted main codebase to typescript
Signed-off-by: Taken <taken@mairimashita.org>
This commit is contained in:
@@ -1,22 +1,12 @@
|
||||
const { REST, Routes } = require("discord.js")
|
||||
const log = require("log-beautify")
|
||||
const fs = require("fs")
|
||||
require("dotenv").config()
|
||||
const token = process.env.DEVTOKEN
|
||||
const clientId = process.env.DEVID
|
||||
const guildId = process.env.GUILDID
|
||||
|
||||
log.useSymbols = false
|
||||
log.setColors({
|
||||
newCmds: "#b4befe",
|
||||
currentCmds: "#f38ba8"
|
||||
})
|
||||
import { Command } from "../interfaces"
|
||||
import config from "./Config"
|
||||
import { REST, RESTGetAPIApplicationGuildCommandResult, RESTPutAPIApplicationGuildCommandsJSONBody, Routes } from "discord.js"
|
||||
import fs = require("fs")
|
||||
|
||||
async function autoDeployCommands() {
|
||||
const commands = []
|
||||
const commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(".js"))
|
||||
const contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(".js"))
|
||||
const commandsTesting = fs.readdirSync("./src/commands-testing/").filter(file => file.endsWith(".js"))
|
||||
const commandFiles = fs.readdirSync("./dist/src/commands/").filter(file => file.endsWith(".js"))
|
||||
const contentMenuCommands = fs.readdirSync("./dist/src/commands-contextmenu/").filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`)
|
||||
@@ -25,23 +15,17 @@ async function autoDeployCommands() {
|
||||
}
|
||||
}
|
||||
for (const file of contentMenuCommands) {
|
||||
const command = require(`../commands-contextmenu/${file}`)
|
||||
if (command.dev) {
|
||||
commands.push(command.data.toJSON())
|
||||
}
|
||||
}
|
||||
for (const file of commandsTesting) {
|
||||
const command = require(`../commands-testing/${file}`)
|
||||
const command: Command = require(`../commands-contextmenu/${file}`)
|
||||
if (command.dev) {
|
||||
commands.push(command.data.toJSON())
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST({ version: "10" }).setToken(token)
|
||||
const rest = new REST({ version: "10" }).setToken(config.dev.devtoken)
|
||||
|
||||
const currentCommands = await rest.get(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
)
|
||||
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
|
||||
) as RESTGetAPIApplicationGuildCommandResult[]
|
||||
|
||||
const currentCommandsInfo = currentCommands.map(command => {
|
||||
return {
|
||||
@@ -67,23 +51,23 @@ async function autoDeployCommands() {
|
||||
}).join("\n")
|
||||
|
||||
if (JSON.stringify(sortedNewCommandsInfo) === JSON.stringify(sortedCurrentCommandsInfo)) {
|
||||
log.success("Commands are the same, skipping deploy.")
|
||||
log.newCmds(newCmds)
|
||||
console.log("Commands are the same, skipping deploy.")
|
||||
console.log(newCmds)
|
||||
return
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
log.warning("Commands are different, starting deploy.")
|
||||
log.currentCmds(currentCmds)
|
||||
console.log("Commands are different, starting deploy.")
|
||||
console.log(currentCmds)
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands.`)
|
||||
|
||||
const data = await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
|
||||
{ body: commands },
|
||||
)
|
||||
) as RESTPutAPIApplicationGuildCommandsJSONBody[]
|
||||
|
||||
log.newCmds(newCmds)
|
||||
console.log(newCmds)
|
||||
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
@@ -91,4 +75,4 @@ async function autoDeployCommands() {
|
||||
})()
|
||||
}
|
||||
|
||||
module.exports = { autoDeployCommands }
|
||||
export { autoDeployCommands }
|
||||
14
src/utils/Client.ts
Normal file
14
src/utils/Client.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Client, Collection } from "discord.js"
|
||||
import { Command } from "../interfaces"
|
||||
import { ContextMenu } from "../interfaces"
|
||||
import { Button } from "../interfaces"
|
||||
import { Modal } from "../interfaces"
|
||||
import { Autocomplete } from "../interfaces"
|
||||
|
||||
export class ExtendedClient extends Client {
|
||||
commands: Collection<string, Command>= new Collection()
|
||||
contextmenus: Collection<string, ContextMenu>= new Collection()
|
||||
buttons: Collection<string, Button>= new Collection()
|
||||
modals: Collection<string, Modal>= new Collection()
|
||||
autocomplete: Collection<string, Autocomplete>= new Collection()
|
||||
}
|
||||
20
src/utils/Config.ts
Normal file
20
src/utils/Config.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Config } from "../interfaces"
|
||||
import "dotenv/config"
|
||||
|
||||
const config: Config = {
|
||||
prod: {
|
||||
token: process.env.TOKEN!,
|
||||
mongoURI: process.env.MONGOURI!,
|
||||
dev: process.env.DEV!,
|
||||
hypixelapikey: process.env.HYPIXELAPIKEY!,
|
||||
redisURI: process.env.REDISURI!
|
||||
},
|
||||
dev: {
|
||||
devtoken: process.env.DEVTOKEN!,
|
||||
clientid: process.env.CLIENTID!,
|
||||
devid: process.env.DEVID!,
|
||||
guildid: process.env.GUILDID!,
|
||||
}
|
||||
}
|
||||
|
||||
export default config
|
||||
16
src/utils/Events.ts
Normal file
16
src/utils/Events.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ExtendedClient as Client } from "./Client"
|
||||
import { loadButtonEvents } from "./eventHandlers/button"
|
||||
import { loadSlashCommandsEvents } from "./eventHandlers/command"
|
||||
import { loadContextMenuEvents } from "./eventHandlers/contextmenu"
|
||||
import { loadModalEvents } from "./eventHandlers/modal"
|
||||
import { loadEvents } from "./eventHandlers/events"
|
||||
import { loadAutocompleteEvents } from "./eventHandlers/autocomplete"
|
||||
|
||||
export function loadAllEvents(client: Client) {
|
||||
loadEvents(client)
|
||||
loadButtonEvents(client)
|
||||
loadSlashCommandsEvents(client)
|
||||
loadContextMenuEvents(client)
|
||||
loadModalEvents(client)
|
||||
loadAutocompleteEvents(client)
|
||||
}
|
||||
6
src/utils/Hypixel.ts
Normal file
6
src/utils/Hypixel.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export { skywarsLevel } from "./functions/skywars"
|
||||
export { bedwarsLevel } from "./functions/bedwars"
|
||||
export { hypixelLevel } from "./functions/hypixel"
|
||||
export { formatUuid } from "./functions/uuid"
|
||||
export { guildLevel, scaledGEXP } from "./functions/guild"
|
||||
export { getUUID, getIGN, getPlayer, getGuild, getHeadURL } from "./functions/account"
|
||||
6
src/utils/Redis.ts
Normal file
6
src/utils/Redis.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Redis } from "ioredis"
|
||||
import config from "./Config"
|
||||
|
||||
const redis = new Redis(config.prod.redisURI)
|
||||
|
||||
export { redis }
|
||||
@@ -1,15 +0,0 @@
|
||||
const { loadButtonEvents } = require("./eventHandlers/button.js")
|
||||
const { loadSlashCommandsEvents } = require("./eventHandlers/command.js")
|
||||
const { loadContextMenuEvents } = require("./eventHandlers/contextmenu.js")
|
||||
const { loadModalEvents } = require("./eventHandlers/modal.js")
|
||||
const { loadEvents } = require("./eventHandlers/events.js")
|
||||
const { loadAutocompleteEvents } = require("./eventHandlers/autocomplete.js")
|
||||
|
||||
module.exports = {
|
||||
loadSlashCommandsEvents,
|
||||
loadButtonEvents,
|
||||
loadContextMenuEvents,
|
||||
loadModalEvents,
|
||||
loadEvents,
|
||||
loadAutocompleteEvents
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
const { Events, Collection } = require("discord.js")
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadAutocompleteEvents(client) {
|
||||
client.autocomplete = new Collection()
|
||||
|
||||
const autocompletePath = path.join(__dirname, "..", "..", "events", "autocomplete")
|
||||
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of autocompleteFiles) {
|
||||
|
||||
const filePath = path.join(autocompletePath, file)
|
||||
const autocomplete = require(filePath)
|
||||
|
||||
if ("name" in autocomplete && "execute" in autocomplete && autocomplete.type === "autocomplete") {
|
||||
client.autocomplete.set(autocomplete.name, autocomplete)
|
||||
} else {
|
||||
console.log(`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`)
|
||||
}
|
||||
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if (!interaction.isAutocomplete()) return
|
||||
|
||||
const autocomplete = interaction.client.autocomplete.get(interaction.commandName)
|
||||
|
||||
if (!autocomplete) {
|
||||
console.error(`No autocomplete matching ${interaction.commandName} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await autocomplete.execute(interaction, client)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
await interaction.respond({
|
||||
content: "There was an error while executing this autocomplete!",
|
||||
ephemeral: true
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadAutocompleteEvents }
|
||||
41
src/utils/eventHandlers/autocomplete.ts
Normal file
41
src/utils/eventHandlers/autocomplete.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { Autocomplete } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
|
||||
function loadAutocompleteEvents(client: Client) {
|
||||
const autocompletePath = path.join(__dirname, "..", "..", "events", "autocomplete")
|
||||
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of autocompleteFiles) {
|
||||
|
||||
const filePath = path.join(autocompletePath, file)
|
||||
const autocomplete: Autocomplete = require(filePath)
|
||||
|
||||
if ("name" in autocomplete && "execute" in autocomplete && autocomplete.type === "autocomplete") {
|
||||
client.autocomplete.set(autocomplete.name, autocomplete)
|
||||
} else {
|
||||
console.log(`[WARNING] The autocomplete at ${filePath} is missing a required "name", "execute" or "type" property.`)
|
||||
}
|
||||
}
|
||||
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if (!interaction.isAutocomplete()) return
|
||||
|
||||
const autocomplete = client.autocomplete.get(interaction.commandName)
|
||||
|
||||
if (!autocomplete) {
|
||||
console.error(`No autocomplete matching ${interaction.commandName} was found.`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await autocomplete.execute(interaction)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export { loadAutocompleteEvents }
|
||||
@@ -1,19 +1,17 @@
|
||||
const { Events, Collection } = require("discord.js")
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadButtonEvents(client) {
|
||||
client.buttons = new Collection()
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { Button } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
|
||||
function loadButtonEvents(client: Client) {
|
||||
const btnPath = path.join(__dirname, "..", "..", "events", "buttons")
|
||||
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of btnFiles) {
|
||||
|
||||
const filePath = path.join(btnPath, file)
|
||||
const btn = require(filePath)
|
||||
const btn: Button = require(filePath)
|
||||
|
||||
if ("name" in btn && "execute" in btn && btn.type === "button") {
|
||||
client.buttons.set(btn.name, btn)
|
||||
@@ -25,8 +23,8 @@ function loadButtonEvents(client) {
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if (!interaction.isButton())
|
||||
return
|
||||
|
||||
const button = interaction.client.buttons.get(interaction.customId)
|
||||
|
||||
const button = client.buttons.get(interaction.customId)
|
||||
|
||||
if (!button) {
|
||||
console.error(`No event matching ${interaction.customId} was found.`)
|
||||
@@ -45,4 +43,4 @@ function loadButtonEvents(client) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { loadButtonEvents }
|
||||
export { loadButtonEvents }
|
||||
@@ -1,35 +1,17 @@
|
||||
const { Events, Collection } = require("discord.js")
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadSlashCommandsEvents(client) {
|
||||
client.commands = new Collection()
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { Command } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
|
||||
function loadSlashCommandsEvents(client: Client) {
|
||||
const cmdPath = path.join(__dirname, "..", "..", "commands")
|
||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of cmdFiles) {
|
||||
|
||||
const filePath = path.join(cmdPath, file)
|
||||
const cmd = require(filePath)
|
||||
|
||||
if ("data" in cmd && "execute" in cmd && cmd.type === "slash") {
|
||||
client.commands.set(cmd.data.name, cmd)
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`)
|
||||
}
|
||||
}
|
||||
|
||||
//! commands testing
|
||||
const cmdTestPath = path.join(__dirname, "..", "..", "commands-testing")
|
||||
const cmdTestFiles = fs.readdirSync(cmdTestPath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of cmdTestFiles) {
|
||||
|
||||
const filePath = path.join(cmdTestPath, file)
|
||||
const cmd = require(filePath)
|
||||
const cmd: Command = require(filePath)
|
||||
|
||||
if ("data" in cmd && "execute" in cmd && cmd.type === "slash") {
|
||||
client.commands.set(cmd.data.name, cmd)
|
||||
@@ -43,7 +25,7 @@ function loadSlashCommandsEvents(client) {
|
||||
if (!interaction.isChatInputCommand())
|
||||
return
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName)
|
||||
const command = client.commands.get(interaction.commandName)
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`)
|
||||
@@ -62,4 +44,4 @@ function loadSlashCommandsEvents(client) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { loadSlashCommandsEvents }
|
||||
export { loadSlashCommandsEvents }
|
||||
@@ -1,20 +1,20 @@
|
||||
const { Events } = require("discord.js")
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { ContextMenu } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadContextMenuEvents(client) {
|
||||
function loadContextMenuEvents(client: Client) {
|
||||
const contextMenuPath = path.join(__dirname, "..", "..", "commands-contextmenu")
|
||||
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of contextMenuFiles) {
|
||||
|
||||
const filePath = path.join(contextMenuPath, file)
|
||||
const cmd = require(filePath)
|
||||
const cmd: ContextMenu = require(filePath)
|
||||
|
||||
if ("data" in cmd && "execute" in cmd && cmd.type === "contextmenu") {
|
||||
client.commands.set(cmd.data.name, cmd)
|
||||
client.contextmenus.set(cmd.data.name, cmd)
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`)
|
||||
}
|
||||
@@ -25,7 +25,7 @@ function loadContextMenuEvents(client) {
|
||||
if (!interaction.isContextMenuCommand())
|
||||
return
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName)
|
||||
const command = client.contextmenus.get(interaction.commandName)
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`)
|
||||
@@ -44,4 +44,4 @@ function loadContextMenuEvents(client) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { loadContextMenuEvents }
|
||||
export { loadContextMenuEvents }
|
||||
@@ -1,24 +0,0 @@
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadEvents(client) {
|
||||
const serverDir = path.join(__dirname, "..", "..", "events", "server")
|
||||
const eventDirs = fs.readdirSync(serverDir)
|
||||
for (const eventDir of eventDirs) {
|
||||
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir))
|
||||
for (const eventFile of eventFiles) {
|
||||
const eventPath = path.join(serverDir, eventDir, eventFile)
|
||||
const event = require(eventPath)
|
||||
if ("name" in event && "execute" in event && "event" in event && event.type === "event") {
|
||||
client.on(event.event, event.execute)
|
||||
} else {
|
||||
console.log(`[WARNING] The event at ${eventPath} is missing a required "name", "execute", "type" or "event" property.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = { loadEvents }
|
||||
20
src/utils/eventHandlers/events.ts
Normal file
20
src/utils/eventHandlers/events.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { Event } from "../../interfaces"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
|
||||
function loadEvents(client: Client) {
|
||||
const serverDir = path.join(__dirname, "..", "..", "events", "server")
|
||||
const eventDirs = fs.readdirSync(serverDir)
|
||||
for (const eventDir of eventDirs) {
|
||||
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir))
|
||||
for (const eventFile of eventFiles) {
|
||||
const eventPath = path.join(serverDir, eventDir, eventFile)
|
||||
const event: Event = require(eventPath)
|
||||
client.on(event.event, event.execute)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export { loadEvents }
|
||||
@@ -1,19 +1,17 @@
|
||||
const { Events, Collection } = require("discord.js")
|
||||
const path = require("path")
|
||||
const fs = require("fs")
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadModalEvents(client) {
|
||||
client.modals = new Collection()
|
||||
import { ExtendedClient as Client } from "../Client"
|
||||
import { Modal } from "../../interfaces"
|
||||
import { Events } from "discord.js"
|
||||
import path = require("path")
|
||||
import fs = require("fs")
|
||||
|
||||
function loadModalEvents(client: Client) {
|
||||
const modalPath = path.join(__dirname, "..", "..", "events", "modals")
|
||||
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(".js"))
|
||||
|
||||
for (const file of modalFiles) {
|
||||
|
||||
const filePath = path.join(modalPath, file)
|
||||
const modal = require(filePath)
|
||||
const modal: Modal = require(filePath)
|
||||
|
||||
if ("name" in modal && "execute" in modal && modal.type === "modal") {
|
||||
client.modals.set(modal.name, modal)
|
||||
@@ -26,7 +24,7 @@ function loadModalEvents(client) {
|
||||
if (!interaction.isModalSubmit())
|
||||
return
|
||||
|
||||
const modal = interaction.client.modals.get(interaction.customId)
|
||||
const modal = client.modals.get(interaction.customId)
|
||||
|
||||
if (!modal) {
|
||||
console.error(`No modal matching ${interaction.customId} was found.`)
|
||||
@@ -45,4 +43,4 @@ function loadModalEvents(client) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { loadModalEvents }
|
||||
export { loadModalEvents }
|
||||
@@ -1,31 +1,35 @@
|
||||
const fetch = require("axios")
|
||||
const apikey = process.env.HYPIXELAPIKEY
|
||||
import fetch from "axios"
|
||||
import config from "../Config"
|
||||
import { Profile, Profile2 } from "../../typings"
|
||||
import { Player, PlayerData } from "../../interfaces"
|
||||
import { Guild, GuildData } from "../../interfaces"
|
||||
const apikey = config.prod.hypixelapikey
|
||||
const mojang = "https://api.mojang.com/users/profiles/minecraft/"
|
||||
const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/"
|
||||
const hypixel = "https://api.hypixel.net/player"
|
||||
const guild = "https://api.hypixel.net/guild"
|
||||
const minotar = "https://minotar.net/helm/"
|
||||
|
||||
async function getUUID(ign) {
|
||||
async function getUUID(ign: string): Promise<string|null> {
|
||||
try {
|
||||
const req = await fetch(mojang + ign)
|
||||
const req: Profile = await fetch(mojang + ign)
|
||||
return req.data.id
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function getIGN(uuid) {
|
||||
async function getIGN(uuid: string): Promise<string|null> {
|
||||
try {
|
||||
const req = await fetch(mojanguuid + uuid)
|
||||
const req: Profile2 = await fetch(mojanguuid + uuid)
|
||||
return req.data.name
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function getPlayer(uuid) {
|
||||
const playerReq = await fetch(hypixel, {
|
||||
async function getPlayer(uuid: string): Promise<PlayerData|null> {
|
||||
const playerReq: Player = await fetch(hypixel, {
|
||||
params: {
|
||||
key: apikey,
|
||||
uuid: uuid
|
||||
@@ -39,10 +43,10 @@ async function getPlayer(uuid) {
|
||||
return playerReq.data.player
|
||||
}
|
||||
|
||||
async function getGuild(query, type) {
|
||||
async function getGuild(query: string, type?: string): Promise<GuildData|null> {
|
||||
const reqType = type ? type : "player"
|
||||
|
||||
const guildReq = await fetch(guild, {
|
||||
const guildReq: Guild = await fetch(guild, {
|
||||
params: {
|
||||
key: apikey,
|
||||
[reqType]: query
|
||||
@@ -56,11 +60,11 @@ async function getGuild(query, type) {
|
||||
return guildReq.data.guild
|
||||
}
|
||||
|
||||
async function getHeadURL(ign) {
|
||||
async function getHeadURL(ign: string): Promise<string|null> {
|
||||
return minotar + ign
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
getUUID,
|
||||
getIGN,
|
||||
getPlayer,
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function getExpForLevel(level) {
|
||||
function getExpForLevel(level: number): number {
|
||||
if (level == 0) return 0
|
||||
|
||||
const respectedLevel = getLevelRespectingPrestige(level)
|
||||
@@ -22,7 +22,7 @@ function getExpForLevel(level) {
|
||||
return 5000
|
||||
}
|
||||
|
||||
function getLevelRespectingPrestige(level) {
|
||||
function getLevelRespectingPrestige(level: number): number {
|
||||
if (level > HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE) {
|
||||
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE
|
||||
}
|
||||
@@ -36,7 +36,7 @@ const EASY_LEVELS_XP = 7000
|
||||
const XP_PER_PRESTIGE = 96 * 5000 + EASY_LEVELS_XP
|
||||
const LEVELS_PER_PRESTIGE = 100
|
||||
const HIGHEST_PRESTIGE = 50
|
||||
function bedwarsLevel(exp) {
|
||||
function bedwarsLevel(exp: number): number {
|
||||
const prestiges = Math.floor(exp / XP_PER_PRESTIGE)
|
||||
let level = prestiges * LEVELS_PER_PRESTIGE
|
||||
let expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE)
|
||||
@@ -52,4 +52,4 @@ function bedwarsLevel(exp) {
|
||||
return level + expWithoutPrestiges / 5000
|
||||
}
|
||||
|
||||
module.exports = { bedwarsLevel }
|
||||
export { bedwarsLevel }
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function guildLevel(exp) {
|
||||
function guildLevel(exp: number): number {
|
||||
const EXP_NEEDED = [
|
||||
100000,
|
||||
150000,
|
||||
@@ -47,10 +47,11 @@ function guildLevel(exp) {
|
||||
/*
|
||||
Code used from the hypixel-guild-bot project https://github.com/SimplyNo/hypixel-guild-bot
|
||||
*/
|
||||
function scaledGEXP(input) {
|
||||
function scaledGEXP(input: number): number {
|
||||
if (input <= 200000) return Number(input)
|
||||
if (input <= 700000) return Number(Math.round(((input - 200000) / 10) + 200000))
|
||||
if (input > 700000) return Number(Math.round(((input - 700000) / 33) + 250000))
|
||||
return 0
|
||||
}
|
||||
|
||||
module.exports = { guildLevel, scaledGEXP }
|
||||
export { guildLevel, scaledGEXP }
|
||||
@@ -8,30 +8,30 @@ const REVERSE_PQ_PREFIX = -(BASE - 0.5 * GROWTH) / GROWTH
|
||||
const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX
|
||||
const GROWTH_DIVIDES_2 = 2 / GROWTH
|
||||
|
||||
function getLevel(exp) {
|
||||
function getLevel(exp: number): number {
|
||||
return exp <= 1 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp))
|
||||
}
|
||||
|
||||
function hypixelLevel(exp) {
|
||||
function hypixelLevel(exp: number): number {
|
||||
return getLevel(exp) + getPercentageToNextLevel(exp)
|
||||
}
|
||||
|
||||
function getTotalExpToLevel(level) {
|
||||
function getTotalExpToLevel(level: number): number {
|
||||
const lv = Math.floor(level); const
|
||||
x0 = getTotalExpToFullLevel(lv)
|
||||
if (level === lv) return x0
|
||||
return (getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0
|
||||
}
|
||||
|
||||
function getTotalExpToFullLevel(level) {
|
||||
function getTotalExpToFullLevel(level: number): number {
|
||||
return (HALF_GROWTH * (level - 2) + BASE) * (level - 1)
|
||||
}
|
||||
|
||||
function getPercentageToNextLevel(exp) {
|
||||
function getPercentageToNextLevel(exp: number): number {
|
||||
const lv = getLevel(exp)
|
||||
const x0 = getTotalExpToLevel(lv)
|
||||
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0)
|
||||
}
|
||||
|
||||
|
||||
module.exports = { hypixelLevel }
|
||||
export { hypixelLevel }
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
Code used from the slothpixel project https://github.com/slothpixel/core
|
||||
*/
|
||||
function skywarsLevel(xp) {
|
||||
function skywarsLevel(xp: number): number {
|
||||
const xps = [0, 20, 70, 150, 250, 500, 1000, 2000, 3500, 6000, 10000, 15000]
|
||||
let exactLevel = 0
|
||||
if (xp >= 15000) {
|
||||
exactLevel = (xp - 15000) / 10000 + 12
|
||||
return exactLevel
|
||||
} else {
|
||||
} else if (xp < 15000) {
|
||||
for (let i = 0; i < xps.length; i++) {
|
||||
if (xp < xps[i]) {
|
||||
exactLevel = i + (xp - xps[i - 1]) / (xps[i] - xps[i - 1])
|
||||
@@ -15,6 +15,8 @@ function skywarsLevel(xp) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
module.exports = { skywarsLevel }
|
||||
export { skywarsLevel }
|
||||
@@ -1,5 +1,5 @@
|
||||
function formatUuid(uuid) {
|
||||
function formatUuid(uuid: string): string {
|
||||
return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5")
|
||||
}
|
||||
|
||||
module.exports = { formatUuid }
|
||||
export { formatUuid }
|
||||
@@ -1,39 +0,0 @@
|
||||
const envars = [
|
||||
"TOKEN",
|
||||
"MONGOURI",
|
||||
"DEV",
|
||||
"HYPIXELAPIKEY",
|
||||
"REDISURI"
|
||||
]
|
||||
const devenvars = [
|
||||
"DEVTOKEN",
|
||||
"CLIENTID",
|
||||
"DEVID",
|
||||
"GUILDID"
|
||||
]
|
||||
|
||||
function init() {
|
||||
if (process.env.NODe_ENV !== "dev") {
|
||||
for (const envar of envars) {
|
||||
if (!process.env[envar]) {
|
||||
console.error(`Missing ${envar} environment variable!`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (const envar of envars) {
|
||||
if (!process.env[envar]) {
|
||||
console.error(`Missing ${envar} environment variable!`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
for (const envar of devenvars) {
|
||||
if (!process.env[envar]) {
|
||||
console.error(`Missing ${envar} environment variable!`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { init }
|
||||
@@ -1,12 +0,0 @@
|
||||
const { loadSlashCommandsEvents, loadContextMenuEvents, loadModalEvents, loadButtonEvents, loadEvents, loadAutocompleteEvents } = require("./eventHandler.js")
|
||||
|
||||
function loadAllEvents(client) {
|
||||
loadSlashCommandsEvents(client)
|
||||
loadAutocompleteEvents(client)
|
||||
loadContextMenuEvents(client)
|
||||
loadButtonEvents(client)
|
||||
loadModalEvents(client)
|
||||
loadEvents(client)
|
||||
}
|
||||
|
||||
module.exports = { loadAllEvents }
|
||||
@@ -1,5 +0,0 @@
|
||||
const { Redis } = require("ioredis")
|
||||
|
||||
const redis = new Redis(process.env.REDISURI)
|
||||
|
||||
module.exports = { redis }
|
||||
@@ -1,20 +0,0 @@
|
||||
const { skywarsLevel } = require("./functions/skywars.js")
|
||||
const { bedwarsLevel } = require("./functions/bedwars.js")
|
||||
const { hypixelLevel } = require("./functions/hypixel.js")
|
||||
const { formatUuid } = require("./functions/uuid.js")
|
||||
const { guildLevel, scaledGEXP } = require("./functions/guild.js")
|
||||
const { getUUID, getIGN, getPlayer, getGuild, getHeadURL } = require("./functions/account.js")
|
||||
|
||||
module.exports = {
|
||||
skywarsLevel,
|
||||
bedwarsLevel,
|
||||
hypixelLevel,
|
||||
guildLevel,
|
||||
scaledGEXP,
|
||||
getUUID,
|
||||
getIGN,
|
||||
getPlayer,
|
||||
getGuild,
|
||||
getHeadURL,
|
||||
formatUuid
|
||||
}
|
||||
Reference in New Issue
Block a user