forked from Galactic/galactic-bot
v2 is no more
This commit is contained in:
parent
d73d1b4798
commit
63a8c79ec0
@ -5,8 +5,6 @@ const { FilterUtil, SettingsMigrator, InfractionMigrator } = require("../../../u
|
||||
const MemberWrapper = require("./MemberWrapper.js");
|
||||
const configVersion = '3.slash.2';
|
||||
|
||||
const { MONGODB_V2_HOST } = process.env;
|
||||
|
||||
class GuildWrapper {
|
||||
|
||||
constructor(client, guild) {
|
||||
@ -31,7 +29,7 @@ class GuildWrapper {
|
||||
const now = Date.now();
|
||||
const id = `${type}:${user}:${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 }) {
|
||||
@ -60,12 +58,12 @@ class GuildWrapper {
|
||||
|
||||
const cb = { timeout: setTimeout(handler.bind(this), diff, data), data };
|
||||
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) {
|
||||
const cb = this.callbacks.get(id);
|
||||
if(cb) clearTimeout(cb.timeout);
|
||||
if (cb) clearTimeout(cb.timeout);
|
||||
this.callbacks.delete(id);
|
||||
await this.client.mongodb.callbacks.deleteOne({ guild: this.id, id });
|
||||
}
|
||||
@ -81,8 +79,8 @@ class GuildWrapper {
|
||||
const result = {};
|
||||
for (const emoji of reactionEmojis) {
|
||||
let reaction = reactions.resolve(emoji);
|
||||
if(!reaction) continue;
|
||||
if(reaction.partial) reaction = await reaction.fetch();
|
||||
if (!reaction) continue;
|
||||
if (reaction.partial) reaction = await reaction.fetch();
|
||||
result[emoji] = reaction.count - 1;
|
||||
}
|
||||
|
||||
@ -93,7 +91,7 @@ class GuildWrapper {
|
||||
}
|
||||
}
|
||||
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 }) {
|
||||
@ -104,7 +102,8 @@ class GuildWrapper {
|
||||
title: this.format('GENERAL_REMINDER_TITLE'),
|
||||
description: reminder,
|
||||
color: EmbedDefaultColor
|
||||
}] });
|
||||
}]
|
||||
});
|
||||
await this.removeCallback(id);
|
||||
}
|
||||
|
||||
@ -128,7 +127,7 @@ class GuildWrapper {
|
||||
}
|
||||
|
||||
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 });
|
||||
if (!data) {
|
||||
this._data = {};
|
||||
@ -155,16 +154,20 @@ class GuildWrapper {
|
||||
|
||||
const data = await this.fetchData();
|
||||
// eslint-disable-next-line prefer-const
|
||||
let { settings, _imported } = data;
|
||||
const {
|
||||
settings,
|
||||
// _imported
|
||||
} = data;
|
||||
const { defaultConfig } = this;
|
||||
|
||||
if (!settings && !_imported?.settings && !_imported?.modlogs && process.env.NODE_ENV === 'staging') {
|
||||
if (this._importPromise) settings = await this._importPromise;
|
||||
else {
|
||||
this._importPromise = this._attemptDataImport();
|
||||
settings = await this._importPromise;
|
||||
}
|
||||
}
|
||||
// V2 db server is no more, leaving this here if needed again
|
||||
// if (!settings && !_imported?.settings && !_imported?.modlogs && process.env.NODE_ENV === 'staging') {
|
||||
// if (this._importPromise) settings = await this._importPromise;
|
||||
// else {
|
||||
// this._importPromise = this._attemptDataImport();
|
||||
// settings = await this._importPromise;
|
||||
// }
|
||||
// }
|
||||
|
||||
if (settings) {
|
||||
// Ensure new settings properties are propagated to existing configs
|
||||
@ -221,7 +224,7 @@ class GuildWrapper {
|
||||
|
||||
async _attemptDataImport() {
|
||||
const migratorOptions = {
|
||||
host: MONGODB_V2_HOST,
|
||||
// host: MONGODB_V2_HOST,
|
||||
database: 'galacticbot',
|
||||
version: '2'
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user