diff --git a/options.json b/options.json index 6f2e3ec..14d4264 100644 --- a/options.json +++ b/options.json @@ -26,15 +26,13 @@ "mongodb": { "database": "galactic", "tables": [ - "infractions", "guilds", - "messages", "attachments", - "users", - "permissions", - "role_cache", - "webhooks" + "permissions" ] + }, + "mariadb": { + "tables": [] } } } \ No newline at end of file diff --git a/src/structure/DiscordClient.js b/src/structure/DiscordClient.js index bb8a131..4d2968d 100644 --- a/src/structure/DiscordClient.js +++ b/src/structure/DiscordClient.js @@ -54,7 +54,13 @@ class DiscordClient extends Client { await this.localeLoader.loadLanguages(); + await this.storageManager.initialize(); + await this.registry.loadComponents('components/observers', Observer); + await this.registry.loadComponents('components/settings', Setting); + + //Build settings constructors for Settings command + await this.registry.loadComponents('components/commands', Command); await this.dispatcher.dispatch(); diff --git a/src/structure/client/wrappers/GuildWrapper.js b/src/structure/client/wrappers/GuildWrapper.js index 44624c3..e4c5f69 100644 --- a/src/structure/client/wrappers/GuildWrapper.js +++ b/src/structure/client/wrappers/GuildWrapper.js @@ -22,4 +22,64 @@ class GuildWrapper { return JSON.parse(JSON.stringify(this.client.defaultConfig())); } -} \ No newline at end of file + /* Wrapper Functions */ + + fetch() { + return this.guild.fetch(); + } + + iconURL(...args) { + return this.guild.iconURL(...args); + } + + get available() { + return this.guild.available; + } + + get bans() { + return this.guild.bans; + } + + get channels() { + return this.guild.channels; + } + + get features() { + return this.guild.features; + } + + get id() { + return this.guild.id; + } + + get maximumMembers() { + return this.guild.maximumMembers; + } + + get maximumPresences() { + return this.guild.maximumPresences; + } + + get me() { + return this.guild.me; + } + + get memberCount() { + return this.guild.memberCount; + } + + get members() { + return this.guild.members; + } + + get name() { + return this.guild.name; + } + + get roles() { + return this.guild.roles; + } + +} + +module.exports = GuildWrapper; \ No newline at end of file diff --git a/src/structure/components/commands/administration/SettingsCommand.js b/src/structure/components/commands/administration/SettingsCommand.js index 5936bf3..efd6fb4 100644 --- a/src/structure/components/commands/administration/SettingsCommand.js +++ b/src/structure/components/commands/administration/SettingsCommand.js @@ -11,22 +11,12 @@ class SettingsCommand extends SlashCommand { new CommandOption({ name: 'category', description: "Select a category to view settings for.", - type: 'STRING', - choices: [ - { - name: 'Administration', - value: 'administrator' - }, - { - name: 'Moderation', - value: 'moderation' - }, - { - name: 'Utility', - value: 'utility' - } - ], - required: true + type: 'SUB_COMMAND_GROUP', + options: [ + new CommandOption({ + type: 'SUB_COMMAND' + }) + ] }) ], guildOnly: true diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 4fd5282..469168c 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -1,3 +1,4 @@ +const GuildWrapper = require('../../client/wrappers/GuildWrapper'); const { Observer, Thing, CommandOption } = require('../../interfaces/'); class CommandHandler extends Observer { @@ -43,7 +44,10 @@ class CommandHandler extends Observer { || interaction.guild && !interaction.guild.available) return undefined; const command = this._matchCommand(interaction.commandName); - const thing = new Thing(this.client, command, interaction); + + let guildWrapper = null; + if(interaction.guild) guildWrapper = new GuildWrapper(this.client, interaction.guild); + const thing = new Thing(this.client, command, interaction, guildWrapper); if(!command) return thing.reply({ content: thing.format('O_COMMANDHANDLER_COMMANDNOTSYNCED'), emoji: 'failure', ephemeral: true }); diff --git a/src/structure/interfaces/Thing.js b/src/structure/interfaces/Thing.js index 4758e5d..56803b3 100644 --- a/src/structure/interfaces/Thing.js +++ b/src/structure/interfaces/Thing.js @@ -2,11 +2,12 @@ const { Emojis } = require('../../constants/'); class Thing { - constructor(client, command, interaction) { + constructor(client, command, interaction, guild) { this.client = client; this.interaction = interaction; this.command = command; + this.guild = guild; this.options = []; @@ -32,20 +33,16 @@ class Thing { return this.client.localeLoader.format(language, locale, parameters, code); } - get guild() { - return this.interaction.guild || null; - } - get channel() { - return this.interaction.channel || null; + return this.interaction.channel; } get user() { - return this.interaction.user || null; + return this.interaction.user; } get member() { - return this.interaction.member || null; + return this.interaction.member; } } diff --git a/src/structure/storage/StorageManager.js b/src/structure/storage/StorageManager.js index 56206f8..d9a71e2 100644 --- a/src/structure/storage/StorageManager.js +++ b/src/structure/storage/StorageManager.js @@ -19,7 +19,7 @@ class StorageManager { // this.manager.logger.write('debug', "Initializing storage providers."); - const _providers = path.join(process.cwd(), "structure/storage/providers"); + const _providers = path.join(process.cwd(), "src/structure/storage/providers"); const providers = fs.readdirSync(_providers); for (const _provider of providers) { @@ -45,10 +45,12 @@ class StorageManager { } _error(info, instance = null) { + //TODO: Change logging string to remove [STORA] this.client.logger.error(`${chalk.bold(`[STORA]`)} ${instance ? `(${this._getName(instance)}) ` : ''}${info}`); } _log(info, instance = null) { + //TODO: Change logging string to remove [STORA] this.client.logger.info(`${chalk.bold(`[STORA]`)} ${instance ? `(${this._getName(instance)}) ` : ''}${info}`); } diff --git a/src/structure/storage/interfaces/Provider.js b/src/structure/storage/interfaces/Provider.js index 0d734f3..4092c17 100644 --- a/src/structure/storage/interfaces/Provider.js +++ b/src/structure/storage/interfaces/Provider.js @@ -19,7 +19,7 @@ class Provider { if (!opts.config) throw new Error('No config file provided!'); this.config = opts.config[opts.name]; - if (this.config && (!this.config.database || !this.config.host)) throw new Error('Invalid config file provided!' + JSON.stringify(this.config)); + // if (this.config && (!this.config.database || !this.config.host)) throw new Error('Invalid config file provided!' + JSON.stringify(this.config)); this.client = client; this.storageManager = client.storageManager; @@ -37,7 +37,7 @@ class Provider { async loadTables() { - const directory = path.join(process.cwd(), 'structure/storage/'); + const directory = path.join(process.cwd(), 'src/structure/storage/'); const files = await Util.readdirRecursive(path.join(directory, `tables/${this.name}`)); const loaded = []; diff --git a/src/structure/storage/providers/Mariadb.js b/src/structure/storage/providers/Mariadb.js index e2defb1..b5ab342 100644 --- a/src/structure/storage/providers/Mariadb.js +++ b/src/structure/storage/providers/Mariadb.js @@ -1,5 +1,5 @@ const { Provider } = require('../interfaces/'); -const MySQL = require('mysql'); +// const MySQL = require('mysql'); class MariaDBProvider extends Provider {