Fixing formatting

This commit is contained in:
2024-01-21 00:03:19 +01:00
parent 614feeff3e
commit 9ec53882d1
15 changed files with 138 additions and 277 deletions

View File

@@ -10,8 +10,5 @@ export default interface Command {
disabled?: boolean
subcommands?: boolean
data: SlashCommandBuilder
execute: (
interaction: ChatInputCommandInteraction,
client: Client
) => Promise<void>
execute: (interaction: ChatInputCommandInteraction, client: Client) => Promise<void>
}

View File

@@ -1,12 +1,7 @@
import { Command } from "interfaces"
import color from "./functions/colors"
import env from "./Env"
import {
REST,
RESTGetAPIApplicationGuildCommandResult,
RESTPutAPIApplicationGuildCommandsJSONBody,
Routes
} from "discord.js"
import { REST, RESTGetAPIApplicationGuildCommandResult, RESTPutAPIApplicationGuildCommandsJSONBody, Routes } from "discord.js"
import fs from "fs"
type FileType = "js" | "ts"
@@ -16,19 +11,11 @@ export default async function autoDeployCommands(fileType: FileType) {
let contentMenuCommands: string[] = []
if (fileType === "js") {
commandFiles = fs
.readdirSync("./dist/commands/")
.filter(file => file.endsWith(fileType))
contentMenuCommands = fs
.readdirSync("./dist/commands-contextmenu/")
.filter(file => file.endsWith(fileType))
commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType))
contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType))
} else if (fileType === "ts") {
commandFiles = fs
.readdirSync("./src/commands/")
.filter(file => file.endsWith(fileType))
contentMenuCommands = fs
.readdirSync("./src/commands-contextmenu/")
.filter(file => file.endsWith(fileType))
commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType))
contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType))
}
for (const file of commandFiles) {
@@ -70,24 +57,15 @@ export default async function autoDeployCommands(fileType: FileType) {
a.name.localeCompare(b.name)
)
const newCmds = sortedNewCommandsInfo
.map(cmd => {
return " " + cmd.name + " was registered."
})
.join("\n")
const currentCmds = sortedCurrentCommandsInfo
.map(cmd => {
return " " + cmd.name + " was unregistered."
})
.join("\n")
const newCmds = sortedNewCommandsInfo.map(cmd => {
return " " + cmd.name + " was registered."
}).join("\n")
const currentCmds = sortedCurrentCommandsInfo.map(cmd => {
return " " + cmd.name + " was unregistered."
}).join("\n")
if (
JSON.stringify(sortedNewCommandsInfo) ===
JSON.stringify(sortedCurrentCommandsInfo)
) {
console.log(
color("Commands are the same, skipping deploy.", "lavender")
)
if (JSON.stringify(sortedNewCommandsInfo) === JSON.stringify(sortedCurrentCommandsInfo)) {
console.log(color("Commands are the same, skipping deploy.", "lavender"))
console.log(color(newCmds, "lavender"))
return
}
@@ -95,9 +73,7 @@ export default async function autoDeployCommands(fileType: FileType) {
try {
console.log(color("Commands are different, starting deploy.", "red"))
console.log(color(currentCmds, "red"))
console.log(
`Started refreshing ${commands.length} application (/) commands.`
)
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = (await rest.put(
Routes.applicationGuildCommands(env.dev.devid!, env.dev.guildid!),
@@ -106,9 +82,7 @@ export default async function autoDeployCommands(fileType: FileType) {
console.log(color("New commands deployed.", "lavender"))
console.log(color(newCmds, "lavender"))
console.log(
`Successfully reloaded ${data.length} application (/) commands.`
)
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error)
}

View File

@@ -3,7 +3,6 @@ import color from "./functions/colors"
import { Command, ContextMenu, Button, Modal, Autocomplete } from "interfaces"
import env from "./Env"
import autoDeployCommands from "./Autodeploy"
import { loadAllEvents } from "./Events"
export class ExtendedClient extends Client {
commands: Collection<string, Command> = new Collection()
@@ -34,20 +33,15 @@ export class ExtendedClient extends Client {
async start() {
let token: string
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT) {
console.log(
color("Running in development mode. [ts-node]", "lavender")
)
loadAllEvents(this, "ts")
console.log(color("Running in development mode. [ts-node]", "lavender"))
token = env.dev.devtoken!
autoDeployCommands("ts")
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
console.log(color("Running in development mode.", "lavender"))
loadAllEvents(this, "js")
token = env.dev.devtoken!
autoDeployCommands("js")
} else {
console.log(color("Running in production mode.", "green"))
loadAllEvents(this, "js")
token = env.prod.token!
}

View File

@@ -10,16 +10,8 @@ type FileType = "js" | "ts"
const embedColor = Number(color.replace("#", "0x"))
export default function loadAutocompleteEvents(client: Client, ft: FileType) {
const autocompletePath = path.join(
__dirname,
"..",
"..",
"components",
"autocomplete"
)
const autocompleteFiles = fs
.readdirSync(autocompletePath)
.filter(file => file.endsWith(ft))
const autocompletePath = path.join(__dirname, "..", "..", "components", "autocomplete")
const autocompleteFiles = fs.readdirSync(autocompletePath).filter(file => file.endsWith(ft))
for (const file of autocompleteFiles) {
const filePath = path.join(autocompletePath, file)
@@ -43,9 +35,7 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) {
const autocomplete = client.autocomplete.get(interaction.commandName)
if (!autocomplete) {
console.error(
`No autocomplete matching ${interaction.commandName} was found.`
)
console.error(`No autocomplete matching ${interaction.commandName} was found.`)
return
}
@@ -54,21 +44,15 @@ export default function loadAutocompleteEvents(client: Client, ft: FileType) {
} catch (error) {
if (process.env.NODE_ENV !== "dev") {
await logToChannel("error", {
embeds: [
{
title: "Autocomplete error occured",
description: String(error),
color: embedColor,
footer: {
icon_url:
interaction.guild!.iconURL() || undefined,
text:
interaction.user.username +
" | " +
interaction.commandName
}
embeds: [{
title: "Autocomplete error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url: interaction.guild!.iconURL() || undefined,
text: interaction.user.username + " | " + interaction.commandName
}
]
}]
})
}
console.error(error)

View File

@@ -35,9 +35,7 @@ export default function loadButtonEvents(client: Client, ft: FileType) {
const button = client.buttons.get(interaction.customId)
if (!button) {
console.error(
`No event matching ${interaction.customId} was found.`
)
console.error(`No event matching ${interaction.customId} was found.`)
return
}
@@ -46,45 +44,33 @@ export default function loadButtonEvents(client: Client, ft: FileType) {
} catch (error) {
if (process.env.NODE_ENV !== "dev") {
await logToChannel("error", {
embeds: [
{
title: "Button error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url:
interaction.guild!.iconURL() || undefined,
text:
interaction.user.username +
" | " +
interaction.customId
}
embeds: [{
title: "Button error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url: interaction.guild!.iconURL() || undefined,
text: interaction.user.username + " | " + interaction.customId
}
]
}]
})
}
console.error(error)
if (!interaction.deferred) {
await interaction.reply({
embeds: [
{
description:
"There was an error while executing this button!",
color: embedColor
}
],
embeds: [{
description: "There was an error while executing this button!",
color: embedColor
}],
ephemeral: true
})
} else {
await interaction.editReply({
embeds: [
{
description:
"There was an error while executing this button! 2",
color: embedColor
}
]
embeds: [{
description: "There was an error while executing this button! 2",
color: embedColor
}]
})
}
}

View File

@@ -47,45 +47,33 @@ export default function loadSlashCommandsEvents(client: Client, ft: FileType) {
} catch (error) {
if (process.env.NODE_ENV !== "dev") {
await logToChannel("error", {
embeds: [
{
title: "Command error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url:
interaction.guild!.iconURL() || undefined,
text:
interaction.user.username +
" | " +
interaction.commandName
}
embeds: [{
title: "Command error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url: interaction.guild!.iconURL() || undefined,
text: interaction.user.username + " | " + interaction.commandName
}
]
}]
})
}
console.error(error)
if (!interaction.deferred) {
await interaction.reply({
embeds: [
{
description:
"There was an error while executing this command!",
color: embedColor
}
],
embeds: [{
description: "There was an error while executing this command!",
color: embedColor
}],
ephemeral: true
})
} else {
await interaction.editReply({
embeds: [
{
description:
"There was an error while executing this command!",
color: embedColor
}
]
embeds: [{
description: "There was an error while executing this command!",
color: embedColor
}]
})
}
}

View File

@@ -10,15 +10,8 @@ type FileType = "js" | "ts"
const embedColor = Number(color.replace("#", "0x"))
export default function loadContextMenuEvents(client: Client, ft: FileType) {
const contextMenuPath = path.join(
__dirname,
"..",
"..",
"commands-contextmenu"
)
const contextMenuFiles = fs
.readdirSync(contextMenuPath)
.filter(file => file.endsWith(ft))
const contextMenuPath = path.join(__dirname, "..", "..", "commands-contextmenu")
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith(ft))
for (const file of contextMenuFiles) {
const filePath = path.join(contextMenuPath, file)
@@ -43,9 +36,7 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) {
const command = client.contextmenus.get(interaction.commandName)
if (!command) {
console.error(
`No command matching ${interaction.commandName} was found.`
)
console.error(`No command matching ${interaction.commandName} was found.`)
return
}
@@ -54,45 +45,33 @@ export default function loadContextMenuEvents(client: Client, ft: FileType) {
} catch (error) {
if (process.env.NODE_ENV !== "dev") {
await logToChannel("error", {
embeds: [
{
title: "Contextmenu error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url:
interaction.guild!.iconURL() || undefined,
text:
interaction.user.username +
" | " +
interaction.commandName
}
embeds: [{
title: "Contextmenu error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url: interaction.guild!.iconURL() || undefined,
text: interaction.user.username + " | " + interaction.commandName
}
]
}]
})
}
console.error(error)
if (!interaction.deferred) {
await interaction.reply({
embeds: [
{
description:
"There was an error while executing this contextmenu command!",
color: embedColor
}
],
embeds: [{
description: "There was an error while executing this contextmenu command!",
color: embedColor
}],
ephemeral: true
})
} else {
await interaction.editReply({
embeds: [
{
description:
"There was an error while executing this contextmenu command!",
color: embedColor
}
]
embeds: [{
description: "There was an error while executing this contextmenu command!",
color: embedColor
}]
})
}
}

View File

@@ -5,33 +5,20 @@ import { Cron } from "interfaces"
export default function loadCronEvents() {
const cronPath = path.join(__dirname, "..", "..", "events", "cron")
const cronFiles = fs
.readdirSync(cronPath)
.filter(file => file.endsWith(".js"))
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".js"))
for (const file of cronFiles) {
const filePath = path.join(cronPath, file)
const cron: Cron = require(filePath)
const time =
cron.time.seconds +
" " +
cron.time.minutes +
" " +
cron.time.hours +
" " +
cron.time.dayOfMonth +
" " +
cron.time.month +
" " +
cron.time.seconds + " " +
cron.time.minutes + " " +
cron.time.hours + " " +
cron.time.dayOfMonth + " " +
cron.time.month + " " +
cron.time.dayOfWeek
new CronJob(
time,
cron.execute,
cron.onComplete,
cron.start,
cron.timeZone
).start()
new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start()
}
}

View File

@@ -6,9 +6,8 @@ import loadContextMenuEvents from "./contextmenu"
import loadCronEvents from "./cron"
import loadEvents from "./events"
import loadModalEvents from "./modal"
type FileType = "js" | "ts"
export function loadAllEvents(client: Client, ft: FileType) {
export default function loadAllEvents(client: Client, ft: "js" | "ts") {
loadEvents(client)
loadButtonEvents(client, ft)
loadSlashCommandsEvents(client, ft)

View File

@@ -11,9 +11,7 @@ const embedColor = Number(color.replace("#", "0x"))
export default function loadModalEvents(client: Client, ft: FileType) {
const modalPath = path.join(__dirname, "..", "..", "components", "modals")
const modalFiles = fs
.readdirSync(modalPath)
.filter(file => file.endsWith(ft))
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith(ft))
for (const file of modalFiles) {
const filePath = path.join(modalPath, file)
@@ -37,9 +35,7 @@ export default function loadModalEvents(client: Client, ft: FileType) {
const modal = client.modals.get(interaction.customId)
if (!modal) {
console.error(
`No modal matching ${interaction.customId} was found.`
)
console.error(`No modal matching ${interaction.customId} was found.`)
return
}
@@ -48,44 +44,32 @@ export default function loadModalEvents(client: Client, ft: FileType) {
} catch (error) {
if (process.env.NODE_ENV !== "dev") {
await logToChannel("error", {
embeds: [
{
title: "Button error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url:
interaction.guild!.iconURL() || undefined,
text:
interaction.user.username +
" | " +
interaction.customId
}
embeds: [{
title: "Button error occured",
description: "```" + error + "```",
color: embedColor,
footer: {
icon_url: interaction.guild!.iconURL() || undefined,
text: interaction.user.username + " | " + interaction.customId
}
]
}]
})
}
console.error(error)
if (!interaction.deferred) {
await interaction.reply({
embeds: [
{
description:
"There was an error while executing this modal!",
color: embedColor
}
]
embeds: [{
description: "There was an error while executing this modal!",
color: embedColor
}]
})
} else {
await interaction.editReply({
embeds: [
{
description:
"There was an error while executing this modal!",
color: embedColor
}
]
embeds: [{
description: "There was an error while executing this modal!",
color: embedColor
}]
})
}
}

View File

@@ -8,7 +8,7 @@ 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/"
type GuildQuerqType = "player" | "name" | "id"
type GuildQueryType = "player" | "name" | "id"
type Profile = {
data: {
@@ -47,8 +47,10 @@ async function getIGN(uuid: string): Promise<string | null> {
async function getPlayer(uuid: string): Promise<PlayerData | null> {
const playerReq: Player = await fetch(hypixel, {
params: {
key: apikey,
uuid: uuid
},
headers: {
"API-Key": apikey
}
})
@@ -59,16 +61,15 @@ async function getPlayer(uuid: string): Promise<PlayerData | null> {
return playerReq.data.player
}
async function getGuild(
query: string,
type?: GuildQuerqType
): Promise<GuildData | null> {
async function getGuild(query: string, type?: GuildQueryType): Promise<GuildData | null> {
const reqType = type ? type : "player"
const guildReq: Guild = await fetch(guild, {
params: {
key: apikey,
[reqType]: query
},
headers: {
"API-Key": apikey
}
})

View File

@@ -38,10 +38,8 @@ function guildLevel(exp: number): number {
*/
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))
if (input <= 700000) return Number(Math.round((input - 200000) / 10 + 200000))
if (input > 700000) return Number(Math.round((input - 700000) / 33 + 250000))
return 0
}

View File

@@ -3,13 +3,25 @@ import color from "utils/functions/colors"
import { Redis } from "ioredis"
import env from "utils/Env"
import { connect } from "mongoose"
import loadAllEvents from "./Events"
const client = new Client()
const redis = new Redis(env.prod.redisURI!)
let ft: "js" | "ts"
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
ft = "ts"
} else {
ft = "js"
}
class Bot {
async start() {
this.init()
loadAllEvents(client, ft)
client.start()
this.databases()
}
private async databases() {
redis.on("ready", () => {
console.log(color("Connected to Redis", "green"))
})

View File

@@ -21,10 +21,7 @@ const channels = {
type Channel = keyof typeof channels
export default async function logToChannel(
channel: Channel,
message: MessageCreateOptions
): Promise<void | null> {
export default async function logToChannel(channel: Channel, message: MessageCreateOptions): Promise<void | null> {
const guild = Illegitimate.client.guilds.cache.get(guildid) as Guild
let logChannel: TextChannel
@@ -35,9 +32,7 @@ export default async function logToChannel(
}
if (!logChannel) {
console.log(
`[ERROR] Could not find channel used for ${channel} logging.`
)
console.log(`[ERROR] Could not find channel used for ${channel} logging.`)
return
}

View File

@@ -30,63 +30,46 @@ type RoleType =
| "default"
| "all"
export default function roleManage(role: RoleType): {
rolesToRemove: string[]
rolesToAdd: string[]
} {
export default function roleManage(role: RoleType): { rolesToRemove: string[], rolesToAdd: string[] } {
if (role === "gm") {
const rolesToRemove = roles.filter(
role => role !== gm && role !== guildStaff && role !== guildRole
)
const rolesToRemove = roles.filter(role => role !== gm && role !== guildStaff && role !== guildRole)
const rolesToAdd = [gm, guildStaff, guildRole]
return { rolesToRemove, rolesToAdd }
}
if (role === "manager") {
const rolesToRemove = roles.filter(
role =>
role !== manager && role !== guildStaff && role !== guildRole
)
const rolesToRemove = roles.filter(role => role !== manager && role !== guildStaff && role !== guildRole)
const rolesToAdd = [manager, guildStaff, guildRole]
return { rolesToRemove, rolesToAdd }
}
if (role === "moderator") {
const rolesToRemove = roles.filter(
role =>
role !== moderator && role !== guildStaff && role !== guildRole
)
const rolesToRemove = roles.filter(role => role !== moderator && role !== guildStaff && role !== guildRole)
const rolesToAdd = [moderator, guildStaff, guildRole]
return { rolesToRemove, rolesToAdd }
}
if (role === "beast") {
const rolesToRemove = roles.filter(
role => role !== beast && role !== guildRole
)
const rolesToRemove = roles.filter(role => role !== beast && role !== guildRole)
const rolesToAdd = [beast, guildRole]
return { rolesToRemove, rolesToAdd }
}
if (role === "elite") {
const rolesToRemove = roles.filter(
role => role !== elite && role !== guildRole
)
const rolesToRemove = roles.filter(role => role !== elite && role !== guildRole)
const rolesToAdd = [elite, guildRole]
return { rolesToRemove, rolesToAdd }
}
if (role === "member") {
const rolesToRemove = roles.filter(
role => role !== member && role !== guildRole
)
const rolesToRemove = roles.filter(role => role !== member && role !== guildRole)
const rolesToAdd = [member, guildRole]
return { rolesToRemove, rolesToAdd }
}
if (role === "default") {
const rolesToRemove = roles
const rolesToAdd: string[] = [defaultMember]
const rolesToAdd = [defaultMember]
return { rolesToRemove, rolesToAdd }
}