Updated env
This commit is contained in:
@@ -24,7 +24,7 @@ export default {
|
||||
const user = (interaction.options.getUser("user") || interaction.user) as User
|
||||
let size: number
|
||||
|
||||
if (user.id === env.prod.dev) {
|
||||
if (user.id === env.prod.DEV) {
|
||||
size = Math.floor(Math.random() * 30) + 1
|
||||
} else {
|
||||
size = Math.floor(Math.random() * 10) + 1
|
||||
|
||||
@@ -6,7 +6,7 @@ import env from "~/utils/Env.js"
|
||||
const cmd: SubCommand = async (interaction) => {
|
||||
await interaction.deferReply()
|
||||
|
||||
if (interaction.user.id !== env.prod.dev) {
|
||||
if (interaction.user.id !== env.prod.DEV) {
|
||||
await interaction.editReply("You are not allowed to use this command.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ const cmd: SubCommand = async (interaction) => {
|
||||
|
||||
const discordMember = interaction.member as GuildMember
|
||||
|
||||
if (discordMember.user.id !== env.prod.dev) {
|
||||
if (discordMember.user.id !== env.prod.DEV) {
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: "You do not have permission to use this command.",
|
||||
|
||||
@@ -24,7 +24,7 @@ const cmd: SubCommand = async (interaction) => {
|
||||
return
|
||||
}
|
||||
|
||||
if (discordMember.user.id !== env.prod.dev) {
|
||||
if (discordMember.user.id !== env.prod.DEV) {
|
||||
await interaction.editReply({
|
||||
embeds: [{
|
||||
description: "You do not have permission to use this command.",
|
||||
|
||||
@@ -41,6 +41,8 @@ export default {
|
||||
const timeString = interaction.options.getString("time")!
|
||||
const reason = interaction.options.getString("reason") || "No reason provided"
|
||||
const mod = interaction.member! as GuildMember
|
||||
// FIXME: report error to ms manitainer
|
||||
// @ts-expect-error: i'll file a bu report later
|
||||
const time = ms(timeString)
|
||||
|
||||
if (!time) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export default {
|
||||
if (interaction.customId === "staffapply") {
|
||||
await interaction.deferReply({ flags: MessageFlags.Ephemeral })
|
||||
|
||||
if (user.user.id !== env.prod.dev) {
|
||||
if (user.user.id !== env.prod.DEV) {
|
||||
if (status === "0") {
|
||||
await interaction.editReply("Staff applications are currently closed.")
|
||||
return
|
||||
|
||||
@@ -4,7 +4,7 @@ import * as schema from "./schema.js"
|
||||
|
||||
const db = drizzle({
|
||||
connection: {
|
||||
url: env.prod.postgresURI
|
||||
url: env.prod.POSTGRESURI
|
||||
},
|
||||
schema: schema
|
||||
})
|
||||
|
||||
@@ -49,7 +49,7 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
|
||||
}).sort((a, b) => a.name > b.name ? 1 : -1)
|
||||
|
||||
client.on("ready", async (c) => {
|
||||
const guildclient = c.guilds.cache.get(env.dev.guildid)!
|
||||
const guildclient = c.guilds.cache.get(env.dev.GUILDID)!
|
||||
const currentCommands = await guildclient.commands.fetch()
|
||||
if (!currentCommands) return
|
||||
|
||||
|
||||
@@ -34,15 +34,15 @@ export class ExtendedClient extends Client {
|
||||
let token: string
|
||||
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
|
||||
log("Running in development mode. [tsx]", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.devtoken
|
||||
token = env.dev.DEVTOKEN
|
||||
autoDeployCommands("ts", this)
|
||||
} else if (process.env.NODE_ENV === "dev" && !process.env.TYPESCRIPT) {
|
||||
log("Running in development mode.", "info", { type: "preset", color: "lavender" })
|
||||
token = env.dev.devtoken
|
||||
token = env.dev.DEVTOKEN
|
||||
autoDeployCommands("js", this)
|
||||
} else {
|
||||
log("Running in production mode.", "info", { type: "preset", color: "green" })
|
||||
token = env.prod.token
|
||||
token = env.prod.TOKEN
|
||||
}
|
||||
|
||||
this.login(token)
|
||||
|
||||
@@ -1,47 +1,42 @@
|
||||
import { createEnv } from "@t3-oss/env-core"
|
||||
import { z } from "zod"
|
||||
import { MissingEnvVarsError } from "./Classes/EnvVarError.js"
|
||||
|
||||
const prodEnvSchema = z.object({
|
||||
token: z.string({ message: "Missing or invalid TOKEN" }),
|
||||
dev: z.string({ message: "Missing or invalid DEV" }),
|
||||
hypixelapikey: z.string({ message: "Missing or invalid HYPIXELAPIKEY" }),
|
||||
redisURI: z.string({ message: "Missing or invalid REDISURI" }),
|
||||
postgresURI: z.string({ message: "Missing or invalid POSTGRESURI" })
|
||||
const prodEnv = createEnv({
|
||||
server: {
|
||||
TOKEN: z.string({ message: "TOKEN" }).min(1),
|
||||
DEV: z.string({ message: "DEV" }).min(1),
|
||||
HYPIXELAPIKEY: z.string({ message: "HYPIXELAPIKEY" }).min(1),
|
||||
REDISURI: z.string({ message: "REDISURI" }).min(1),
|
||||
POSTGRESURI: z.string({ message: "POSTGRESURI" }).min(1)
|
||||
},
|
||||
runtimeEnv: process.env,
|
||||
onValidationError: (e) => {
|
||||
const allErrors = e.map(err => err.message).join(" ")
|
||||
|
||||
throw new MissingEnvVarsError(`[PROD]: ${allErrors}`)
|
||||
}
|
||||
})
|
||||
|
||||
const devEnvSchema = z.object({
|
||||
devtoken: z.string({ message: "Missing or invalid DEVTOKEN" }),
|
||||
clientid: z.string({ message: "Missing or invalid CLIENTID" }),
|
||||
devid: z.string({ message: "Missing or invalid DEVID" }),
|
||||
guildid: z.string({ message: "Missing or invalid GUILDID" })
|
||||
const devEnv = createEnv({
|
||||
server: {
|
||||
DEVTOKEN: z.string({ message: "DEVTOKEN" }).min(1),
|
||||
CLIENTID: z.string({ message: "CLIENTID" }).min(1),
|
||||
DEVID: z.string({ message: "DEVID" }).min(1),
|
||||
GUILDID: z.string({ message: "GUILDID" }).min(1)
|
||||
},
|
||||
runtimeEnv: process.env,
|
||||
skipValidation: process.env.NODE_ENV !== "dev",
|
||||
onValidationError: (e) => {
|
||||
const allErrors = e.map(err => err.message).join(" ")
|
||||
|
||||
throw new MissingEnvVarsError(`[DEV]: ${allErrors}`)
|
||||
}
|
||||
})
|
||||
|
||||
const parsedProdEnv = prodEnvSchema.safeParse({
|
||||
token: process.env.TOKEN,
|
||||
dev: process.env.DEV,
|
||||
hypixelapikey: process.env.HYPIXELAPIKEY,
|
||||
redisURI: process.env.REDISURI,
|
||||
postgresURI: process.env.POSTGRESURI
|
||||
})
|
||||
|
||||
const parsedDevEnv = devEnvSchema.safeParse({
|
||||
devtoken: process.env.DEVTOKEN,
|
||||
clientid: process.env.CLIENTID,
|
||||
devid: process.env.DEVID,
|
||||
guildid: process.env.GUILDID
|
||||
})
|
||||
|
||||
if (!parsedProdEnv.success) {
|
||||
throw new MissingEnvVarsError(parsedProdEnv.error.errors[0].message)
|
||||
}
|
||||
|
||||
if (!parsedDevEnv.success && process.env.NODE_ENV === "dev") {
|
||||
throw new MissingEnvVarsError(parsedDevEnv.error.errors[0].message)
|
||||
}
|
||||
|
||||
const env = {
|
||||
prod: parsedProdEnv.data,
|
||||
dev: parsedDevEnv.data
|
||||
} as { prod: z.infer<typeof prodEnvSchema>, dev: z.infer<typeof devEnvSchema> }
|
||||
prod: prodEnv,
|
||||
dev: devEnv
|
||||
}
|
||||
|
||||
export default env
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import axios from "axios"
|
||||
import { IGuild, IGuildData, IPlayer, IPlayerData } from "~/typings"
|
||||
import env from "~/utils/Env.js"
|
||||
const apikey = env.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/v2/player"
|
||||
|
||||
@@ -8,7 +8,7 @@ import loadAllEvents from "./Events/loadevents.js"
|
||||
import { log } from "./Logger.js"
|
||||
|
||||
const client = new Client()
|
||||
const redis = new Redis(env.prod.redisURI)
|
||||
const redis = new Redis(env.prod.REDISURI)
|
||||
const player = new Player(client)
|
||||
|
||||
let ft: "js" | "ts"
|
||||
|
||||
Reference in New Issue
Block a user