From 800668f3e0fec80f3ba08f115d9563324bc54045 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Mon, 29 Aug 2022 19:53:53 -0400 Subject: deploy stuff --- config/Config.ts | 13 ++++++++++--- config/example-options.ts | 1 + ecosystem.config.cjs | 10 +++++----- lib/extensions/discord-akairo/TanzaniteClient.ts | 7 +++++-- lib/utils/BotClientUtils.ts | 5 ++++- lib/utils/UpdateCache.ts | 2 +- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/config/Config.ts b/config/Config.ts index 4aae10a..90d4428 100644 --- a/config/Config.ts +++ b/config/Config.ts @@ -51,7 +51,7 @@ export class Config implements ConfigOptions { this.credentials = options.credentials; this.environment = options.environment; this.owners = options.owners; - this.prefix = options.prefix; + this.prefix = typeof options.prefix === 'string' ? options.prefix : options.prefix[this.environment]; this.channels = options.channels; this.db = options.db; this.logging = options.logging; @@ -118,7 +118,7 @@ export interface ConfigOptions { /** * A string that needs to come before text commands. */ - prefix: string; + prefix: EnvironmentMap; /** * Various discord channels that logs will be sent in. @@ -210,7 +210,7 @@ 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 | ''; + [Key in ConfigChannelKey]: EnvironmentMap; }; /** @@ -222,6 +222,11 @@ export type ConfigChannelKey = 'log' | 'error' | 'dm' | 'servers'; * Options for the Postgres database connection. */ export interface DataBase { + /** + * Ex. "tanzanite" would use the databases "tanzanite", "tanzanite-beta", "tanzanite-dev", and "tanzanite-shared". + */ + databasePrefix: string; + /** * The host of the database. */ @@ -272,3 +277,5 @@ export interface SupportGuild { */ invite: string | null; } + +export type EnvironmentMap = T | { [Key in Environment]: T }; diff --git a/config/example-options.ts b/config/example-options.ts index 43b805e..903928d 100644 --- a/config/example-options.ts +++ b/config/example-options.ts @@ -26,6 +26,7 @@ export default new Config({ servers: '1000000000000000' }, db: { + databasePrefix: 'tanzanite', host: 'localhost', port: 5432, username: '[USER_NAME]', diff --git a/ecosystem.config.cjs b/ecosystem.config.cjs index 32971cf..ce407cb 100644 --- a/ecosystem.config.cjs +++ b/ecosystem.config.cjs @@ -4,8 +4,8 @@ module.exports = { name: `tanzanite${e}`, script: 'yarn', args: 'start:raw', - out_file: `../bushbot${e}.log`, - error_file: `../bushbot${e}.log`, + out_file: `../tanzanite${e}.log`, + error_file: `../tanzanite${e}.log`, max_memory_restart: '1G', node_args: ['--max_old_space_size=2048'], env: { FORCE_COLOR: '3' }, @@ -19,11 +19,11 @@ module.exports = { ['production', 'beta'].map((e) => [ e, { - 'user': 'pi', - 'host': '192.168.1.210', + 'user': 'ironmoon', + 'host': '192.168.1.11', 'ref': `origin/${e === 'production' ? 'master' : 'beta'}`, 'repo': 'https://github.com/TanzaniteBot/tanzanite.git', - 'path': `/code/bush-bot${e === 'beta' ? '-beta' : ''}`, + 'path': `/code/tanzanite${e === 'beta' ? '-beta' : ''}`, 'post-deploy': `yarn install && yarn build && pm2 start ecosystem.config.cjs --only tanzanite${ e === 'beta' ? '-beta' : '' }` diff --git a/lib/extensions/discord-akairo/TanzaniteClient.ts b/lib/extensions/discord-akairo/TanzaniteClient.ts index 24ce962..fe34b58 100644 --- a/lib/extensions/discord-akairo/TanzaniteClient.ts +++ b/lib/extensions/discord-akairo/TanzaniteClient.ts @@ -347,13 +347,16 @@ export class TanzaniteClient extends AkairoClie logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false, timezone: 'America/New_York' }; + + const prefix = this.config.db.databasePrefix; + this.instanceDB = new Sequelize({ ...sharedDBOptions, - database: this.config.isDevelopment ? 'bushbot-dev' : this.config.isBeta ? 'bushbot-beta' : 'bushbot' + database: this.config.isDevelopment ? `${prefix}-dev` : this.config.isBeta ? `${prefix}-beta` : prefix }); this.sharedDB = new Sequelize({ ...sharedDBOptions, - database: 'bushbot-shared' + database: `${prefix}-shared` }); this.sentry = Sentry; diff --git a/lib/utils/BotClientUtils.ts b/lib/utils/BotClientUtils.ts index a251bdf..1dd46bf 100644 --- a/lib/utils/BotClientUtils.ts +++ b/lib/utils/BotClientUtils.ts @@ -469,7 +469,10 @@ export class BotClientUtils { if (!(channel in channels)) throw new TypeError(`Invalid channel provided (${channel}), must be one of ${Object.keys(channels).join(' ')}`); - const channelId = channels[channel]; + const channelConfig = channels[channel]; + const environment = this.client.config.environment; + + const channelId = typeof channelConfig === 'string' ? channelConfig : channelConfig[environment]; if (channelId === '') return null; const res = await this.client.channels.fetch(channelId); diff --git a/lib/utils/UpdateCache.ts b/lib/utils/UpdateCache.ts index 2f96d9d..0e39344 100644 --- a/lib/utils/UpdateCache.ts +++ b/lib/utils/UpdateCache.ts @@ -14,7 +14,7 @@ export async function updateGlobalCache(client: Client) { } export async function updateSharedCache(client: Client) { - const row: { [x: string]: any } = ((await Shared.findByPk(0)) ?? (await Shared.create())).toJSON(); + const row: { [x: string]: any } = ((await Shared.findByPk(0)) ?? (await Shared.create({ primaryKey: 0 }))).toJSON(); for (const option in row) { if (Object.keys(client.cache.shared).includes(option)) { -- cgit