Merge pull request #28 from TeamNewGuys/user-can-view-profile

Fixed import paths
This commit is contained in:
Noah
2021-09-11 13:38:48 +10:00
committed by GitHub
7 changed files with 30 additions and 28 deletions
+2
View File
@@ -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
+1 -1
View File
@@ -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";
+5 -5
View File
@@ -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.
*/
+8 -8
View File
@@ -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) => {
+6 -6
View File
@@ -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;
}
+1 -1
View File
@@ -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";
+7 -7
View File
@@ -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<T>(method: Exclude<RequestTypes, Requ
const loggerUrl = `${method} ${realUrl}`;
logger.debug(`Making a request to ${loggerUrl}.`);
try {
const res = await fetch(realUrl, {
method,
@@ -47,7 +47,7 @@ export async function TachiServerV1Request<T>(method: Exclude<RequestTypes, Requ
return contents;
} catch (err) {
logger.error(`Failed while requesting ${method} ${realUrl}.`, { err });
// Throw the error upwards for it to be caught be a higher handler.
throw err;
}
@@ -65,7 +65,7 @@ export async function TachiServerV1Get<T = unknown>(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<T = unknown>(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<unknown>): void {
} else {
logger.debug(`Request ${loggerUrl} was successful: ${res.description} (${res.statusCode})`);
}
}
}