modlogs import

This commit is contained in:
Erik 2022-06-18 14:01:37 +03:00
parent 3786cc2b40
commit b38206a795
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -89,11 +89,12 @@ 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' };
} }
await migrator.end(); await migrator.end();
console.log(imported); this.client.logger(`Imported ${imported.length} infractions in ${guild.name}`);
if (overwrite) { // Overwrite any existing logs with the imported ones if (overwrite) { // Overwrite any existing logs with the imported ones
await this.client.mongodb.infractions.deleteMany({ guild: guild.id }); await this.client.mongodb.infractions.deleteMany({ guild: guild.id });
await this.client.mongodb.infractions.insertMany(imported); await this.client.mongodb.infractions.insertMany(imported);
guild._data.caseId = imported[imported.length-1].case;
} else { // Bump existing logs by the highest case id from imported logs } else { // Bump existing logs by the highest case id from imported logs
const highestOldId = imported[imported.length - 1]; const highestOldId = imported[imported.length - 1];
const existingLogs = await this.client.mongodb.infractions.find({ guild: guild.id }); const existingLogs = await this.client.mongodb.infractions.find({ guild: guild.id });
@ -101,12 +102,11 @@ class ImportCommand extends SlashCommand {
log.case += highestOldId; log.case += highestOldId;
await this.client.mongodb.infractions.updateOne({ _id: log._id }, { case: log.case }); await this.client.mongodb.infractions.updateOne({ _id: log._id }, { case: log.case });
} }
guild._settings.caseId += highestOldId; guild._data.caseId += highestOldId;
await guild.updateSettings({ caseId: guild._settings.caseId });
} }
await guild.updateData({ caseId: guild._data.caseId });
return { content: 'blah' }; return { index: 'COMMAND_INFRACTIONS_IMPORT_SUCCESS', params: { cases: imported.length } };
} }
@ -148,8 +148,11 @@ class ImportCommand extends SlashCommand {
await this.client.storageManager.mongodb.permissions.updateOne({ guildId: guild.id }, permissions); await this.client.storageManager.mongodb.permissions.updateOne({ guildId: guild.id }, permissions);
} }
const { premium } = imported.settings;
delete imported.settings.premium;
await guild.updateData({ premium });
await guild.updateSettings(imported.settings); await guild.updateSettings(imported.settings);
return { index: 'COMMAND_IMPORT_SUCCESS', emoji: 'success' }; return { index: 'COMMAND_SETTINGS_IMPORT_SUCCESS', emoji: 'success' };
} }
} }