import thing

This commit is contained in:
Erik 2022-07-23 20:44:03 +03:00
parent 38587d68ac
commit 5f646f3321
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -4,14 +4,17 @@ const { SlashCommand } = require("../../../interfaces");
const dbs = { const dbs = {
'2': process.env.NODE_ENV === 'development' ? 'navybot' : 'galacticbot', '2': process.env.NODE_ENV === 'development' ? 'navybot' : 'galacticbot',
'3': 'newgbot' 'qa': 'galactic'
}; };
const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD, MONGODB_V2_HOST } = process.env; const { MONGODB_QA_HOST, MONGODB_USERNAME, MONGODB_PASSWORD, MONGODB_V2_HOST } = process.env;
class ImportCommand extends SlashCommand { class ImportCommand extends SlashCommand {
constructor(client) { constructor(client) {
const importChoices = [{ name: 'v2', value: '2' }];
if (process.env.NODE_ENV === 'production') importChoices.push({ name: 'qa', value: 'qa' });
super(client, { super(client, {
name: 'import', name: 'import',
description: 'Import old settings & modlogs', description: 'Import old settings & modlogs',
@ -24,10 +27,7 @@ class ImportCommand extends SlashCommand {
options: [{ options: [{
name: 'version', name: 'version',
description: 'Which version do you want to import from', description: 'Which version do you want to import from',
choices: [ choices: importChoices
{ name: 'v2', value: '2' },
{ name: 'v3', value: '3' }
]
}] }]
}, { }, {
name: 'modlogs', name: 'modlogs',
@ -35,10 +35,7 @@ class ImportCommand extends SlashCommand {
options: [{ options: [{
name: 'version', name: 'version',
description: 'Which version do you want to import from', description: 'Which version do you want to import from',
choices: [ choices: importChoices
{ name: 'v2', value: '2' },
{ name: 'v3', value: '3' }
]
}, { }, {
name: 'overwrite', name: 'overwrite',
description: 'Whether any existing logs should be overwritten by the imports. By default new ones are bumped', description: 'Whether any existing logs should be overwritten by the imports. By default new ones are bumped',
@ -54,7 +51,7 @@ class ImportCommand extends SlashCommand {
const data = await guild.fetchData(); const data = await guild.fetchData();
if (!data._imported) data._imported = {}; if (!data._imported) data._imported = {};
if (data._imported[subcommand.name]) return { emoji: 'failure', index: 'COMMAND_IMPORT_IMPORTED', params: { thing: Util.capitalise(subcommand.name) } }; if (data._imported[subcommand.name]) return { emoji: 'failure', index: 'COMMAND_IMPORT_IMPORTED', params: { thing: Util.capitalise(subcommand.name) } };
version = version?.value || '3'; version = version?.value || '2';
await invoker.reply({ index: 'COMMAND_IMPORT_WORKING', emoji: 'loading' }); await invoker.reply({ index: 'COMMAND_IMPORT_WORKING', emoji: 'loading' });
const result = await this[subcommand.name](guild, version, overwrite?.value); const result = await this[subcommand.name](guild, version, overwrite?.value);
@ -72,10 +69,10 @@ class ImportCommand extends SlashCommand {
async modlogs(guild, version, overwrite = false) { async modlogs(guild, version, overwrite = false) {
const migrator = new InfractionMigrator(this.client, guild, { const migrator = new InfractionMigrator(this.client, guild, {
host: version === '2' ? MONGODB_V2_HOST : MONGODB_HOST, host: version === '2' ? MONGODB_V2_HOST : MONGODB_QA_HOST,
username: version === '2' ? null : MONGODB_USERNAME, username: version === '2' ? null : MONGODB_USERNAME,
password: MONGODB_PASSWORD, password: MONGODB_PASSWORD,
database: dbs[version], // Default to v3 database: dbs[version],
version version
}); });
@ -114,7 +111,7 @@ class ImportCommand extends SlashCommand {
async settings(guild, version) { async settings(guild, version) {
// const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env; // const { MONGODB_HOST, MONGODB_USERNAME, MONGODB_PASSWORD } = process.env;
const migrator = new SettingsMigrator(this.client, guild, { const migrator = new SettingsMigrator(this.client, guild, {
host: version === '2' ? MONGODB_V2_HOST : MONGODB_HOST, host: version === '2' ? MONGODB_V2_HOST : MONGODB_QA_HOST,
username: version === '2' ? null : MONGODB_USERNAME, username: version === '2' ? null : MONGODB_USERNAME,
password: MONGODB_PASSWORD, password: MONGODB_PASSWORD,
database: dbs[version], // Default to v3 database: dbs[version], // Default to v3