Added eslintrc config and updated all files to it

This commit is contained in:
2023-11-22 23:50:21 +01:00
parent 10771fd04e
commit 3d4fc1fccb
70 changed files with 1276 additions and 1234 deletions

View File

@@ -1,10 +1,10 @@
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;
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({
@@ -13,31 +13,31 @@ log.setColors({
})
async function autoDeployCommands() {
const commands = [];
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
const contentMenuCommands = fs.readdirSync('./commands-contextmenu/').filter(file => file.endsWith('.js'));
const commandsTesting = fs.readdirSync('./commands-testing/').filter(file => file.endsWith('.js'));
const commands = []
const commandFiles = fs.readdirSync("./commands/").filter(file => file.endsWith(".js"))
const contentMenuCommands = fs.readdirSync("./commands-contextmenu/").filter(file => file.endsWith(".js"))
const commandsTesting = fs.readdirSync("./commands-testing/").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`../commands/${file}`);
const command = require(`../commands/${file}`)
if (command.dev) {
commands.push(command.data.toJSON());
commands.push(command.data.toJSON())
}
}
for (const file of contentMenuCommands) {
const command = require(`../commands-contextmenu/${file}`);
const command = require(`../commands-contextmenu/${file}`)
if (command.dev) {
commands.push(command.data.toJSON());
commands.push(command.data.toJSON())
}
}
for (const file of commandsTesting) {
const command = require(`../commands-testing/${file}`);
const command = require(`../commands-testing/${file}`)
if (command.dev) {
commands.push(command.data.toJSON());
commands.push(command.data.toJSON())
}
}
const rest = new REST({ version: '10' }).setToken(token);
const rest = new REST({ version: "10" }).setToken(token)
const currentCommands = await rest.get(
Routes.applicationGuildCommands(clientId, guildId),
@@ -61,32 +61,32 @@ async function autoDeployCommands() {
const newCmds = sortedNewCommandsInfo.map(cmd => {
return " " + cmd.name + " was registered."
}).join('\n')
}).join("\n")
const currentCmds = sortedCurrentCommandsInfo.map(cmd => {
return " " + cmd.name + " was unregistered."
}).join('\n')
}).join("\n")
if (JSON.stringify(sortedNewCommandsInfo) === JSON.stringify(sortedCurrentCommandsInfo)) {
log.success('Commands are the same, skipping deploy.')
log.success("Commands are the same, skipping deploy.")
log.newCmds(newCmds)
return
}
(async () => {
try {
log.warning('Commands are different, starting deploy.')
log.warning("Commands are different, starting deploy.")
log.currentCmds(currentCmds)
console.log(`Started refreshing ${commands.length} application (/) commands.`);
console.log(`Started refreshing ${commands.length} application (/) commands.`)
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
)
log.newCmds(newCmds)
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
console.log(`Successfully reloaded ${data.length} application (/) commands.`)
} catch (error) {
console.error(error);
console.error(error)
}
})()
}

View File

@@ -1,8 +1,8 @@
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 { 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")
module.exports = {
loadSlashCommandsEvents,

View File

@@ -1,42 +1,42 @@
const { Events } = require('discord.js')
const path = require('path');
const fs = require('fs');
const { Events } = require("discord.js")
const path = require("path")
const fs = require("fs")
/** @param { import('discord.js').Client } client */
function loadButtonEvents(client) {
const btnPath = path.join(__dirname, '..', '..', 'events', 'buttons');
const btnFiles = fs.readdirSync(btnPath).filter(file => file.endsWith('.js'));
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 filePath = path.join(btnPath, file)
const btn = require(filePath)
if ('name' in btn && 'execute' in btn && btn.type === 'button') {
client.events.set(btn.name, btn);
if ("name" in btn && "execute" in btn && btn.type === "button") {
client.events.set(btn.name, btn)
} else {
console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`);
console.log(`[WARNING] The button at ${filePath} is missing a required "name", "execute" or "type" property.`)
}
}
client.on(Events.InteractionCreate, async event => {
if (!event.isButton())
return;
return
const event2 = event.client.events.get(event.customId);
const event2 = event.client.events.get(event.customId)
if (!event2) {
console.error(`No event matching ${event.customId} was found.`);
return;
console.error(`No event matching ${event.customId} was found.`)
return
}
try {
await event2.execute(event);
await event2.execute(event)
} catch (error) {
console.error(error);
console.error(error)
await event.reply({
content: 'There was an error while executing this event!',
content: "There was an error while executing this event!",
ephemeral: true
})
}

View File

@@ -1,59 +1,59 @@
const { Events } = require('discord.js')
const path = require('path');
const fs = require('fs');
const { Events } = require("discord.js")
const path = require("path")
const fs = require("fs")
/** @param { import('discord.js').Client } client */
function loadSlashCommandsEvents(client) {
const cmdPath = path.join(__dirname, '..', '..', 'commands');
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith('.js'));
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);
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);
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.`);
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'));
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 filePath = path.join(cmdTestPath, file)
const cmd = require(filePath)
if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') {
client.commands.set(cmd.data.name, cmd);
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.`);
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`)
}
}
//! command handler
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand())
return;
return
const command = interaction.client.commands.get(interaction.commandName);
const command = interaction.client.commands.get(interaction.commandName)
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
console.error(`No command matching ${interaction.commandName} was found.`)
return
}
try {
await command.execute(interaction);
await command.execute(interaction)
} catch (error) {
console.error(error);
console.error(error)
await interaction.reply({
content: 'There was an error while executing this command!',
content: "There was an error while executing this command!",
ephemeral: true
})
}

View File

@@ -1,43 +1,43 @@
const { Events } = require('discord.js')
const path = require('path');
const fs = require('fs');
const { Events } = require("discord.js")
const path = require("path")
const fs = require("fs")
/** @param { import('discord.js').Client } client */
function loadContextMenuEvents(client) {
const contextMenuPath = path.join(__dirname, '..', '..', 'commands-contextmenu');
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith('.js'));
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 filePath = path.join(contextMenuPath, file)
const cmd = require(filePath)
if ('data' in cmd && 'execute' in cmd && cmd.type === 'contextmenu') {
client.commands.set(cmd.data.name, cmd);
if ("data" in cmd && "execute" in cmd && cmd.type === "contextmenu") {
client.commands.set(cmd.data.name, cmd)
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`);
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`)
}
}
//! context menu command handler
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isContextMenuCommand())
return;
return
const command = interaction.client.commands.get(interaction.commandName);
const command = interaction.client.commands.get(interaction.commandName)
if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
console.error(`No command matching ${interaction.commandName} was found.`)
return
}
try {
await command.execute(interaction);
await command.execute(interaction)
} catch (error) {
console.error(error);
console.error(error)
await interaction.reply({
content: 'There was an error while executing this command!',
content: "There was an error while executing this command!",
ephemeral: true
})
}

View File

@@ -1,20 +1,20 @@
const path = require('path');
const fs = require('fs');
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 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') {
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.`);
console.log(`[WARNING] The event at ${eventPath} is missing a required "name", "execute", "type" or "event" property.`)
}
}
}

View File

@@ -1,22 +1,22 @@
const { Events } = require('discord.js')
const path = require('path');
const fs = require('fs');
const { Events } = require("discord.js")
const path = require("path")
const fs = require("fs")
/** @param { import('discord.js').Client } client */
function loadModalEvents(client) {
const modalPath = path.join(__dirname, '..', '..', 'events', 'modals');
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith('.js'));
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 filePath = path.join(modalPath, file)
const modal = require(filePath)
if ('name' in modal && 'execute' in modal && modal.type === 'modal') {
client.on(Events.InteractionCreate, modal.execute);
if ("name" in modal && "execute" in modal && modal.type === "modal") {
client.on(Events.InteractionCreate, modal.execute)
} else {
console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`);
console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`)
}
}
}

View File

@@ -1,10 +1,10 @@
const fetch = require('axios')
const fetch = require("axios")
const apikey = process.env.HYPIXELAPIKEY
const mojang = 'https://api.mojang.com/users/profiles/minecraft/'
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/'
const hypixel = "https://api.hypixel.net/player"
const guild = "https://api.hypixel.net/guild"
const minotar = "https://minotar.net/helm/"
async function getUUID(ign) {
try {

View File

@@ -2,52 +2,52 @@
Code used from the slothpixel project https://github.com/slothpixel/core
*/
function getExpForLevel(level) {
if (level == 0) return 0;
if (level == 0) return 0
let respectedLevel = getLevelRespectingPrestige(level);
let respectedLevel = getLevelRespectingPrestige(level)
if (respectedLevel > EASY_LEVELS) {
return 5000;
return 5000
}
switch (respectedLevel) {
case 1:
return 500;
case 2:
return 1000;
case 3:
return 2000;
case 4:
return 3500;
case 1:
return 500
case 2:
return 1000
case 3:
return 2000
case 4:
return 3500
}
return 5000;
return 5000
}
function getLevelRespectingPrestige(level) {
if (level > HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE) {
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE;
return level - HIGHEST_PRESTIGE * LEVELS_PER_PRESTIGE
}
else {
return level % LEVELS_PER_PRESTIGE;
return level % LEVELS_PER_PRESTIGE
}
}
const EASY_LEVELS = 4;
const EASY_LEVELS_XP = 7000;
const XP_PER_PRESTIGE = 96 * 5000 + EASY_LEVELS_XP;
const LEVELS_PER_PRESTIGE = 100;
const HIGHEST_PRESTIGE = 50;
const EASY_LEVELS = 4
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) {
let prestiges = Math.floor(exp / XP_PER_PRESTIGE);
let level = prestiges * LEVELS_PER_PRESTIGE;
let expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE);
let prestiges = Math.floor(exp / XP_PER_PRESTIGE)
let level = prestiges * LEVELS_PER_PRESTIGE
let expWithoutPrestiges = exp - (prestiges * XP_PER_PRESTIGE)
for (let i = 1; i <= EASY_LEVELS; ++i) {
let expForEasyLevel = getExpForLevel(i);
let expForEasyLevel = getExpForLevel(i)
if (expWithoutPrestiges < expForEasyLevel) {
break;
break
}
level++;
expWithoutPrestiges -= expForEasyLevel;
level++
expWithoutPrestiges -= expForEasyLevel
}
return level + expWithoutPrestiges / 5000
}

View File

@@ -18,39 +18,39 @@ function guildLevel(exp) {
2500000,
2500000,
3000000,
];
]
let level = 0;
let level = 0
// Increments by one from zero to the level cap
for (let i = 0; i <= 1000; i += 1) {
// need is the required exp to get to the next level
let need = 0;
let need = 0
if (i >= EXP_NEEDED.length) {
need = EXP_NEEDED[EXP_NEEDED.length - 1];
} else { need = EXP_NEEDED[i]; }
need = EXP_NEEDED[EXP_NEEDED.length - 1]
} else { need = EXP_NEEDED[i] }
// If the required exp to get to the next level isn't met returns
// the current level plus progress towards the next (unused exp/need)
// Otherwise increments the level and substracts the used exp from exp var
if ((exp - need) < 0) {
return Math.round((level + (exp / need)) * 100) / 100;
return Math.round((level + (exp / need)) * 100) / 100
}
level += 1;
exp -= need;
level += 1
exp -= need
}
// Returns the level cap - currently 1000
// If changed here, also change in for loop above
return 1000;
return 1000
}
/*
Code used from the hypixel-guild-bot project https://github.com/SimplyNo/hypixel-guild-bot
*/
function scaledGEXP(input) {
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 <= 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))
}
module.exports = { guildLevel, scaledGEXP }

View File

@@ -1,36 +1,36 @@
/*
Code used from the slothpixel project https://github.com/slothpixel/core
*/
const BASE = 10000;
const GROWTH = 2500;
const HALF_GROWTH = 0.5 * GROWTH;
const REVERSE_PQ_PREFIX = -(BASE - 0.5 * GROWTH) / GROWTH;
const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX;
const GROWTH_DIVIDES_2 = 2 / GROWTH;
const BASE = 10000
const GROWTH = 2500
const HALF_GROWTH = 0.5 * GROWTH
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) {
return exp <= 1 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp));
return exp <= 1 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp))
}
function hypixelLevel(exp) {
return getLevel(exp) + getPercentageToNextLevel(exp);
return getLevel(exp) + getPercentageToNextLevel(exp)
}
function getTotalExpToLevel(level) {
const lv = Math.floor(level); const
x0 = getTotalExpToFullLevel(lv);
if (level === lv) return x0;
return (getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0;
x0 = getTotalExpToFullLevel(lv)
if (level === lv) return x0
return (getTotalExpToFullLevel(lv + 1) - x0) * (level % 1) + x0
}
function getTotalExpToFullLevel(level) {
return (HALF_GROWTH * (level - 2) + BASE) * (level - 1);
return (HALF_GROWTH * (level - 2) + BASE) * (level - 1)
}
function getPercentageToNextLevel(exp) {
const lv = getLevel(exp);
const x0 = getTotalExpToLevel(lv);
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0);
const lv = getLevel(exp)
const x0 = getTotalExpToLevel(lv)
return (exp - x0) / (getTotalExpToLevel(lv + 1) - x0)
}

View File

@@ -2,16 +2,16 @@
Code used from the slothpixel project https://github.com/slothpixel/core
*/
function skywarsLevel(xp) {
let xps = [0, 20, 70, 150, 250, 500, 1000, 2000, 3500, 6000, 10000, 15000];
let 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;
exactLevel = (xp - 15000) / 10000 + 12
return exactLevel
} else {
for (i = 0; i < xps.length; i++) {
if (xp < xps[i]) {
exactLevel = i + (xp - xps[i - 1]) / (xps[i] - xps[i - 1]);
return exactLevel;
exactLevel = i + (xp - xps[i - 1]) / (xps[i] - xps[i - 1])
return exactLevel
}
}
}

View File

@@ -1,5 +1,5 @@
function formatUuid(uuid) {
return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, '$1-$2-$3-$4-$5')
return uuid.replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/, "$1-$2-$3-$4-$5")
}
module.exports = { formatUuid }

View File

@@ -1,9 +1,9 @@
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')
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,