69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { Player } from "discord-player"
|
|
import { YoutubeiExtractor } from "discord-player-youtubei"
|
|
import { Redis } from "ioredis"
|
|
import { ExtendedClient as Client } from "~/utils/Client.js"
|
|
import env from "~/utils/Env.js"
|
|
import { MissingEnvVarsError } from "./Classes.js"
|
|
import loadAllEvents from "./Events/loadevents.js"
|
|
import { log } from "./Logger.js"
|
|
|
|
const client = new Client()
|
|
const redis = new Redis(env.prod.redisURI)
|
|
const player = new Player(client)
|
|
|
|
let ft: "js" | "ts"
|
|
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
|
|
ft = "ts"
|
|
} else {
|
|
ft = "js"
|
|
}
|
|
|
|
class Illegitimate {
|
|
async start() {
|
|
await this.init()
|
|
await loadAllEvents(client, ft)
|
|
// await player.extractors.loadDefault()
|
|
await player.extractors.loadDefault(ext => ext != "YouTubeExtractor")
|
|
await player.extractors.register(YoutubeiExtractor, {})
|
|
await client.start()
|
|
await this.databases()
|
|
this.loadMethods()
|
|
}
|
|
|
|
private async databases() {
|
|
redis.on("ready", () => {
|
|
log("Connected to Redis", "info", { type: "preset", color: "green" })
|
|
})
|
|
}
|
|
|
|
private async init() {
|
|
const prodValues = env.prod
|
|
const devValues = env.dev
|
|
|
|
if (process.env.NODE_ENV === "dev") {
|
|
for (const [key, value] of Object.entries(devValues)) {
|
|
if (!value) throw new MissingEnvVarsError(`No ${key} specified`)
|
|
}
|
|
for (const [key, value] of Object.entries(prodValues)) {
|
|
if (!value) throw new MissingEnvVarsError(`No ${key} specified`)
|
|
}
|
|
} else {
|
|
for (const [key, value] of Object.entries(prodValues)) {
|
|
if (!value) throw new MissingEnvVarsError(`No ${key} specified`)
|
|
}
|
|
}
|
|
}
|
|
|
|
private loadMethods() {
|
|
String.prototype.removeIndents = function(this: string) {
|
|
return this.replace(/^ */gm, "")
|
|
}
|
|
|
|
String.prototype.capitalizeFirstLetter = function(this: string) {
|
|
return this[0].toUpperCase() + this.slice(1).toLowerCase()
|
|
}
|
|
}
|
|
}
|
|
|
|
export { client, Illegitimate, redis }
|