Skip to content

Commit

Permalink
Add Inherited Config to Support Multi-Environment Configuration (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
LamboCreeper authored Jan 19, 2022
1 parent 1adfd69 commit db7794c
Show file tree
Hide file tree
Showing 32 changed files with 267 additions and 173 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules/
.nyc_output/
coverage/
.codacy-coverage/
.vscode
.vscode
src/config.dev.json
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This repository contains the code for the CodeSupport Discord Bot. The project i
- [Axios](https://www.npmjs.com/package/axios)
- [Twitter](https://www.npmjs.com/package/twitter)
- [dotenv](https://www.npmjs.com/package/dotenv)
- [Inherited Config](https://www.npmjs.com/package/@codesupport/inherited-config)

### Development
- [TypeScript](https://www.npmjs.com/package/typescript)
Expand All @@ -39,6 +40,7 @@ This repository contains the code for the CodeSupport Discord Bot. The project i
- You will need to supply the `DISCORD_TOKEN` environment variable

If you would like to use a `.env` file for storing your environment variables please create it in the root of the project.
If you would like to overwrite values in `config.json` to better suit your local environment create a file named `config.dev.json` with any values you would like to overwrite `config.json` with.

## Structure
- All source code lives inside `src/`
Expand Down
163 changes: 115 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"start": "node -r dotenv/config ./build/index.js",
"build": "tsc",
"dev": "cross-env NODE_ENV=development nodemon --watch src --ext ts --exec 'ts-node -r dotenv/config ./src/index.ts'",
"dev": "cross-env NODE_ENV=dev nodemon --watch src --ext ts --exec 'ts-node -r dotenv/config ./src/index.ts'",
"coverage": "nyc --reporter=lcov --reporter=text-summary npm test",
"test": "ts-mocha test/**/*Test.ts test/**/**/*Test.ts test/appTest.ts --exit",
"test:debug": "ts-mocha test/**/*Test.ts test/**/**/*Test.ts test/appTest.ts --timeout 999999999 --exit",
Expand All @@ -33,6 +33,7 @@
"npm": ">=7.0.0"
},
"dependencies": {
"@codesupport/inherited-config": "^1.0.2",
"axios": "^0.21.1",
"axios-cache-adapter": "^2.5.0",
"discord.js": "^13.5.0",
Expand Down
9 changes: 6 additions & 3 deletions src/abstracts/LogMessageDeleteHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MessageEmbed, Message, TextChannel, ColorResolvable} from "discord.js";
import { LOG_CHANNEL_ID, EMBED_COLOURS } from "../config.json";
import EventHandler from "./EventHandler";
import getConfigValue from "../utils/getConfigValue";
import GenericObject from "../interfaces/GenericObject";

abstract class LogMessageDeleteHandler extends EventHandler {
async sendLog(message: Message): Promise<void> {
Expand All @@ -10,9 +11,11 @@ abstract class LogMessageDeleteHandler extends EventHandler {
embed.setTitle("Message Deleted");
embed.setDescription(`Author: ${message.author}\nChannel: ${message.channel}`);
embed.addField("Message", message.content);
embed.setColor(<ColorResolvable>EMBED_COLOURS.DEFAULT);
embed.setColor(getConfigValue<GenericObject<ColorResolvable>>("EMBED_COLOURS").DEFAULT);

const logsChannel = message.guild?.channels.cache.find(channel => channel.id === LOG_CHANNEL_ID) as TextChannel;
const logsChannel = message.guild?.channels.cache.find(
channel => channel.id === getConfigValue<string>("LOG_CHANNEL_ID")
) as TextChannel;

await logsChannel?.send({ embeds: [embed] });
}
Expand Down
Loading

0 comments on commit db7794c

Please sign in to comment.