diff --git a/nodemon-ts.json b/nodemon-js.json similarity index 59% rename from nodemon-ts.json rename to nodemon-js.json index 24cdcf8..c1993e0 100644 --- a/nodemon-ts.json +++ b/nodemon-js.json @@ -3,12 +3,12 @@ "ignore": [ ".git", "node_modules/**/node_modules", - "dist/config" + "dist/config", + "src" ], "verbose": true, "env": { - "NODE_ENV": "dev", - "TYPESCRIPT": "true" + "NODE_ENV": "dev" }, - "ext": "ts, json" -} \ No newline at end of file + "ext": "js, json" +} diff --git a/nodemon.json b/nodemon.json index c1993e0..24cdcf8 100644 --- a/nodemon.json +++ b/nodemon.json @@ -3,12 +3,12 @@ "ignore": [ ".git", "node_modules/**/node_modules", - "dist/config", - "src" + "dist/config" ], "verbose": true, "env": { - "NODE_ENV": "dev" + "NODE_ENV": "dev", + "TYPESCRIPT": "true" }, - "ext": "js, json" -} + "ext": "ts, json" +} \ No newline at end of file diff --git a/package.json b/package.json index 18a856b..ea2f454 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,8 @@ "start": "node dist/src/index.js", "build": "tsc", "watch": "tsc -w", - "dev": "nodemon dist/src/index.js", - "dev:ts": "nodemon --config nodemon-ts.json", + "dev": "nodemon", + "dev:js": "nodemon --config nodemon-js.json dist/src/index.js", "dev:build": "ts-node scripts/dev-deploy.ts", "dev:delete": "ts-node scripts/delete-commands.ts", "format": "prettier --write src/", diff --git a/src/commands/guild/top.ts b/src/commands/guild/top.ts index 9292ae7..db16547 100644 --- a/src/commands/guild/top.ts +++ b/src/commands/guild/top.ts @@ -1,8 +1,9 @@ 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" +import Illegitimate from "../../utils/Illegitimate" +const redis = Illegitimate.redis async function guildTop( interaction: ChatInputCommandInteraction, diff --git a/src/events/buttons/staffapply.ts b/src/events/buttons/staffapply.ts index 3181cba..8b7b937 100644 --- a/src/events/buttons/staffapply.ts +++ b/src/events/buttons/staffapply.ts @@ -15,7 +15,7 @@ import staffapp from "../../schemas/staffAppSchema" import settings from "../../schemas/settingsSchema" import { getUUID } from "../../utils/Hypixel" import { Button } from "../../interfaces" -import config from "../../utils/Config" +import env from "../../utils/Env" export = { name: "staffapply", @@ -42,7 +42,7 @@ export = { if (interaction.customId === "staffapply") { await interaction.deferReply({ ephemeral: true }) - if (user.user.id !== config.prod.dev) { + if (user.user.id !== env.prod.dev) { if (status === "0") { await interaction.editReply( "Staff applications are currently closed.", @@ -51,15 +51,15 @@ export = { } } - // if (!userRoles.has(guildRole)) { - // await interaction.editReply("You must be a member of the guild to apply for staff.") - // return - // } + if (!userRoles.has(guildRole)) { + await interaction.editReply("You must be a member of the guild to apply for staff.") + return + } - // if (userRoles.has(guildStaff)) { - // await interaction.editReply("You are already a staff member.") - // return - // } + if (userRoles.has(guildStaff)) { + await interaction.editReply("You are already a staff member.") + return + } const application = await staffapp.findOne({ userID: user.user.id }) diff --git a/src/interfaces/Config.ts b/src/interfaces/Env.ts similarity index 71% rename from src/interfaces/Config.ts rename to src/interfaces/Env.ts index fc43d3c..88b436b 100644 --- a/src/interfaces/Config.ts +++ b/src/interfaces/Env.ts @@ -1,4 +1,4 @@ -interface ProdConfig { +interface ProdEnv { token: string | undefined mongoURI: string | undefined dev: string | undefined @@ -6,14 +6,14 @@ interface ProdConfig { redisURI: string | undefined } -interface DevConfig { +interface DevEnv { devtoken: string | undefined clientid: string | undefined devid: string | undefined guildid: string | undefined } -export default interface Config { - prod: ProdConfig - dev: DevConfig +export default interface Env { + prod: ProdEnv + dev: DevEnv } diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 92b117b..626a4e5 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -5,7 +5,7 @@ import ContextMenu from "./ContextMenu" import Event from "./Event" import Modal from "./Modal" -import Config from "./Config" +import Env from "./Env" import Cron from "./Cron" import TimeZones from "./TimeZones" @@ -13,7 +13,7 @@ import { Guild, GuildData } from "./Guild" import { Player, PlayerData } from "./Player" export { - Config, + Env, Cron, TimeZones, Autocomplete, diff --git a/src/utils/Autodeploy.ts b/src/utils/Autodeploy.ts index df14873..14e83e8 100644 --- a/src/utils/Autodeploy.ts +++ b/src/utils/Autodeploy.ts @@ -1,6 +1,6 @@ import { Command } from "../interfaces" -import config from "./Config" -import color from "./Colors" +import env from "./Env" +import color from "./functions/colors" import { REST, RESTGetAPIApplicationGuildCommandResult, @@ -36,10 +36,10 @@ async function autoDeployCommands(fileType: FileType) { } } - const rest = new REST({ version: "10" }).setToken(config.dev.devtoken!) + const rest = new REST({ version: "10" }).setToken(env.dev.devtoken!) const currentCommands = (await rest.get( - Routes.applicationGuildCommands(config.dev.devid!, config.dev.guildid!), + Routes.applicationGuildCommands(env.dev.devid!, env.dev.guildid!), )) as RESTGetAPIApplicationGuildCommandResult[] const currentCommandsInfo = currentCommands.map(command => { @@ -98,8 +98,8 @@ async function autoDeployCommands(fileType: FileType) { const data = (await rest.put( Routes.applicationGuildCommands( - config.dev.devid!, - config.dev.guildid!, + env.dev.devid!, + env.dev.guildid!, ), { body: commands }, )) as RESTPutAPIApplicationGuildCommandsJSONBody[] diff --git a/src/utils/Client.ts b/src/utils/Client.ts index db008e3..947ef9b 100644 --- a/src/utils/Client.ts +++ b/src/utils/Client.ts @@ -4,7 +4,7 @@ import { ContextMenu } from "../interfaces" import { Button } from "../interfaces" import { Modal } from "../interfaces" import { Autocomplete } from "../interfaces" -import config from "./Config" +import env from "./Env" import { autoDeployCommands } from "./Autodeploy" import { loadAllEvents } from "./Events" @@ -40,17 +40,17 @@ export class ExtendedClient extends Client { if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT) { console.log("Running in development mode. [ts-node]") loadAllEvents(this, "ts") - token = config.dev.devtoken! + token = env.dev.devtoken! autoDeployCommands("ts") } else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) { console.log("Running in development mode.") loadAllEvents(this, "js") - token = config.dev.devtoken! + token = env.dev.devtoken! autoDeployCommands("js") } else { console.log("Running in production mode.") loadAllEvents(this, "js") - token = config.prod.token! + token = env.prod.token! } this.login(token) diff --git a/src/utils/Config.ts b/src/utils/Env.ts similarity index 82% rename from src/utils/Config.ts rename to src/utils/Env.ts index e858db2..10e6c4a 100644 --- a/src/utils/Config.ts +++ b/src/utils/Env.ts @@ -1,7 +1,7 @@ -import { Config } from "../interfaces" +import { Env } from "../interfaces" import "dotenv/config" -const config: Config = { +const env: Env = { prod: { token: process.env.TOKEN, mongoURI: process.env.MONGOURI, @@ -17,4 +17,4 @@ const config: Config = { }, } -export default config +export default env diff --git a/src/utils/Events.ts b/src/utils/Events.ts index 51383b6..be1f569 100644 --- a/src/utils/Events.ts +++ b/src/utils/Events.ts @@ -1,10 +1,10 @@ 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" +import { loadButtonEvents } from "./eventHandlers" +import { loadSlashCommandsEvents } from "./eventHandlers" +import { loadContextMenuEvents } from "./eventHandlers" +import { loadModalEvents } from "./eventHandlers" +import { loadEvents } from "./eventHandlers" +import { loadAutocompleteEvents } from "./eventHandlers" import { FileType } from "../typings" export function loadAllEvents(client: Client, ft: FileType) { diff --git a/src/utils/Illegitimate.ts b/src/utils/Illegitimate.ts index 360bf18..d9c83c9 100644 --- a/src/utils/Illegitimate.ts +++ b/src/utils/Illegitimate.ts @@ -1,10 +1,11 @@ import { ExtendedClient as Client } from "./Client" -import config from "./Config" -import { redis } from "./Redis" +import { Redis } from "ioredis" +import env from "./Env" import { connect } from "mongoose" import init from "./Init" -import { loadCronEvents } from "./Cron" +import { loadCronEvents } from "./eventHandlers" const client = new Client() +const redis = new Redis(env.prod.redisURI!) class Bot { constructor() {} @@ -16,10 +17,10 @@ class Bot { redis.on("ready", () => { console.log("Connected to Redis") }) - connect(config.prod.mongoURI!, {}).then(() => { + connect(env.prod.mongoURI!, {}).then(() => { console.log("Connected to MongoDB") }) } } -export default { Bot, client } \ No newline at end of file +export default { Bot, client, redis } \ No newline at end of file diff --git a/src/utils/Init.ts b/src/utils/Init.ts index 03b13c4..df1a4ab 100644 --- a/src/utils/Init.ts +++ b/src/utils/Init.ts @@ -1,7 +1,7 @@ -import config from "./Config" +import env from "./Env" -const prodValues = config.prod -const devValues = config.dev +const prodValues = env.prod +const devValues = env.dev export default function init() { if (process.env.NODE_ENV === "dev") { diff --git a/src/utils/Redis.ts b/src/utils/Redis.ts deleted file mode 100644 index 6d28b78..0000000 --- a/src/utils/Redis.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Redis } from "ioredis" -import config from "./Config" - -const redis = new Redis(config.prod.redisURI!) - -export { redis } diff --git a/src/utils/eventHandlers/autocomplete.ts b/src/utils/eventHandlers/autocomplete.ts index 59622b5..1bbe403 100644 --- a/src/utils/eventHandlers/autocomplete.ts +++ b/src/utils/eventHandlers/autocomplete.ts @@ -5,7 +5,7 @@ import path = require("path") import fs = require("fs") import { FileType } from "../../typings" -function loadAutocompleteEvents(client: Client, ft: FileType) { +export default function loadAutocompleteEvents(client: Client, ft: FileType) { const autocompletePath = path.join( __dirname, "..", @@ -52,6 +52,4 @@ function loadAutocompleteEvents(client: Client, ft: FileType) { console.error(error) } }) -} - -export { loadAutocompleteEvents } +} \ No newline at end of file diff --git a/src/utils/eventHandlers/button.ts b/src/utils/eventHandlers/button.ts index 41f554e..1ce9ae9 100644 --- a/src/utils/eventHandlers/button.ts +++ b/src/utils/eventHandlers/button.ts @@ -5,7 +5,7 @@ import path = require("path") import fs = require("fs") import { FileType } from "../../typings" -function loadButtonEvents(client: Client, ft: FileType) { +export default function loadButtonEvents(client: Client, ft: FileType) { const btnPath = path.join(__dirname, "..", "..", "events", "buttons") const btnFiles = fs .readdirSync(btnPath) @@ -46,6 +46,4 @@ function loadButtonEvents(client: Client, ft: FileType) { }) } }) -} - -export { loadButtonEvents } +} \ No newline at end of file diff --git a/src/utils/eventHandlers/command.ts b/src/utils/eventHandlers/command.ts index 52d6a15..6aa045b 100644 --- a/src/utils/eventHandlers/command.ts +++ b/src/utils/eventHandlers/command.ts @@ -5,7 +5,7 @@ import path = require("path") import fs = require("fs") import { FileType } from "../../typings" -function loadSlashCommandsEvents(client: Client, ft: FileType) { +export default function loadSlashCommandsEvents(client: Client, ft: FileType) { const cmdPath = path.join(__dirname, "..", "..", "commands") const cmdFiles = fs .readdirSync(cmdPath) .filter(file => file.endsWith(ft)) @@ -45,6 +45,4 @@ function loadSlashCommandsEvents(client: Client, ft: FileType) { }) } }) -} - -export { loadSlashCommandsEvents } +} \ No newline at end of file diff --git a/src/utils/eventHandlers/contextmenu.ts b/src/utils/eventHandlers/contextmenu.ts index 2b0b501..4d93e9e 100644 --- a/src/utils/eventHandlers/contextmenu.ts +++ b/src/utils/eventHandlers/contextmenu.ts @@ -5,7 +5,7 @@ import path = require("path") import fs = require("fs") import { FileType } from "../../typings" -function loadContextMenuEvents(client: Client, ft: FileType) { +export default function loadContextMenuEvents(client: Client, ft: FileType) { const contextMenuPath = path.join( __dirname, "..", @@ -52,6 +52,4 @@ function loadContextMenuEvents(client: Client, ft: FileType) { }) } }) -} - -export { loadContextMenuEvents } +} \ No newline at end of file diff --git a/src/utils/Cron.ts b/src/utils/eventHandlers/cron.ts similarity index 77% rename from src/utils/Cron.ts rename to src/utils/eventHandlers/cron.ts index a39cd87..579a956 100644 --- a/src/utils/Cron.ts +++ b/src/utils/eventHandlers/cron.ts @@ -1,10 +1,10 @@ import { CronJob } from "cron" import path from "path" import fs from "fs" -import { Cron } from "../interfaces" +import { Cron } from "../../interfaces" -function loadCronEvents() { - const cronPath = path.join(__dirname, "..", "events", "cron") +export default function loadCronEvents() { + const cronPath = path.join(__dirname, "..", "..", "events", "cron") const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(".js")) for (const file of cronFiles) { @@ -15,6 +15,4 @@ function loadCronEvents() { new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start() } -} - -export { loadCronEvents } \ No newline at end of file +} \ No newline at end of file diff --git a/src/utils/eventHandlers/events.ts b/src/utils/eventHandlers/events.ts index 78ed31b..b1b1151 100644 --- a/src/utils/eventHandlers/events.ts +++ b/src/utils/eventHandlers/events.ts @@ -3,7 +3,7 @@ import { Event } from "../../interfaces" import path = require("path") import fs = require("fs") -function loadEvents(client: Client) { +export default function loadEvents(client: Client) { const serverDir = path.join(__dirname, "..", "..", "events", "server") const eventDirs = fs.readdirSync(serverDir) for (const eventDir of eventDirs) { @@ -14,6 +14,4 @@ function loadEvents(client: Client) { client.on(event.event, event.execute) } } -} - -export { loadEvents } +} \ No newline at end of file diff --git a/src/utils/eventHandlers/index.ts b/src/utils/eventHandlers/index.ts new file mode 100644 index 0000000..c4a85ef --- /dev/null +++ b/src/utils/eventHandlers/index.ts @@ -0,0 +1,17 @@ +import loadAutocompleteEvents from "./autocomplete" +import loadButtonEvents from "./button" +import loadSlashCommandsEvents from "./command" +import loadContextMenuEvents from "./contextmenu" +import loadCronEvents from "./cron" +import loadEvents from "./events" +import loadModalEvents from "./modal" + +export { + loadAutocompleteEvents, + loadButtonEvents, + loadSlashCommandsEvents, + loadContextMenuEvents, + loadCronEvents, + loadEvents, + loadModalEvents +} \ No newline at end of file diff --git a/src/utils/eventHandlers/modal.ts b/src/utils/eventHandlers/modal.ts index 0d110de..161631a 100644 --- a/src/utils/eventHandlers/modal.ts +++ b/src/utils/eventHandlers/modal.ts @@ -5,7 +5,7 @@ import path = require("path") import fs = require("fs") import { FileType } from "../../typings" -function loadModalEvents(client: Client, ft: FileType) { +export default function loadModalEvents(client: Client, ft: FileType) { const modalPath = path.join(__dirname, "..", "..", "events", "modals") const modalFiles = fs .readdirSync(modalPath) diff --git a/src/utils/functions/account.ts b/src/utils/functions/account.ts index 58f1dd6..0a0f815 100644 --- a/src/utils/functions/account.ts +++ b/src/utils/functions/account.ts @@ -1,9 +1,9 @@ import fetch from "axios" -import config from "../Config" +import env from "../Env" import { Profile, Profile2 } from "../../typings" import { Player, PlayerData } from "../../interfaces" import { Guild, GuildData } from "../../interfaces" -const apikey = config.prod.hypixelapikey +const apikey = env.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" diff --git a/src/utils/Colors.ts b/src/utils/functions/colors.ts similarity index 100% rename from src/utils/Colors.ts rename to src/utils/functions/colors.ts