This commit is contained in:
noolaan 2020-04-11 22:13:45 -06:00
commit f3856a1ecb
6 changed files with 34 additions and 12 deletions

View File

@ -1,14 +1,15 @@
class Provider { class Provider {
constructor(manager, config) { constructor(manager, config, name) {
if(!config) throw new Error('No config file provided!'); 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.manager = manager;
this.config = config;
this.db; this.db;
this.loaded = false; this.loaded = false;
this.name = name;
} }

View File

@ -1,15 +1,34 @@
const { Collection } = require('../util/'); const { Collection } = require('../util/');
const path = require('path');
const fs = require('fs');
class StorageManager { class StorageManager {
constructor(manager) { constructor(manager, options = {}) {
this.providers = new Collection(); this.providers = new Collection();
this.manager = manager;
this.options = options;
} }
async initialize() { 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);
}
} }
} }

View File

@ -1,11 +1,11 @@
const Provider = require('./Provider.js'); const Provider = require('../Provider.js');
const MySQL = require('mysql'); const MySQL = require('mysql');
class MariaDBProvider extends Provider { class MariaDBProvider extends Provider {
constructor(manager, config) { constructor(manager, config) {
super(manager, config); super(manager, config, 'mariadb');
} }
@ -49,7 +49,7 @@ class MariaDBProvider extends Provider {
* Query using SQL to MariaDB * Query using SQL to MariaDB
* *
* @param {string} query SQL query string. * @param {string} query SQL query string.
* @param {array} values Array of values to replace ? with in the query string * @param {array<Object>} values Array of values to replace ? with in the query string
* @returns {object} Returns an object containing the query result * @returns {object} Returns an object containing the query result
* @memberof MariaDBProvider * @memberof MariaDBProvider
*/ */

View File

@ -1,11 +1,11 @@
const Provider = require('./Provider.js'); const Provider = require('../Provider.js');
const { MongoClient } = require('mongodb'); const { MongoClient } = require('mongodb');
class MongoDBProvider extends Provider { class MongoDBProvider extends Provider {
constructor(manager, config) { constructor(manager, config) {
super(manager, config); super(manager, config, 'mongodb');
this.client; this.client;
@ -13,7 +13,7 @@ class MongoDBProvider extends Provider {
async init() { async init() {
this.manager.logger.log('Initializing mongodb.'); //this.manager.logger.log('Initializing mongodb.');
try { try {

View File

@ -32,6 +32,8 @@ class DiscordClient extends Client {
if(this._built) return undefined; if(this._built) return undefined;
console.log('Building Discord client');
await super.login(this._options.bot.token); await super.login(this._options.bot.token);
await this.registry.loadComponents('components/commands/', Command); await this.registry.loadComponents('components/commands/', Command);
@ -41,6 +43,8 @@ class DiscordClient extends Client {
this._built = true; this._built = true;
console.log('Client built');
} }

View File

@ -11,8 +11,6 @@ class Observer extends Component {
disabled: opts.disabled disabled: opts.disabled
}); });
this.client = client;
this.name = opts.name; this.name = opts.name;
this.priority = opts.priority || 1; this.priority = opts.priority || 1;
this.hooks = opts.hooks || []; this.hooks = opts.hooks || [];