From f9bf9745645b5019dfa55a2ade9daac5b67f9930 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 25 Apr 2022 17:34:54 +0300 Subject: [PATCH] prepwork for staging --- .../commands/administration/Import.js | 12 +++++--- .../components/observers/CommandHandler.js | 2 +- src/utilities/SettingsMigrator.js | 28 +++++++++++++++---- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/structure/components/commands/administration/Import.js b/src/structure/components/commands/administration/Import.js index 4558837..b886688 100644 --- a/src/structure/components/commands/administration/Import.js +++ b/src/structure/components/commands/administration/Import.js @@ -21,7 +21,7 @@ class ImportCommand extends SlashCommand { type: 'SUB_COMMAND', options: [{ name: 'version', - description: 'Which version do you want to import', + description: 'Which version do you want to import from', choices: [ { name: 'v2', value: '2' }, { name: 'v3', value: '3' } @@ -36,9 +36,10 @@ class ImportCommand extends SlashCommand { const { subcommand, guild } = invoker; const settings = await guild.settings(); if (settings._imported); - console.log(subcommand); version = version?.value || '3'; + if(subcommand.name === 'modlogs') return { content: 'Not supported yet' }; + // TODO split into settings and modlogs const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env; @@ -58,19 +59,22 @@ class ImportCommand extends SlashCommand { return { index: 'COMMAND_IMPORT_ERROR', params: { message: err.message }, emoji: 'failure' }; } - const { webhook } = imported; + const { webhook, permissions } = imported; if (webhook) { if (typeof webhook === 'string') { const hooks = await guild.fetchWebhooks(); const hook = hooks.get(webhook); if(hook) await guild.updateWebhook('messages', hook); } else if (version === '3') { - delete webhook._id; delete webhook.feature; await this.client.storageManager.mongodb.webhooks.updateOne({ feature: 'messages', guild: guild.id }, webhook); } } + if (permissions) { + await this.client.storageManager.mongodb.permissions.updateOne({ guildId: guild.id }, permissions); + } + await guild.updateSettings(imported.settings); return { index: 'COMMAND_IMPORT_SUCCESS', emoji: 'success' }; } diff --git a/src/structure/components/observers/CommandHandler.js b/src/structure/components/observers/CommandHandler.js index 95d3b68..2a496d2 100644 --- a/src/structure/components/observers/CommandHandler.js +++ b/src/structure/components/observers/CommandHandler.js @@ -1,7 +1,7 @@ const { MessageEmbed, Message } = require('discord.js'); const { Util } = require('../../../utilities'); const { InvokerWrapper, MessageWrapper } = require('../../client/wrappers'); -const { Observer, CommandOption, CommandError } = require('../../interfaces/'); +const { Observer, CommandError } = require('../../interfaces/'); class CommandHandler extends Observer { diff --git a/src/utilities/SettingsMigrator.js b/src/utilities/SettingsMigrator.js index 19e5128..6d8e745 100644 --- a/src/utilities/SettingsMigrator.js +++ b/src/utilities/SettingsMigrator.js @@ -48,17 +48,36 @@ class SettingsMigrator { const { _version } = settings; if (!_version) return Promise.reject(new Error('Unable to determine configuration version')); - let webhook = null; - if (version === '3') + let webhook = null, + permissions = null; + if (version === '3') { webhook = await this.mongo.findOne('webhooks', { guild: this.guild, feature: 'messageLog' }); - else if (version === '2') + permissions = await this.mongo.findOne('permissions', { guildId: this.guild }); + delete webhook._id; + delete permissions._id; + } else if (version === '2') { ({ webhook } = settings.chatlogs); + permissions = this.permissions(settings.roles); + permissions.guildId = this.guild; + } this.logger.info(`Settings migration for ${this.guild}`); - return { settings: this.cleanUp(this[_version](settings)), webhook }; + return { settings: this.cleanUp(this[_version](settings)), webhook, permissions }; } + permissions(roles) { + const keys = Object.keys(roles); + const perms = {}; + for (const roleId of keys) { + perms[roleId] = { + global: roles[roleId].perms + }; + } + + return perms; + } + '3'(result) { // console.log(result); // most of these should be mostly 1:1 apart from the names that changed @@ -95,7 +114,6 @@ class SettingsMigrator { } '2'(result) { - console.log(result); const settings = {}; return settings; }