Merge branch 'dev' into 'main'
Added new init function See merge request illegitimate/illegitimate-bot!140
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
interface ProdConfig {
|
||||
token: string
|
||||
mongoURI: string
|
||||
dev: string
|
||||
hypixelapikey: string
|
||||
redisURI: string
|
||||
token: string | undefined
|
||||
mongoURI: string | undefined
|
||||
dev: string | undefined
|
||||
hypixelapikey: string | undefined
|
||||
redisURI: string | undefined
|
||||
}
|
||||
|
||||
interface DevConfig {
|
||||
devtoken: string
|
||||
clientid: string
|
||||
devid: string
|
||||
guildid: string
|
||||
devtoken: string | undefined
|
||||
clientid: string | undefined
|
||||
devid: string | undefined
|
||||
guildid: string | undefined
|
||||
}
|
||||
|
||||
export default interface Config {
|
||||
|
||||
@@ -31,10 +31,10 @@ async function autoDeployCommands() {
|
||||
}
|
||||
}
|
||||
|
||||
const rest = new REST({ version: "10" }).setToken(config.dev.devtoken)
|
||||
const rest = new REST({ version: "10" }).setToken(config.dev.devtoken!)
|
||||
|
||||
const currentCommands = (await rest.get(
|
||||
Routes.applicationGuildCommands(config.dev.devid, config.dev.guildid),
|
||||
Routes.applicationGuildCommands(config.dev.devid!, config.dev.guildid!),
|
||||
)) as RESTGetAPIApplicationGuildCommandResult[]
|
||||
|
||||
const currentCommandsInfo = currentCommands.map(command => {
|
||||
@@ -94,8 +94,8 @@ async function autoDeployCommands() {
|
||||
|
||||
const data = (await rest.put(
|
||||
Routes.applicationGuildCommands(
|
||||
config.dev.devid,
|
||||
config.dev.guildid,
|
||||
config.dev.devid!,
|
||||
config.dev.guildid!,
|
||||
),
|
||||
{ body: commands },
|
||||
)) as RESTPutAPIApplicationGuildCommandsJSONBody[]
|
||||
|
||||
@@ -40,11 +40,11 @@ export class ExtendedClient extends Client {
|
||||
let token: string
|
||||
if (process.env.NODE_ENV === "dev") {
|
||||
console.log("Running in development mode.")
|
||||
token = config.dev.devtoken
|
||||
token = config.dev.devtoken!
|
||||
autoDeployCommands()
|
||||
} else {
|
||||
console.log("Running in production mode.")
|
||||
token = config.prod.token
|
||||
token = config.prod.token!
|
||||
}
|
||||
|
||||
this.login(token)
|
||||
|
||||
@@ -3,17 +3,17 @@ import "dotenv/config"
|
||||
|
||||
const config: Config = {
|
||||
prod: {
|
||||
token: process.env.TOKEN!,
|
||||
mongoURI: process.env.MONGOURI!,
|
||||
dev: process.env.DEV!,
|
||||
hypixelapikey: process.env.HYPIXELAPIKEY!,
|
||||
redisURI: process.env.REDISURI!,
|
||||
token: process.env.TOKEN,
|
||||
mongoURI: process.env.MONGOURI,
|
||||
dev: process.env.DEV,
|
||||
hypixelapikey: process.env.HYPIXELAPIKEY,
|
||||
redisURI: process.env.REDISURI,
|
||||
},
|
||||
dev: {
|
||||
devtoken: process.env.DEVTOKEN!,
|
||||
clientid: process.env.CLIENTID!,
|
||||
devid: process.env.DEVID!,
|
||||
guildid: process.env.GUILDID!,
|
||||
devtoken: process.env.DEVTOKEN,
|
||||
clientid: process.env.CLIENTID,
|
||||
devid: process.env.DEVID,
|
||||
guildid: process.env.GUILDID,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ import { ExtendedClient as Client } from "./Client"
|
||||
import config from "./Config"
|
||||
import { redis } from "./Redis"
|
||||
import { connect } from "mongoose"
|
||||
// import init from "./Init"
|
||||
import init from "./Init"
|
||||
const client = new Client()
|
||||
|
||||
export default class Illegitimate {
|
||||
constructor() {}
|
||||
|
||||
async start() {
|
||||
// init()
|
||||
init()
|
||||
|
||||
client.start()
|
||||
|
||||
@@ -17,7 +17,7 @@ export default class Illegitimate {
|
||||
console.log("Connected to Redis")
|
||||
})
|
||||
|
||||
connect(config.prod.mongoURI, {}).then(() => {
|
||||
connect(config.prod.mongoURI!, {}).then(() => {
|
||||
console.log("Connected to MongoDB")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,22 +5,17 @@ const devValues = config.dev
|
||||
|
||||
export default function init() {
|
||||
if (process.env.NODE_ENV === "dev") {
|
||||
Object.keys(devValues).forEach(key => {
|
||||
if (!process.env[key.toUpperCase()]) {
|
||||
throw new Error(`[DEV] Missing environment variable: ${key}`)
|
||||
for (const [key, value] of Object.entries(devValues)) {
|
||||
if (!value) throw new Error(`No ${key} specified`)
|
||||
}
|
||||
})
|
||||
|
||||
Object.keys(prodValues).forEach(key => {
|
||||
if (!process.env[key.toUpperCase()]) {
|
||||
throw new Error(`[PROD] Missing environment variable: ${key}`)
|
||||
for (const [key, value] of Object.entries(prodValues)) {
|
||||
if (!value) throw new Error(`No ${key} specified`)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Object.keys(prodValues).forEach(key => {
|
||||
if (!process.env[key]) {
|
||||
throw new Error(`[PROD] Missing environment variable: ${key}`)
|
||||
}
|
||||
})
|
||||
for (const [key, value] of Object.entries(prodValues)) {
|
||||
if (!value) throw new Error(`No ${key} specified`)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Redis } from "ioredis"
|
||||
import config from "./Config"
|
||||
|
||||
const redis = new Redis(config.prod.redisURI)
|
||||
const redis = new Redis(config.prod.redisURI!)
|
||||
|
||||
export { redis }
|
||||
|
||||
Reference in New Issue
Block a user