55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import { RedisClient } from "bun"
|
|
import { LoadEventsOptions } from "~/typings"
|
|
import { ExtendedClient as Client } from "~/utils/Client"
|
|
import env from "./Env"
|
|
import loadAllEvents from "./Events/loadevents"
|
|
import { log } from "./Logger"
|
|
|
|
const client = new Client()
|
|
const redis = new RedisClient(env.prod.REDISURI)
|
|
|
|
class Illegitimate {
|
|
async start() {
|
|
await loadAllEvents(client, this.getOpts())
|
|
await client.start()
|
|
await this.databases()
|
|
this.loadMethods()
|
|
}
|
|
|
|
private async databases() {
|
|
redis.connect().then(() => {
|
|
log.custom("Connected to Redis", "info", { type: "preset", color: "green" })
|
|
}).catch(() => {
|
|
log.error("Failed to connect to Redis")
|
|
}).finally(() => {
|
|
redis.close()
|
|
})
|
|
}
|
|
|
|
private getOpts(): LoadEventsOptions {
|
|
if (process.env.BUN__DOCKER === "true") {
|
|
return {
|
|
ft: "js",
|
|
dir: ""
|
|
}
|
|
} else {
|
|
return {
|
|
ft: "ts",
|
|
dir: "src"
|
|
}
|
|
}
|
|
}
|
|
|
|
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 }
|