Merged in dotenv changes

This commit is contained in:
Noah Heague
2021-09-05 15:40:00 +10:00
6 changed files with 38 additions and 6 deletions
+1
View File
@@ -2,3 +2,4 @@ node_modules
.idea
.vscode
yarn-error.log
.env
+3 -1
View File
@@ -4,7 +4,8 @@
"main": "src/index.ts",
"license": "MIT",
"scripts": {
"start": "ts-node src/index.ts"
"start": "ts-node src/index.ts",
"setup": "./scripts/createEnv.sh"
},
"devDependencies": {
"@types/jest": "^27.0.1",
@@ -21,6 +22,7 @@
"@discordjs/rest": "^0.1.0-canary.0",
"deezer-api-ts": "^1.2.1",
"discord.js": "^13.1.0",
"dotenv": "^10.0.0",
"songlink-api": "^1.0.0",
"ts-node": "^10.2.0",
"winston": "^3.3.3"
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
DOT_ENV_PATH="$(dirname "$0")/../.env"
# Wipe existing file
rm "$DOT_ENV_PATH" 2> /dev/null
# Setup env based on $ENV
if [[ "$ENV" != "PROD" ]]; then
# Non-prod environment
echo "ENV=DEV" >> "$DOT_ENV_PATH"
echo "DISCORD_TOKEN=${NON_PROD_DISCORD_TOKEN:-"_"}" >> "$DOT_ENV_PATH"
else
# Prod environment
echo "ENV=PROD" >> "$DOT_ENV_PATH"
echo "DISCORD_TOKEN=${PROD_DISCORD_TOKEN:-"_"}" >> "$DOT_ENV_PATH"
fi
+12 -4
View File
@@ -2,6 +2,9 @@ import { Client, Intents } from "discord.js";
import { LoggerLayers } from "./config";
import { registerSlashCommands, slashCommands, tidyGuildCommands, SlashCommand } from "./slashCommands/register";
import { createLayeredLogger } from "./utils/logger";
import { config } from "dotenv";
config();
const logger = createLayeredLogger(LoggerLayers.client);
@@ -32,13 +35,18 @@ client.on("interactionCreate", async (interaction) => {
(async () => {
try {
await client.login(process.env.DISCORDTOKEN);
if (!process.env.ENV) {
throw new Error("Environment not configured");
}
logger.info(`Running on ${process.env.ENV} environment`);
await client.login(process.env.DISCORD_TOKEN);
logger.info(`Logged in successfully to ${client.guilds.cache.size} guilds`);
} catch (e) {
logger.error("Log in Failed:", e);
} finally {
await tidyGuildCommands(client);
await registerSlashCommands(client);
} catch (e) {
logger.error("Log in Failed:", e);
}
})();
+1 -1
View File
@@ -28,7 +28,7 @@ export const slashCommands: SlashCommand[] = [
}
];
const rest = new REST({ version: "9" }).setToken(process.env.DISCORDTOKEN);
const rest = new REST({ version: "9" }).setToken(process.env.DISCORD_TOKEN);
export const registerSlashCommands = async (client: Client): Promise<void> => {
try {
logger.info("Registering slash commands");
+5
View File
@@ -1486,6 +1486,11 @@ dot-prop@^6.0.1:
dependencies:
is-obj "^2.0.0"
dotenv@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
electron-to-chromium@^1.3.811:
version "1.3.830"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.830.tgz#40e3144204f8ca11b2cebec83cf14c20d3499236"