prepwork for staging

This commit is contained in:
Erik 2022-04-25 17:34:54 +03:00
parent d2cf41b28f
commit f9bf974564
Signed by: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 32 additions and 10 deletions

View File

@ -21,7 +21,7 @@ class ImportCommand extends SlashCommand {
type: 'SUB_COMMAND', type: 'SUB_COMMAND',
options: [{ options: [{
name: 'version', name: 'version',
description: 'Which version do you want to import', description: 'Which version do you want to import from',
choices: [ choices: [
{ name: 'v2', value: '2' }, { name: 'v2', value: '2' },
{ name: 'v3', value: '3' } { name: 'v3', value: '3' }
@ -36,9 +36,10 @@ class ImportCommand extends SlashCommand {
const { subcommand, guild } = invoker; const { subcommand, guild } = invoker;
const settings = await guild.settings(); const settings = await guild.settings();
if (settings._imported); if (settings._imported);
console.log(subcommand);
version = version?.value || '3'; version = version?.value || '3';
if(subcommand.name === 'modlogs') return { content: 'Not supported yet' };
// TODO split into settings and modlogs // TODO split into settings and modlogs
const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env; 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' }; return { index: 'COMMAND_IMPORT_ERROR', params: { message: err.message }, emoji: 'failure' };
} }
const { webhook } = imported; const { webhook, permissions } = imported;
if (webhook) { if (webhook) {
if (typeof webhook === 'string') { if (typeof webhook === 'string') {
const hooks = await guild.fetchWebhooks(); const hooks = await guild.fetchWebhooks();
const hook = hooks.get(webhook); const hook = hooks.get(webhook);
if(hook) await guild.updateWebhook('messages', hook); if(hook) await guild.updateWebhook('messages', hook);
} else if (version === '3') { } else if (version === '3') {
delete webhook._id;
delete webhook.feature; delete webhook.feature;
await this.client.storageManager.mongodb.webhooks.updateOne({ feature: 'messages', guild: guild.id }, webhook); 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); await guild.updateSettings(imported.settings);
return { index: 'COMMAND_IMPORT_SUCCESS', emoji: 'success' }; return { index: 'COMMAND_IMPORT_SUCCESS', emoji: 'success' };
} }

View File

@ -1,7 +1,7 @@
const { MessageEmbed, Message } = require('discord.js'); const { MessageEmbed, Message } = require('discord.js');
const { Util } = require('../../../utilities'); const { Util } = require('../../../utilities');
const { InvokerWrapper, MessageWrapper } = require('../../client/wrappers'); const { InvokerWrapper, MessageWrapper } = require('../../client/wrappers');
const { Observer, CommandOption, CommandError } = require('../../interfaces/'); const { Observer, CommandError } = require('../../interfaces/');
class CommandHandler extends Observer { class CommandHandler extends Observer {

View File

@ -48,17 +48,36 @@ class SettingsMigrator {
const { _version } = settings; const { _version } = settings;
if (!_version) return Promise.reject(new Error('Unable to determine configuration version')); if (!_version) return Promise.reject(new Error('Unable to determine configuration version'));
let webhook = null; let webhook = null,
if (version === '3') permissions = null;
if (version === '3') {
webhook = await this.mongo.findOne('webhooks', { guild: this.guild, feature: 'messageLog' }); 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); ({ webhook } = settings.chatlogs);
permissions = this.permissions(settings.roles);
permissions.guildId = this.guild;
}
this.logger.info(`Settings migration for ${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) { '3'(result) {
// console.log(result); // console.log(result);
// most of these should be mostly 1:1 apart from the names that changed // most of these should be mostly 1:1 apart from the names that changed
@ -95,7 +114,6 @@ class SettingsMigrator {
} }
'2'(result) { '2'(result) {
console.log(result);
const settings = {}; const settings = {};
return settings; return settings;
} }