diff --git a/bot/scripts/createEnv.sh b/bot/scripts/createEnv.sh index 68e196a6e..c22c4f13a 100644 --- a/bot/scripts/createEnv.sh +++ b/bot/scripts/createEnv.sh @@ -12,10 +12,12 @@ if [[ "$ENV" != "PROD" ]]; then echo "DEV_SERVER_ID=769803764021592104" >> "$DOT_ENV_PATH" # Where is testing taking place? echo "BOT_CLIENT_SECRET=${NON_PROD_BOT_CLIENT_SECRET:-"_"}" >> "$DOT_ENV_PATH" echo "BOT_CLIENT_ID=${NON_PROD_BOT_CLIENT_ID:-"_"}" >> "$DOT_ENV_PATH" + echo "CONF_JSON5_LOCATION=./conf.json5" >> "$DOT_ENV_PATH" else # Prod environment echo "ENV=PROD" >> "$DOT_ENV_PATH" echo "DISCORD_TOKEN=${PROD_DISCORD_TOKEN:-"_"}" >> "$DOT_ENV_PATH" echo "BOT_CLIENT_SECRET=${PROD_BOT_CLIENT_SECRET:-"_"}" >> "$DOT_ENV_PATH" echo "BOT_CLIENT_ID=${PROD_BOT_CLIENT_ID:-"_"}" >> "$DOT_ENV_PATH" + echo "CONF_JSON5_LOCATION=./conf.json5" >> "$DOT_ENV_PATH" fi diff --git a/bot/src/index.ts b/bot/src/index.ts index c468cae78..c172ad4d1 100644 --- a/bot/src/index.ts +++ b/bot/src/index.ts @@ -1,5 +1,5 @@ import { Client, Intents } from "discord.js"; -import { ProcessEnv } from "setup"; +import { ProcessEnv } from "./setup"; import { LoggerLayers } from "./config"; import { registerSlashCommands, slashCommands, SlashCommand } from "./slashCommands/register"; import { createLayeredLogger } from "./utils/logger"; diff --git a/bot/src/server/middleware.ts b/bot/src/server/middleware.ts index 9b3fffe48..d87749b29 100644 --- a/bot/src/server/middleware.ts +++ b/bot/src/server/middleware.ts @@ -1,14 +1,14 @@ -import { LoggerLayers } from "config"; +import { LoggerLayers } from "../config"; import { RequestHandler } from "express"; -import { ProcessEnv } from "setup"; -import { createLayeredLogger } from "utils/logger"; +import { ProcessEnv } from "../setup"; +import { createLayeredLogger } from "../utils/logger"; const logger = createLayeredLogger(LoggerLayers.serverAuth); /** - * Middleware that checks that a webhook request has Authorization set to + * Middleware that checks that a webhook request has Authorization set to * exactly "Bearer $CLIENT_SECRET". - * + * * This is to prevent things like users spoofing webhook events. * $CLIENT_SECRET is part of the registered tachi OAuth2 client. */ diff --git a/bot/src/server/server.ts b/bot/src/server/server.ts index c9278320d..654d57b44 100644 --- a/bot/src/server/server.ts +++ b/bot/src/server/server.ts @@ -1,10 +1,10 @@ import express, { Express } from "express"; -import { LoggerLayers } from "config"; -import { createLayeredLogger } from "utils/logger"; +import { LoggerLayers } from "../config"; +import { createLayeredLogger } from "../utils/logger"; import { ValidateWebhookRequest } from "./middleware"; import { WebhookEvents, APITokenDocument } from "tachi-common"; -import { BotConfig, ProcessEnv } from "setup"; -import { RequestTypes, TachiServerV1Request } from "utils/fetch-tachi"; +import { BotConfig, ProcessEnv } from "../setup"; +import { RequestTypes, TachiServerV1Request } from "../utils/fetch-tachi"; const app: Express = express(); @@ -21,7 +21,7 @@ app.set("query parser", "simple"); /** * Return the status of this bot and the version it's running. - * + * * @name GET / */ app.get("/", (req, res) => { @@ -37,7 +37,7 @@ app.get("/", (req, res) => { /** * Listens for tachi-server style webhook calls. - * + * * @name POST /webhook */ app.post("/webhook", ValidateWebhookRequest, (req, res) => { @@ -71,7 +71,7 @@ app.post("/webhook", ValidateWebhookRequest, (req, res) => { /** * Our OAuth2 Callback handler. Note that this is a GET request, as per * OAuth spec, but does perform *real* mutations on data. It's awkward. - * + * * @param code - The intermediate code for us to send back. * @param context - The discordID we fired this auth request with. * @@ -111,7 +111,7 @@ app.get("/oauth/callback", async (req, res) => { /** * 404 Handler. If something gets to this point, they haven't matched with anything. - * + * * @name ALL * */ app.all("*", (req, res) => { diff --git a/bot/src/setup.ts b/bot/src/setup.ts index 7ceb1fb33..d07a31bbd 100644 --- a/bot/src/setup.ts +++ b/bot/src/setup.ts @@ -1,6 +1,6 @@ -import { LoggerLayers } from "config"; -import { createLayeredLogger } from "utils/logger"; -import { FormatPrError } from "utils/prudence"; +import { LoggerLayers } from "./config"; +import { createLayeredLogger } from "./utils/logger"; +import { FormatPrError } from "./utils/prudence"; import JSON5 from "json5"; import fs from "fs"; import Prudence from "prudence"; @@ -27,7 +27,7 @@ function ParseBotConfig(fileLoc = "conf.json5"): BotConfig { const contents = fs.readFileSync(fileLoc, "utf-8"); data = JSON5.parse(contents); } catch (err) { - logger.crit("Failed to find a valid conf.json5 file. Cannot boot.", { err }); + logger.error("Failed to find a valid conf.json5 file. Cannot boot.", { err }); throw err; } @@ -39,7 +39,7 @@ function ParseBotConfig(fileLoc = "conf.json5"): BotConfig { }); if (err) { - logger.crit(FormatPrError(err, "Invalid conf.json5 file. Cannot safely boot.")); + logger.error(FormatPrError(err, "Invalid conf.json5 file. Cannot safely boot.")); throw err; } @@ -63,7 +63,7 @@ function ParseEnvVars() { }, {}, { allowExcessKeys: true }); if (err) { - logger.crit(FormatPrError(err, "Invalid environment. Cannot safely boot.")); + logger.error(FormatPrError(err, "Invalid environment. Cannot safely boot.")); throw err; } diff --git a/bot/src/slashCommands/register.ts b/bot/src/slashCommands/register.ts index 4ef1e650a..cf341743c 100644 --- a/bot/src/slashCommands/register.ts +++ b/bot/src/slashCommands/register.ts @@ -3,7 +3,7 @@ import { REST } from "@discordjs/rest"; import { APIApplicationCommandOption } from "discord-api-types"; import { Routes } from "discord-api-types/v9"; import { Client, CommandInteraction } from "discord.js"; -import { ProcessEnv } from "setup"; +import { ProcessEnv } from "../setup"; import { LoggerLayers } from "../config"; import { help } from "../help/help"; import { createLayeredLogger } from "../utils/logger"; diff --git a/bot/src/utils/fetch-tachi.ts b/bot/src/utils/fetch-tachi.ts index cb0c442d5..951c07c88 100644 --- a/bot/src/utils/fetch-tachi.ts +++ b/bot/src/utils/fetch-tachi.ts @@ -1,5 +1,5 @@ -import { LoggerLayers } from "config"; -import { BotConfig } from "setup"; +import { LoggerLayers } from "../config"; +import { BotConfig } from "../setup"; import { integer, SuccessfulAPIResponse, UnsuccessfulAPIResponse } from "tachi-common"; import { createLayeredLogger } from "./logger"; @@ -29,7 +29,7 @@ export async function TachiServerV1Request(method: Exclude(method: Exclude(url: string, params: Record< const urlParams = new URLSearchParams(params); const realUrl = `${PrependTachiUrl(url, "1")}?${urlParams.toString()}`; - + const res = await fetch(realUrl); const json = await res.json(); const contents = { ...json, statusCode: res.status }; @@ -75,7 +75,7 @@ export async function TachiServerV1Get(url: string, params: Record< return contents; } catch (err) { logger.error(`Failed while requesting GET ${url}.`, { err }); - + throw err; } } @@ -101,4 +101,4 @@ function LogRequestResult(loggerUrl: string, res: APIResponse): void { } else { logger.debug(`Request ${loggerUrl} was successful: ${res.description} (${res.statusCode})`); } -} \ No newline at end of file +}