prepwork for staging
This commit is contained in:
parent
d2cf41b28f
commit
f9bf974564
@ -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' };
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user