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 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 }) {
|
||||||
@ -52,20 +50,20 @@ class GuildWrapper {
|
|||||||
async createCallback(data, update = true) {
|
async createCallback(data, update = true) {
|
||||||
const handler = this[`_${data.type}`];//.bind(this);
|
const handler = this[`_${data.type}`];//.bind(this);
|
||||||
if (!handler) throw new Error(`Invalid callback type`);
|
if (!handler) throw new Error(`Invalid callback type`);
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
const time = data.created + data.time;
|
const time = data.created + data.time;
|
||||||
const diff = time - now;
|
const diff = time - now;
|
||||||
if (diff < 5000) return handler.bind(this)(data);
|
if (diff < 5000) return handler.bind(this)(data);
|
||||||
|
|
||||||
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
|
||||||
@ -173,7 +176,7 @@ class GuildWrapper {
|
|||||||
if (!(key in defaultConfig)) continue;
|
if (!(key in defaultConfig)) continue;
|
||||||
defaultConfig[key] = { ...defaultConfig[key], ...settings[key] };
|
defaultConfig[key] = { ...defaultConfig[key], ...settings[key] };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._settings = defaultConfig;
|
this._settings = defaultConfig;
|
||||||
@ -205,7 +208,7 @@ class GuildWrapper {
|
|||||||
const perms = await this.client.storageManager.mongodb.permissions.findOne({ guildId: this.id });
|
const perms = await this.client.storageManager.mongodb.permissions.findOne({ guildId: this.id });
|
||||||
if (!perms) this._permissions = { guildId: this.id };
|
if (!perms) this._permissions = { guildId: this.id };
|
||||||
else this._permissions = perms;
|
else this._permissions = perms;
|
||||||
|
|
||||||
return this._permissions;
|
return this._permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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'
|
||||||
};
|
};
|
||||||
@ -264,7 +267,7 @@ class GuildWrapper {
|
|||||||
if (webhook) {
|
if (webhook) {
|
||||||
const hooks = await this.fetchWebhooks().catch(() => null);
|
const hooks = await this.fetchWebhooks().catch(() => null);
|
||||||
const hook = hooks?.get(webhook);
|
const hook = hooks?.get(webhook);
|
||||||
if (hook)
|
if (hook)
|
||||||
await this.updateWebhook('messages', hook);
|
await this.updateWebhook('messages', hook);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,7 +363,7 @@ class GuildWrapper {
|
|||||||
|
|
||||||
async userWrapper() {
|
async userWrapper() {
|
||||||
if (this._userWrapper) return this._userWrapper;
|
if (this._userWrapper) return this._userWrapper;
|
||||||
|
|
||||||
this._userWrapper = await this.client.getUserWrapper(this.author.id);
|
this._userWrapper = await this.client.getUserWrapper(this.author.id);
|
||||||
return this._userWrapper;
|
return this._userWrapper;
|
||||||
}
|
}
|
||||||
@ -369,7 +372,7 @@ class GuildWrapper {
|
|||||||
const member = await this.resolveMember(user);
|
const member = await this.resolveMember(user);
|
||||||
if (!member) return Promise.reject(new Error('No member found'));
|
if (!member) return Promise.reject(new Error('No member found'));
|
||||||
if (this.memberWrappers.has(member.id)) return this.memberWrappers.get(member.id);
|
if (this.memberWrappers.has(member.id)) return this.memberWrappers.get(member.id);
|
||||||
|
|
||||||
const wrapper = new MemberWrapper(this.client, member);
|
const wrapper = new MemberWrapper(this.client, member);
|
||||||
this.memberWrappers.set(wrapper.id, wrapper);
|
this.memberWrappers.set(wrapper.id, wrapper);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
|
Loading…
Reference in New Issue
Block a user