From 9646080b929c0963a64775a75a58032bf6dd7947 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 4 Apr 2022 14:31:14 +0300 Subject: [PATCH] misc fixes n tweaks --- .gitignore | 1 - options.json | 3 ++- src/structure/client/wrappers/GuildWrapper.js | 4 ++-- .../client/wrappers/InteractionWrapper.js | 2 +- .../components/observers/CommandHandler.js | 6 ++++-- src/structure/interfaces/commands/SlashCommand.js | 14 ++++++++++---- src/utilities/Util.js | 4 ++++ 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index f31b01c..79f8989 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ commandHash.json # Logs, duh logs -emojis.json # API src/middleware/api diff --git a/options.json b/options.json index e201f43..0ff145d 100644 --- a/options.json +++ b/options.json @@ -12,7 +12,8 @@ "GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILD_WEBHOOKS", - "GUILD_BANS" + "GUILD_BANS", + "GUILD_PRESENCES" ] }, "invite": "https://discord.gg/49u6cHu", diff --git a/src/structure/client/wrappers/GuildWrapper.js b/src/structure/client/wrappers/GuildWrapper.js index 212beea..15503b8 100644 --- a/src/structure/client/wrappers/GuildWrapper.js +++ b/src/structure/client/wrappers/GuildWrapper.js @@ -128,14 +128,14 @@ class GuildWrapper { } get locale() { - return this._settings?.locale || 'en_us'; + return this._settings?.locale || 'en_gb'; } format(index, parameters = {}, opts = {}) { const { code = false, - language = this.locale || 'en_us' + language = this.locale || 'en_gb' } = opts; return this.client.localeLoader.format(language, index, parameters, code); diff --git a/src/structure/client/wrappers/InteractionWrapper.js b/src/structure/client/wrappers/InteractionWrapper.js index 0986ec5..f430705 100644 --- a/src/structure/client/wrappers/InteractionWrapper.js +++ b/src/structure/client/wrappers/InteractionWrapper.js @@ -133,7 +133,7 @@ class InteractionWrapper { format(index, parameters = {}, opts = {}) { const { code = false, - language = this.user.locale || this.guild?.locale || 'en_us' + language = this.user.locale || this.guild?.locale || 'en_gb' } = opts; return this.client.localeLoader.format(language, index, parameters, code); } diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 0f22c07..ecc47db 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -246,7 +246,8 @@ class CommandHandler extends Observer { if(!member) return { error: true }; return { error: false, value: member }; }, - USER: (user) => { + USER: async (user) => { + user = await this.client.users.fetch(user); return { error: false, value: user }; }, TEXT_CHANNEL: async (channel) => { @@ -263,7 +264,8 @@ class CommandHandler extends Observer { channel = await guild.resolveChannel(channel); return { error: false, value: channel }; }, - ROLE: (role) => { + ROLE: async (role) => { + role = await guild.roles.fetch(role); return { error: false, value: role }; }, MENTIONABLE: (mentionable) => { diff --git a/src/structure/interfaces/commands/SlashCommand.js b/src/structure/interfaces/commands/SlashCommand.js index ab4c4fe..709ab71 100644 --- a/src/structure/interfaces/commands/SlashCommand.js +++ b/src/structure/interfaces/commands/SlashCommand.js @@ -38,11 +38,17 @@ class SlashCommand extends Command { if (opt instanceof CommandOption) this.options.push(opt); else if (opt.name instanceof Array) { // Allows easy templating of subcommands that share arguments - const { name: names, description, ...opts } = opt; + const { name: names, description, type, ...opts } = opt; for (const name of names) { - let desc = description; - if(description instanceof Array) desc = description[names.indexOf(name)] || 'Missing description'; - this.options.push(new CommandOption({ name, description: desc, ...opts })); + const index = names.indexOf(name); + let desc = description, + _type = type; + if (description instanceof Array) desc = description[index] || 'Missing description'; + if (type instanceof Array) { + _type = type[index]; + if(!_type) throw new Error(`Missing type for option ${name} in command ${this.name}`); + } + this.options.push(new CommandOption({ name, type: _type, description: desc, ...opts })); } } else this.options.push(new CommandOption(opt)); } diff --git a/src/utilities/Util.js b/src/utilities/Util.js index 3aacc4f..c47ac86 100644 --- a/src/utilities/Util.js +++ b/src/utilities/Util.js @@ -267,6 +267,10 @@ class Util { return humaniser(seconds * 1000, { largest: 2 }) + (relative ? ' ago' : ''); } + static timeAgo(seconds) { + return Util.humanise(Date.now() / 1000 - seconds, true); + } + /** * Convert seconds to a human readable string representation * @param {int} seconds