v2 is no more

This commit is contained in:
Erik 2023-01-29 19:36:28 +02:00
parent d73d1b4798
commit 63a8c79ec0
Signed by: Navy.gif
GPG Key ID: 2532FBBB61C65A68

View File

@ -5,8 +5,6 @@ const { FilterUtil, SettingsMigrator, InfractionMigrator } = require("../../../u
const MemberWrapper = require("./MemberWrapper.js"); const MemberWrapper = require("./MemberWrapper.js");
const configVersion = '3.slash.2'; const configVersion = '3.slash.2';
const { MONGODB_V2_HOST } = process.env;
class GuildWrapper { class GuildWrapper {
constructor(client, guild) { constructor(client, guild) {
@ -31,7 +29,7 @@ class GuildWrapper {
const now = Date.now(); const now = Date.now();
const id = `${type}:${user}:${now}`; const id = `${type}:${user}:${now}`;
const data = { ...opts, user, id, guild: this.id, type, time: duration * 1000, created: now }; const data = { ...opts, user, id, guild: this.id, type, time: duration * 1000, created: now };
if(duration) await this.createCallback(data); if (duration) await this.createCallback(data);
} }
async createReminder({ time, user, channel, reminder }) { async createReminder({ time, user, channel, reminder }) {
@ -60,12 +58,12 @@ class GuildWrapper {
const cb = { timeout: setTimeout(handler.bind(this), diff, data), data }; const cb = { timeout: setTimeout(handler.bind(this), diff, data), data };
this.callbacks.set(data.id, cb); this.callbacks.set(data.id, cb);
if(update) await this.client.mongodb.callbacks.updateOne({ id: data.id, guild: this.id }, data); if (update) await this.client.mongodb.callbacks.updateOne({ id: data.id, guild: this.id }, data);
} }
async removeCallback(id) { async removeCallback(id) {
const cb = this.callbacks.get(id); const cb = this.callbacks.get(id);
if(cb) clearTimeout(cb.timeout); if (cb) clearTimeout(cb.timeout);
this.callbacks.delete(id); this.callbacks.delete(id);
await this.client.mongodb.callbacks.deleteOne({ guild: this.id, id }); await this.client.mongodb.callbacks.deleteOne({ guild: this.id, id });
} }
@ -81,8 +79,8 @@ class GuildWrapper {
const result = {}; const result = {};
for (const emoji of reactionEmojis) { for (const emoji of reactionEmojis) {
let reaction = reactions.resolve(emoji); let reaction = reactions.resolve(emoji);
if(!reaction) continue; if (!reaction) continue;
if(reaction.partial) reaction = await reaction.fetch(); if (reaction.partial) reaction = await reaction.fetch();
result[emoji] = reaction.count - 1; result[emoji] = reaction.count - 1;
} }
@ -93,7 +91,7 @@ class GuildWrapper {
} }
} }
await this.removeCallback(id); await this.removeCallback(id);
if(startedIn) await startedIn.send(this.format('COMMAND_POLL_NOTIFY_STARTER', { user, channel })); if (startedIn) await startedIn.send(this.format('COMMAND_POLL_NOTIFY_STARTER', { user, channel }));
} }
async _reminder({ reminder, user, channel, id }) { async _reminder({ reminder, user, channel, id }) {
@ -104,7 +102,8 @@ class GuildWrapper {
title: this.format('GENERAL_REMINDER_TITLE'), title: this.format('GENERAL_REMINDER_TITLE'),
description: reminder, description: reminder,
color: EmbedDefaultColor color: EmbedDefaultColor
}] }); }]
});
await this.removeCallback(id); await this.removeCallback(id);
} }
@ -128,7 +127,7 @@ class GuildWrapper {
} }
async fetchData() { async fetchData() {
if(this._data) return this._data; if (this._data) return this._data;
const data = await this.client.mongodb.guilds.findOne({ guildId: this.id }); const data = await this.client.mongodb.guilds.findOne({ guildId: this.id });
if (!data) { if (!data) {
this._data = {}; this._data = {};
@ -155,16 +154,20 @@ class GuildWrapper {
const data = await this.fetchData(); const data = await this.fetchData();
// eslint-disable-next-line prefer-const // eslint-disable-next-line prefer-const
let { settings, _imported } = data; const {
settings,
// _imported
} = data;
const { defaultConfig } = this; const { defaultConfig } = this;
if (!settings && !_imported?.settings && !_imported?.modlogs && process.env.NODE_ENV === 'staging') { // V2 db server is no more, leaving this here if needed again
if (this._importPromise) settings = await this._importPromise; // if (!settings && !_imported?.settings && !_imported?.modlogs && process.env.NODE_ENV === 'staging') {
else { // if (this._importPromise) settings = await this._importPromise;
this._importPromise = this._attemptDataImport(); // else {
settings = await this._importPromise; // this._importPromise = this._attemptDataImport();
} // settings = await this._importPromise;
} // }
// }
if (settings) { if (settings) {
// Ensure new settings properties are propagated to existing configs // Ensure new settings properties are propagated to existing configs
@ -221,7 +224,7 @@ class GuildWrapper {
async _attemptDataImport() { async _attemptDataImport() {
const migratorOptions = { const migratorOptions = {
host: MONGODB_V2_HOST, // host: MONGODB_V2_HOST,
database: 'galacticbot', database: 'galacticbot',
version: '2' version: '2'
}; };