diff --git a/storage/Provider.js b/storage/Provider.js index 5b726bd..918e9bf 100644 --- a/storage/Provider.js +++ b/storage/Provider.js @@ -1,14 +1,15 @@ class Provider { - constructor(manager, config) { + constructor(manager, config, name) { if(!config) throw new Error('No config file provided!'); - if(config && (!config.database || !config.url)) throw new Error('Invalid config file provided!'); + this.config = config[name]; + if(config && (!this.config.database || !this.config.host)) throw new Error('Invalid config file provided!' + JSON.stringify(this.config)); this.manager = manager; - this.config = config; this.db; this.loaded = false; + this.name = name; } diff --git a/storage/StorageManager.js b/storage/StorageManager.js index 988fc1b..00c65e3 100644 --- a/storage/StorageManager.js +++ b/storage/StorageManager.js @@ -1,15 +1,34 @@ const { Collection } = require('../util/'); +const path = require('path'); +const fs = require('fs'); class StorageManager { - constructor(manager) { + constructor(manager, options = {}) { this.providers = new Collection(); + this.manager = manager; + this.options = options; } async initialize() { + console.log('Initiating storage providers'); + let _providers = path.join(process.cwd(), 'storage', 'providers'); + let providers = fs.readdirSync(_providers); + + for(let _provider of providers) { + + let provider = require(path.join(_providers, _provider)); + provider = new provider(this.manager, this.options); + + await provider.init(); + + this.providers.set(provider.name, provider); + + } + } } diff --git a/storage/providers/Mariadb.js b/storage/providers/Mariadb.js index 7871f5f..51cda4f 100644 --- a/storage/providers/Mariadb.js +++ b/storage/providers/Mariadb.js @@ -1,11 +1,11 @@ -const Provider = require('./Provider.js'); +const Provider = require('../Provider.js'); const MySQL = require('mysql'); class MariaDBProvider extends Provider { constructor(manager, config) { - super(manager, config); + super(manager, config, 'mariadb'); } @@ -49,7 +49,7 @@ class MariaDBProvider extends Provider { * Query using SQL to MariaDB * * @param {string} query SQL query string. - * @param {array} values Array of values to replace ? with in the query string + * @param {array} values Array of values to replace ? with in the query string * @returns {object} Returns an object containing the query result * @memberof MariaDBProvider */ diff --git a/storage/providers/Mongodb.js b/storage/providers/Mongodb.js index 34bf0a2..0ed9456 100644 --- a/storage/providers/Mongodb.js +++ b/storage/providers/Mongodb.js @@ -1,11 +1,11 @@ -const Provider = require('./Provider.js'); +const Provider = require('../Provider.js'); const { MongoClient } = require('mongodb'); class MongoDBProvider extends Provider { constructor(manager, config) { - super(manager, config); + super(manager, config, 'mongodb'); this.client; @@ -13,7 +13,7 @@ class MongoDBProvider extends Provider { async init() { - this.manager.logger.log('Initializing mongodb.'); + //this.manager.logger.log('Initializing mongodb.'); try { diff --git a/structure/client/DiscordClient.js b/structure/client/DiscordClient.js index 912cd3a..3d51002 100644 --- a/structure/client/DiscordClient.js +++ b/structure/client/DiscordClient.js @@ -32,6 +32,8 @@ class DiscordClient extends Client { if(this._built) return undefined; + console.log('Building Discord client'); + await super.login(this._options.bot.token); await this.registry.loadComponents('components/commands/', Command); @@ -41,6 +43,8 @@ class DiscordClient extends Client { this._built = true; + console.log('Client built'); + } diff --git a/structure/interfaces/Observer.js b/structure/interfaces/Observer.js index aa08ea5..bb1ef01 100644 --- a/structure/interfaces/Observer.js +++ b/structure/interfaces/Observer.js @@ -11,8 +11,6 @@ class Observer extends Component { disabled: opts.disabled }); - this.client = client; - this.name = opts.name; this.priority = opts.priority || 1; this.hooks = opts.hooks || [];