diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-07-10 21:54:43 +0200 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-07-10 21:54:43 +0200 |
commit | 627979e836edd0801f9201a98e239bf697a211be (patch) | |
tree | 0cf2d347d4eb6f02bfcc714307c4e211664c53b9 /config | |
parent | 131b44f23be250aed2aeacdb51321b141d2ede4f (diff) | |
download | tanzanite-627979e836edd0801f9201a98e239bf697a211be.tar.gz tanzanite-627979e836edd0801f9201a98e239bf697a211be.tar.bz2 tanzanite-627979e836edd0801f9201a98e239bf697a211be.zip |
allow more config options to be null / not set
Diffstat (limited to 'config')
-rw-r--r-- | config/Config.ts | 214 | ||||
-rw-r--r-- | config/example-options.ts | 2 |
2 files changed, 191 insertions, 25 deletions
diff --git a/config/Config.ts b/config/Config.ts index 7504658..4aae10a 100644 --- a/config/Config.ts +++ b/config/Config.ts @@ -1,15 +1,52 @@ import type { Snowflake } from 'discord.js'; -export class Config { +/** + * Different options for the bot. + */ +export class Config implements ConfigOptions { + /** + * Credentials for various services that the bot depends on. + */ public credentials: Credentials; + + /** + * The environment that the bot is operating under. + */ public environment: Environment; + + /** + * Bot developers. + */ public owners: Snowflake[]; + + /** + * A string that needs to come before text commands. + */ public prefix: string; + + /** + * Various discord channels that logs will be sent in. + */ public channels: Channels; + + /** + * Options for the Postgres database connection. + */ public db: DataBase; + + /** + * Options for what events to log. + */ public logging: Logging; + + /** + * Information regarding the bot's support server. + */ public supportGuild: SupportGuild; + /** + * @param options The options + */ public constructor(options: ConfigOptions) { this.credentials = options.credentials; this.environment = options.environment; @@ -32,6 +69,8 @@ export class Config { return this.credentials.betaToken; case 'development': return this.credentials.devToken; + default: + throw new TypeError(`Unexpected environment: "${this.environment}"`); } } @@ -57,52 +96,179 @@ export class Config { } } +/** + * The options to be provided to the {@link Config} class. + */ export interface ConfigOptions { + /** + * Credentials for various services that the bot depends on. + */ credentials: Credentials; + + /** + * The environment that the bot is operating under. + */ environment: Environment; + + /** + * Bot developers. + */ owners: Snowflake[]; + + /** + * A string that needs to come before text commands. + */ prefix: string; + + /** + * Various discord channels that logs will be sent in. + */ channels: Channels; + + /** + * Options for the Postgres database connection. + */ db: DataBase; + + /** + * Options for what events to log. + */ logging: Logging; + + /** + * Information regarding the bot's support server. + */ supportGuild: SupportGuild; } -interface Credentials { +/** + * Credentials for various services that the bot depends on. + */ +export interface Credentials { + /** + * The discord bot token - used when in a 'production' environment. + */ token: string; + + /** + * The discord bot token - used when in a 'beta' environment. + */ betaToken: string; + + /** + * The discord bot token - used when in a 'development' environment. + */ devToken: string; - hypixelApiKey: string; - wolframAlphaAppId: string; - imgurClientId: string; - imgurClientSecret: string; - sentryDsn: string; - perspectiveApiKey: string; -} -type Environment = 'production' | 'beta' | 'development'; + /** + * Api Key for the Hypixel Minecraft Java server. + * @see {@link https://api.hypixel.net/#section/Authentication/ApiKey} + */ + hypixelApiKey: string | null; + + /** + * The app id for an API Application for WorlframAlpha + * @see {@link https://products.wolframalpha.com/api/} + */ + wolframAlphaAppId: string | null; -interface Channels { - log: Snowflake; - error: Snowflake; - dm: Snowflake; - servers: Snowflake; + /** + * The client id for Imgur's API + * @see {@link https://apidocs.imgur.com/#authorization-and-oauth} + */ + imgurClientId: string | null; + + /** + * The client secret for Imgur's API + * @see {@link https://apidocs.imgur.com/#authorization-and-oauth} + */ + imgurClientSecret: string | null; + + /** + * The sentry DSN (Data Source Name) for error reporting + * @see {@link https://docs.sentry.io/product/sentry-basics/dsn-explainer/} + */ + sentryDsn: string | null; + + /** + * The Perspective API Key + * @see {@link https://perspectiveapi.com/} + */ + perspectiveApiKey: string | null; } -interface DataBase { +/** + * The possible environments that the bot can be running in. + */ +export type Environment = 'production' | 'beta' | 'development'; + +/** + * Various discord channels that logs will be sent in. + */ +export type Channels = { + /** + * The id of a channel to send logging messages in, + * use an empty string for no channel to be used. + */ + [Key in ConfigChannelKey]: Snowflake | ''; +}; + +/** + * The type of information to be sent in the configured channel. + */ +export type ConfigChannelKey = 'log' | 'error' | 'dm' | 'servers'; + +/** + * Options for the Postgres database connection. + */ +export interface DataBase { + /** + * The host of the database. + */ host: string; + + /** + * The port of the database. + */ port: number; + + /** + * The username which is used to authenticate against the database. + */ username: string; + + /** + * The password which is used to authenticate against the database. + */ password: string; } -interface Logging { - db: boolean; - verbose: boolean; - info: boolean; -} +/** + * Options for what events to log. + */ +export type Logging = { + /** + * Whether or not to log database queries, verbose logs, or informational logs + */ + [Key in LoggingType]: boolean; +}; -interface SupportGuild { - id: Snowflake; - invite: string; +/** + * The logging level that can be changed. + */ +export type LoggingType = 'db' | 'verbose' | 'info'; + +/** + * Information regarding the bot's support server. + */ +export interface SupportGuild { + /** + * The id of the support server. + */ + id: Snowflake | null; + + /** + * An invite link to the support server. + */ + invite: string | null; } diff --git a/config/example-options.ts b/config/example-options.ts index 1289c8d..43b805e 100644 --- a/config/example-options.ts +++ b/config/example-options.ts @@ -9,7 +9,7 @@ export default new Config({ wolframAlphaAppId: '[APP_ID]', imgurClientId: '[CLIENT_ID]', imgurClientSecret: '[CLIENT_SECRET]', - sentryDsn: 'SENTRY_DSN', + sentryDsn: '[SENTRY_DSN]', perspectiveApiKey: '[PERSPECTIVE_API_KEY]' }, environment: 'development', |