diff --git a/src/lib/Client.js b/src/lib/Client.js index 694b80f126..5e5aba7454 100644 --- a/src/lib/Client.js +++ b/src/lib/Client.js @@ -25,7 +25,6 @@ const TaskStore = require('./structures/TaskStore'); const GatewayDriver = require('./settings/gateway/GatewayDriver'); // lib/settings/schema -const Gateway = require('./settings/gateway/Gateway'); const Schema = require('./settings/schema/Schema'); // lib/util @@ -248,30 +247,6 @@ class KlasaClient extends Discord.Client { */ this.gateways = new GatewayDriver(this); - const { guilds, users, clientStorage } = this.options.gateways; - const guildSchema = 'schema' in guilds ? guilds.schema : this.constructor.defaultGuildSchema; - const userSchema = 'schema' in users ? users.schema : this.constructor.defaultUserSchema; - const clientSchema = 'schema' in clientStorage ? clientStorage.schema : this.constructor.defaultClientSchema; - - // Update Guild Schema with Keys needed in Klasa - const prefixKey = guildSchema.get('prefix'); - if (!prefixKey || prefixKey.default === null) { - guildSchema.add('prefix', 'string', { array: Array.isArray(this.options.prefix), default: this.options.prefix }); - } - - const languageKey = guildSchema.get('language'); - if (!languageKey || languageKey.default === null) { - guildSchema.add('language', 'language', { default: this.options.language }); - } - - guildSchema.add('disableNaturalPrefix', 'boolean', { configurable: Boolean(this.options.regexPrefix) }); - - // Register default gateways - this.gateways - .register(new Gateway(this, 'guilds', { schema: guildSchema, ...this.options.gateways.guilds || {} })) - .register(new Gateway(this, 'users', { schema: userSchema, ...this.options.gateways.users || {} })) - .register(new Gateway(this, 'clientStorage', { schema: clientSchema, ...this.options.gateways.clientStorage || {} })); - /** * The Settings instance that handles this client's settings * @since 0.5.0 diff --git a/src/lib/settings/gateway/GatewayDriver.js b/src/lib/settings/gateway/GatewayDriver.js index 4e62451c72..6eb49b4677 100644 --- a/src/lib/settings/gateway/GatewayDriver.js +++ b/src/lib/settings/gateway/GatewayDriver.js @@ -1,4 +1,5 @@ const GatewayStorage = require('./GatewayStorage'); +const Gateway = require('./Gateway'); const Type = require('../../util/Type'); const { Collection } = require('discord.js'); @@ -8,30 +9,6 @@ const { Collection } = require('discord.js'); */ class GatewayDriver extends Collection { - /** - * @typedef {Object} GatewayDriverRegisterOptions - * @property {string} [provider = this.client.options.providers.default] The name of the provider to use - * @property {Schema} [schema] The schema to use for this gateway. - * @property {string|string[]|true} [syncArg] The sync args to pass to Gateway#sync during Gateway init - */ - - /** - * @typedef {Object} GatewayDriverGuildsSchema - * @property {SchemaPieceOptions} prefix The per-guild's configurable prefix key - * @property {SchemaPieceOptions} language The per-guild's configurable language key - * @property {SchemaPieceOptions} disableNaturalPrefix The per-guild's configurable disableNaturalPrefix key - * @property {SchemaPieceOptions} disabledCommands The per-guild's configurable disabledCommands key - * @private - */ - - /** - * @typedef {Object} GatewayDriverClientStorageSchema - * @property {SchemaPieceOptions} userBlacklist The client's configurable user blacklist key - * @property {SchemaPieceOptions} guildBlacklist The client's configurable guild blacklist key - * @property {SchemaPieceOptions} schedules The schedules where {@link ScheduledTask}s are stored at - * @private - */ - /** * @since 0.3.0 * @param {KlasaClient} client The Klasa client @@ -47,6 +24,30 @@ class GatewayDriver extends Collection { * @readonly */ Object.defineProperty(this, 'client', { value: client }); + + // Setup default gateways and adjust client options as necessary + const { guilds, users, clientStorage } = client.options.gateways; + guilds.schema = 'schema' in guilds ? guilds.schema : client.constructor.defaultGuildSchema; + users.schema = 'schema' in users ? users.schema : client.constructor.defaultUserSchema; + clientStorage.schema = 'schema' in clientStorage ? clientStorage.schema : client.constructor.defaultClientSchema; + + const prefix = guilds.schema.get('prefix'); + const language = guilds.schema.get('language'); + + if (!prefix || prefix.default === null) { + guilds.schema.add('prefix', 'string', { array: Array.isArray(client.options.prefix), default: client.options.prefix }); + } + + if (!language || language.default === null) { + guilds.schema.add('language', 'language', { default: client.options.language }); + } + + guilds.schema.add('disableNaturalPrefix', 'boolean', { configurable: Boolean(client.options.regexPrefix) }); + + this + .register(new Gateway(client, 'guilds', guilds)) + .register(new Gateway(client, 'users', users)) + .register(new Gateway(client, 'clientStorage', clientStorage)); }