Merge branch 'dev' into 'main'

Dev

See merge request illegitimate/illegitimate-bot!145
This commit is contained in:
2023-12-30 16:09:27 +00:00
24 changed files with 93 additions and 92 deletions

View File

@@ -3,12 +3,12 @@
"ignore": [ "ignore": [
".git", ".git",
"node_modules/**/node_modules", "node_modules/**/node_modules",
"dist/config" "dist/config",
"src"
], ],
"verbose": true, "verbose": true,
"env": { "env": {
"NODE_ENV": "dev", "NODE_ENV": "dev"
"TYPESCRIPT": "true"
}, },
"ext": "ts, json" "ext": "js, json"
} }

View File

@@ -3,12 +3,12 @@
"ignore": [ "ignore": [
".git", ".git",
"node_modules/**/node_modules", "node_modules/**/node_modules",
"dist/config", "dist/config"
"src"
], ],
"verbose": true, "verbose": true,
"env": { "env": {
"NODE_ENV": "dev" "NODE_ENV": "dev",
"TYPESCRIPT": "true"
}, },
"ext": "js, json" "ext": "ts, json"
} }

View File

@@ -7,8 +7,8 @@
"start": "node dist/src/index.js", "start": "node dist/src/index.js",
"build": "tsc", "build": "tsc",
"watch": "tsc -w", "watch": "tsc -w",
"dev": "nodemon dist/src/index.js", "dev": "nodemon",
"dev:ts": "nodemon --config nodemon-ts.json", "dev:js": "nodemon --config nodemon-js.json dist/src/index.js",
"dev:build": "ts-node scripts/dev-deploy.ts", "dev:build": "ts-node scripts/dev-deploy.ts",
"dev:delete": "ts-node scripts/delete-commands.ts", "dev:delete": "ts-node scripts/delete-commands.ts",
"format": "prettier --write src/", "format": "prettier --write src/",

View File

@@ -1,8 +1,9 @@
import { getUUID, getPlayer, getGuild, getIGN } from "../../utils/Hypixel" import { getUUID, getPlayer, getGuild, getIGN } from "../../utils/Hypixel"
import { color, devMessage } from "../../../config/options.json" import { color, devMessage } from "../../../config/options.json"
import { ChannelType, ChatInputCommandInteraction } from "discord.js" import { ChannelType, ChatInputCommandInteraction } from "discord.js"
import { redis } from "../../utils/Redis"
import { GuildData } from "../../interfaces/Guild" import { GuildData } from "../../interfaces/Guild"
import Illegitimate from "../../utils/Illegitimate"
const redis = Illegitimate.redis
async function guildTop( async function guildTop(
interaction: ChatInputCommandInteraction, interaction: ChatInputCommandInteraction,

View File

@@ -15,7 +15,7 @@ import staffapp from "../../schemas/staffAppSchema"
import settings from "../../schemas/settingsSchema" import settings from "../../schemas/settingsSchema"
import { getUUID } from "../../utils/Hypixel" import { getUUID } from "../../utils/Hypixel"
import { Button } from "../../interfaces" import { Button } from "../../interfaces"
import config from "../../utils/Config" import env from "../../utils/Env"
export = { export = {
name: "staffapply", name: "staffapply",
@@ -42,7 +42,7 @@ export = {
if (interaction.customId === "staffapply") { if (interaction.customId === "staffapply") {
await interaction.deferReply({ ephemeral: true }) await interaction.deferReply({ ephemeral: true })
if (user.user.id !== config.prod.dev) { if (user.user.id !== env.prod.dev) {
if (status === "0") { if (status === "0") {
await interaction.editReply( await interaction.editReply(
"Staff applications are currently closed.", "Staff applications are currently closed.",
@@ -51,15 +51,15 @@ export = {
} }
} }
// if (!userRoles.has(guildRole)) { if (!userRoles.has(guildRole)) {
// await interaction.editReply("You must be a member of the guild to apply for staff.") await interaction.editReply("You must be a member of the guild to apply for staff.")
// return return
// } }
// if (userRoles.has(guildStaff)) { if (userRoles.has(guildStaff)) {
// await interaction.editReply("You are already a staff member.") await interaction.editReply("You are already a staff member.")
// return return
// } }
const application = await staffapp.findOne({ userID: user.user.id }) const application = await staffapp.findOne({ userID: user.user.id })

View File

@@ -1,4 +1,4 @@
interface ProdConfig { interface ProdEnv {
token: string | undefined token: string | undefined
mongoURI: string | undefined mongoURI: string | undefined
dev: string | undefined dev: string | undefined
@@ -6,14 +6,14 @@ interface ProdConfig {
redisURI: string | undefined redisURI: string | undefined
} }
interface DevConfig { interface DevEnv {
devtoken: string | undefined devtoken: string | undefined
clientid: string | undefined clientid: string | undefined
devid: string | undefined devid: string | undefined
guildid: string | undefined guildid: string | undefined
} }
export default interface Config { export default interface Env {
prod: ProdConfig prod: ProdEnv
dev: DevConfig dev: DevEnv
} }

View File

@@ -5,7 +5,7 @@ import ContextMenu from "./ContextMenu"
import Event from "./Event" import Event from "./Event"
import Modal from "./Modal" import Modal from "./Modal"
import Config from "./Config" import Env from "./Env"
import Cron from "./Cron" import Cron from "./Cron"
import TimeZones from "./TimeZones" import TimeZones from "./TimeZones"
@@ -13,7 +13,7 @@ import { Guild, GuildData } from "./Guild"
import { Player, PlayerData } from "./Player" import { Player, PlayerData } from "./Player"
export { export {
Config, Env,
Cron, Cron,
TimeZones, TimeZones,
Autocomplete, Autocomplete,

View File

@@ -1,6 +1,6 @@
import { Command } from "../interfaces" import { Command } from "../interfaces"
import config from "./Config" import env from "./Env"
import color from "./Colors" import color from "./functions/colors"
import { import {
REST, REST,
RESTGetAPIApplicationGuildCommandResult, 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( const currentCommands = (await rest.get(
Routes.applicationGuildCommands(config.dev.devid!, config.dev.guildid!), Routes.applicationGuildCommands(env.dev.devid!, env.dev.guildid!),
)) as RESTGetAPIApplicationGuildCommandResult[] )) as RESTGetAPIApplicationGuildCommandResult[]
const currentCommandsInfo = currentCommands.map(command => { const currentCommandsInfo = currentCommands.map(command => {
@@ -98,8 +98,8 @@ async function autoDeployCommands(fileType: FileType) {
const data = (await rest.put( const data = (await rest.put(
Routes.applicationGuildCommands( Routes.applicationGuildCommands(
config.dev.devid!, env.dev.devid!,
config.dev.guildid!, env.dev.guildid!,
), ),
{ body: commands }, { body: commands },
)) as RESTPutAPIApplicationGuildCommandsJSONBody[] )) as RESTPutAPIApplicationGuildCommandsJSONBody[]

View File

@@ -4,7 +4,7 @@ import { ContextMenu } from "../interfaces"
import { Button } from "../interfaces" import { Button } from "../interfaces"
import { Modal } from "../interfaces" import { Modal } from "../interfaces"
import { Autocomplete } from "../interfaces" import { Autocomplete } from "../interfaces"
import config from "./Config" import env from "./Env"
import { autoDeployCommands } from "./Autodeploy" import { autoDeployCommands } from "./Autodeploy"
import { loadAllEvents } from "./Events" import { loadAllEvents } from "./Events"
@@ -40,17 +40,17 @@ export class ExtendedClient extends Client {
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT) { if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT) {
console.log("Running in development mode. [ts-node]") console.log("Running in development mode. [ts-node]")
loadAllEvents(this, "ts") loadAllEvents(this, "ts")
token = config.dev.devtoken! token = env.dev.devtoken!
autoDeployCommands("ts") autoDeployCommands("ts")
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) { } else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
console.log("Running in development mode.") console.log("Running in development mode.")
loadAllEvents(this, "js") loadAllEvents(this, "js")
token = config.dev.devtoken! token = env.dev.devtoken!
autoDeployCommands("js") autoDeployCommands("js")
} else { } else {
console.log("Running in production mode.") console.log("Running in production mode.")
loadAllEvents(this, "js") loadAllEvents(this, "js")
token = config.prod.token! token = env.prod.token!
} }
this.login(token) this.login(token)

View File

@@ -1,7 +1,7 @@
import { Config } from "../interfaces" import { Env } from "../interfaces"
import "dotenv/config" import "dotenv/config"
const config: Config = { const env: Env = {
prod: { prod: {
token: process.env.TOKEN, token: process.env.TOKEN,
mongoURI: process.env.MONGOURI, mongoURI: process.env.MONGOURI,
@@ -17,4 +17,4 @@ const config: Config = {
}, },
} }
export default config export default env

View File

@@ -1,10 +1,10 @@
import { ExtendedClient as Client } from "./Client" import { ExtendedClient as Client } from "./Client"
import { loadButtonEvents } from "./eventHandlers/button" import { loadButtonEvents } from "./eventHandlers"
import { loadSlashCommandsEvents } from "./eventHandlers/command" import { loadSlashCommandsEvents } from "./eventHandlers"
import { loadContextMenuEvents } from "./eventHandlers/contextmenu" import { loadContextMenuEvents } from "./eventHandlers"
import { loadModalEvents } from "./eventHandlers/modal" import { loadModalEvents } from "./eventHandlers"
import { loadEvents } from "./eventHandlers/events" import { loadEvents } from "./eventHandlers"
import { loadAutocompleteEvents } from "./eventHandlers/autocomplete" import { loadAutocompleteEvents } from "./eventHandlers"
import { FileType } from "../typings" import { FileType } from "../typings"
export function loadAllEvents(client: Client, ft: FileType) { export function loadAllEvents(client: Client, ft: FileType) {

View File

@@ -1,10 +1,11 @@
import { ExtendedClient as Client } from "./Client" import { ExtendedClient as Client } from "./Client"
import config from "./Config" import { Redis } from "ioredis"
import { redis } from "./Redis" import env from "./Env"
import { connect } from "mongoose" import { connect } from "mongoose"
import init from "./Init" import init from "./Init"
import { loadCronEvents } from "./Cron" import { loadCronEvents } from "./eventHandlers"
const client = new Client() const client = new Client()
const redis = new Redis(env.prod.redisURI!)
class Bot { class Bot {
constructor() {} constructor() {}
@@ -16,10 +17,10 @@ class Bot {
redis.on("ready", () => { redis.on("ready", () => {
console.log("Connected to Redis") console.log("Connected to Redis")
}) })
connect(config.prod.mongoURI!, {}).then(() => { connect(env.prod.mongoURI!, {}).then(() => {
console.log("Connected to MongoDB") console.log("Connected to MongoDB")
}) })
} }
} }
export default { Bot, client } export default { Bot, client, redis }

View File

@@ -1,7 +1,7 @@
import config from "./Config" import env from "./Env"
const prodValues = config.prod const prodValues = env.prod
const devValues = config.dev const devValues = env.dev
export default function init() { export default function init() {
if (process.env.NODE_ENV === "dev") { if (process.env.NODE_ENV === "dev") {

View File

@@ -1,6 +0,0 @@
import { Redis } from "ioredis"
import config from "./Config"
const redis = new Redis(config.prod.redisURI!)
export { redis }

View File

@@ -5,7 +5,7 @@ import path = require("path")
import fs = require("fs") import fs = require("fs")
import { FileType } from "../../typings" import { FileType } from "../../typings"
function loadAutocompleteEvents(client: Client, ft: FileType) { export default function loadAutocompleteEvents(client: Client, ft: FileType) {
const autocompletePath = path.join( const autocompletePath = path.join(
__dirname, __dirname,
"..", "..",
@@ -52,6 +52,4 @@ function loadAutocompleteEvents(client: Client, ft: FileType) {
console.error(error) console.error(error)
} }
}) })
} }
export { loadAutocompleteEvents }

View File

@@ -5,7 +5,7 @@ import path = require("path")
import fs = require("fs") import fs = require("fs")
import { FileType } from "../../typings" 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 btnPath = path.join(__dirname, "..", "..", "events", "buttons")
const btnFiles = fs const btnFiles = fs
.readdirSync(btnPath) .readdirSync(btnPath)
@@ -46,6 +46,4 @@ function loadButtonEvents(client: Client, ft: FileType) {
}) })
} }
}) })
} }
export { loadButtonEvents }

View File

@@ -5,7 +5,7 @@ import path = require("path")
import fs = require("fs") import fs = require("fs")
import { FileType } from "../../typings" 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 cmdPath = path.join(__dirname, "..", "..", "commands")
const cmdFiles = fs .readdirSync(cmdPath) .filter(file => file.endsWith(ft)) const cmdFiles = fs .readdirSync(cmdPath) .filter(file => file.endsWith(ft))
@@ -45,6 +45,4 @@ function loadSlashCommandsEvents(client: Client, ft: FileType) {
}) })
} }
}) })
} }
export { loadSlashCommandsEvents }

View File

@@ -5,7 +5,7 @@ import path = require("path")
import fs = require("fs") import fs = require("fs")
import { FileType } from "../../typings" import { FileType } from "../../typings"
function loadContextMenuEvents(client: Client, ft: FileType) { export default function loadContextMenuEvents(client: Client, ft: FileType) {
const contextMenuPath = path.join( const contextMenuPath = path.join(
__dirname, __dirname,
"..", "..",
@@ -52,6 +52,4 @@ function loadContextMenuEvents(client: Client, ft: FileType) {
}) })
} }
}) })
} }
export { loadContextMenuEvents }

View File

@@ -1,10 +1,10 @@
import { CronJob } from "cron" import { CronJob } from "cron"
import path from "path" import path from "path"
import fs from "fs" import fs from "fs"
import { Cron } from "../interfaces" import { Cron } from "../../interfaces"
function loadCronEvents() { export default function loadCronEvents() {
const cronPath = path.join(__dirname, "..", "events", "cron") 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) { for (const file of cronFiles) {
@@ -15,6 +15,4 @@ function loadCronEvents() {
new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start() new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start()
} }
} }
export { loadCronEvents }

View File

@@ -3,7 +3,7 @@ import { Event } from "../../interfaces"
import path = require("path") import path = require("path")
import fs = require("fs") import fs = require("fs")
function loadEvents(client: Client) { export default function loadEvents(client: Client) {
const serverDir = path.join(__dirname, "..", "..", "events", "server") const serverDir = path.join(__dirname, "..", "..", "events", "server")
const eventDirs = fs.readdirSync(serverDir) const eventDirs = fs.readdirSync(serverDir)
for (const eventDir of eventDirs) { for (const eventDir of eventDirs) {
@@ -14,6 +14,4 @@ function loadEvents(client: Client) {
client.on(event.event, event.execute) client.on(event.event, event.execute)
} }
} }
} }
export { loadEvents }

View File

@@ -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
}

View File

@@ -5,7 +5,7 @@ import path = require("path")
import fs = require("fs") import fs = require("fs")
import { FileType } from "../../typings" 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 modalPath = path.join(__dirname, "..", "..", "events", "modals")
const modalFiles = fs const modalFiles = fs
.readdirSync(modalPath) .readdirSync(modalPath)

View File

@@ -1,9 +1,9 @@
import fetch from "axios" import fetch from "axios"
import config from "../Config" import env from "../Env"
import { Profile, Profile2 } from "../../typings" import { Profile, Profile2 } from "../../typings"
import { Player, PlayerData } from "../../interfaces" import { Player, PlayerData } from "../../interfaces"
import { Guild, GuildData } 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 mojang = "https://api.mojang.com/users/profiles/minecraft/"
const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/" const mojanguuid = "https://sessionserver.mojang.com/session/minecraft/profile/"
const hypixel = "https://api.hypixel.net/player" const hypixel = "https://api.hypixel.net/player"