From eaf79728790f0e49a9eab2e35f1239e6adc7739f Mon Sep 17 00:00:00 2001 From: Navy Date: Tue, 8 Jun 2021 23:28:52 +0300 Subject: [PATCH] various fixes --- .eslintrc.json | 8 +++- Manager.js | 44 +++++++++++++++++++ .../inhibitors/ClientPermissions.js | 3 +- .../components/observers/Automoderation.js | 2 +- .../languages/en_us/en_us_commands.lang | 3 +- .../languages/en_us/en_us_settings.lang | 18 ++++++-- 6 files changed, 71 insertions(+), 7 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 175bb3d..a0e8308 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -59,7 +59,13 @@ "id-blacklist": "warn", "id-match": "warn", "implicit-arrow-linebreak": "warn", - "indent": "warn", + "indent": [ + "warn", + 4, + { + "SwitchCase": 1 + } + ], "init-declarations": "warn", "jsx-quotes": "warn", "key-spacing": "warn", diff --git a/Manager.js b/Manager.js index 5e3fc9e..ff0723b 100644 --- a/Manager.js +++ b/Manager.js @@ -1,6 +1,7 @@ const { EventEmitter } = require('events'); // eslint-disable-next-line no-unused-vars const { inspect } = require('util'); +const os = require('os'); const ShardManager = require('./middleware/ShardManager.js'); const Logger = require('./middleware/logger/Logger.js'); @@ -27,8 +28,11 @@ class Manager extends EventEmitter { _handleMessage(shard, message) { if (message._mEval) return this.eval(shard, message); + // Messages coming from the API that have the _logger flag will be caught here, i.e. both flags should be on if (message._logger) return this.logger._handleMessage(shard, message); if (message._webhook) return undefined; //todo + if (message._api) return this.apiRequest(shard, message); + } async build() { @@ -82,6 +86,46 @@ class Manager extends EventEmitter { } + async apiRequest(shard, message) { + + const { type } = message; + switch (type) { + case 'statsQuery': + // TODO: Figure out best strategy for stats querying - push/pull, prometheus, simple polling + //return this.aggregateStatistics(); + } + + } + + async aggregateStatistics() { + + const managerData = { + memory: process.memoryUsage().heapUsed, // Bytes + uptime: Date.now() - this.readyAt, + library: { + name: 'Discord.js', + versionersion: require('discord.js').version + }, + managedShards: this.shardManager.shards.size + }; + + const CPU = os.cpus(); + const freeMemory = os.freemem(); + const totalMemory = os.totalmem(); + const systemData = { + cpu: CPU[0].model, + cores: CPU.length, + memory: { + used: totalMemory - freeMemory, + total: totalMemory + }, + osType: os.type(), + uptime: os.uptime(), + hostname: os.hostname() + }; + + } + get uptime() { return this.readyAt !== null ? Date.now() - this.readyAt : 0; } diff --git a/structure/client/components/inhibitors/ClientPermissions.js b/structure/client/components/inhibitors/ClientPermissions.js index 1a63488..4a6865b 100644 --- a/structure/client/components/inhibitors/ClientPermissions.js +++ b/structure/client/components/inhibitors/ClientPermissions.js @@ -13,7 +13,8 @@ class ClientPermissions extends Inhibitor { } - execute(message, command) { + async execute(message, command) { + if (!message.guild.me) message.guild.me = await message.guild.members.fetch(message.client.user); const missing = message.channel.permissionsFor(message.guild.me).missing(command.clientPermissions); if(missing.length > 0) { return super._fail({ missing: missing.join(', ') }); diff --git a/structure/client/components/observers/Automoderation.js b/structure/client/components/observers/Automoderation.js index eff8abc..2cfba89 100644 --- a/structure/client/components/observers/Automoderation.js +++ b/structure/client/components/observers/Automoderation.js @@ -93,7 +93,7 @@ module.exports = class AutoModeration extends Observer { const { bypass, ignore, enabled, silent, explicit, fuzzy, regex, whitelist, actions } = setting; const roles = member?.roles.cache.map((r) => r.id) || []; - if (!enabled || roles.some((r) => bypass.includes(r.id)) || ignore.includes(channel.id)) return; + if (!enabled || roles.some((r) => bypass.includes(r)) || ignore.includes(channel.id)) return; // Which message obj to work with const msg = edited || message; diff --git a/structure/language/languages/en_us/en_us_commands.lang b/structure/language/languages/en_us/en_us_commands.lang index 5db9c26..ac517a0 100644 --- a/structure/language/languages/en_us/en_us_commands.lang +++ b/structure/language/languages/en_us/en_us_commands.lang @@ -665,7 +665,8 @@ For instance the mute setting has a `createmute` (`{prefix}settings createmute < `{prefix}help [ command / setting ]` **❯ Links** -[Documentation](https://docs.corgi.wtf/) +[Documentation](https://galactic.corgi.wtf/documentation) +[Dashboard](https://galactic.corgi.wtf/dashboard) **[NON-FUNCTIONAL PRE-ALPHA]** [Support & Info server](https://discord.gg/SvJgtEj) [@BotGalactic Twitter](https://twitter.com/BotGalactic) [GalacticBot Patreon](https://www.patreon.com/galacticbot) diff --git a/structure/language/languages/en_us/en_us_settings.lang b/structure/language/languages/en_us/en_us_settings.lang index 4a22d65..8b96080 100644 --- a/structure/language/languages/en_us/en_us_settings.lang +++ b/structure/language/languages/en_us/en_us_settings.lang @@ -288,6 +288,18 @@ Successfully set the explicit word filter to `{changed}`. [S_WORDFILTER_EXPLICIT_RESET] Successfully reset the explicit word filter. +[S_WORDFILTER_WHITELIST_ADD] +Successfully added `{changed}` to the whitelist. + +[S_WORDFILTER_WHITELIST_REMOVE] +Successfully removed `{changed}` from the whitelist. + +[S_WORDFILTER_WHITELIST_SET] +Successfully set the whitelist to `{changed}`. + +[S_WORDFILTER_WHITELIST_RESET] +Successfully reset the whitelist. + [S_WORDFILTER_FUZZY_ADD] Successfully added `{changed}` to the fuzzy word filter. @@ -316,13 +328,13 @@ Successfully reset the regex word filter. Successfully toggled the word filter **{toggle}**. [S_WORDFILTER_IGNORE_ADD] -Successfully added {changed} to be ignored by the word filter. +Successfully added **{changed}** to be ignored by the word filter. [S_WORDFILTER_IGNORE_REMOVE] -Successfully removed {changed} from being ignored by the word filter. +Successfully removed **{changed}** from being ignored by the word filter. [S_WORDFILTER_IGNORE_SET] -Successfully set {changed} to be ignored by the word filter. +Successfully set **{changed}** to be ignored by the word filter. [S_WORDFILTER_IGNORE_RESET] Successfully reset the ignored channels for the word filter.