uhh guildwrapper stuff

This commit is contained in:
nolan 2021-08-25 21:05:39 -07:00
parent 79a9ba618b
commit c863630b40
9 changed files with 93 additions and 36 deletions

View File

@ -26,15 +26,13 @@
"mongodb": {
"database": "galactic",
"tables": [
"infractions",
"guilds",
"messages",
"attachments",
"users",
"permissions",
"role_cache",
"webhooks"
"permissions"
]
},
"mariadb": {
"tables": []
}
}
}

View File

@ -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();

View File

@ -22,4 +22,64 @@ class GuildWrapper {
return JSON.parse(JSON.stringify(this.client.defaultConfig()));
}
}
/* 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;

View File

@ -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

View File

@ -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 });

View File

@ -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;
}
}

View File

@ -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}`);
}

View File

@ -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 = [];

View File

@ -1,5 +1,5 @@
const { Provider } = require('../interfaces/');
const MySQL = require('mysql');
// const MySQL = require('mysql');
class MariaDBProvider extends Provider {