2020-04-19 12:12:10 +02:00
|
|
|
const escapeRegex = require('escape-string-regexp');
|
2020-04-08 18:08:46 +02:00
|
|
|
const { Structures } = require('discord.js');
|
|
|
|
|
|
|
|
const Guild = Structures.extend('Guild', (Guild) => {
|
|
|
|
|
|
|
|
class ExtendedGuild extends Guild {
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this._settings = null; //internal cache of current guild's settings; should ALWAYS stay the same as database.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-19 10:27:13 +02:00
|
|
|
async settings() {
|
|
|
|
|
|
|
|
if (!this._settings) this._settings = this.client.transactionHandler._send({ provider: 'mongodb', request: { type: 'findOne', query: { guild: this.id } } });
|
|
|
|
if (this._settings instanceof Promise) this._settings = await this._settings;
|
|
|
|
return this._settings;
|
|
|
|
|
|
|
|
}
|
2020-04-19 12:12:10 +02:00
|
|
|
|
|
|
|
async format(key, parameters = {}) {
|
|
|
|
const language = "en_us"; //this._settings.language or something idk
|
|
|
|
|
|
|
|
let value = this.client.localeLoader.languages[language][key];
|
|
|
|
for(const [param, val] of Object.entries(parameters)) {
|
|
|
|
value = value.replace(new RegExp(`{${escapeRegex(param.toLowerCase())}}`, 'gi'), val);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-19 10:27:13 +02:00
|
|
|
|
2020-04-11 10:06:39 +02:00
|
|
|
async resolveMembers(members, strict = false) {
|
|
|
|
|
|
|
|
return await this.client.resolver.resolveMembers(members, this, strict);
|
2020-04-17 17:23:13 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
async resolveMember(member, strict) {
|
|
|
|
|
|
|
|
let [ result ] = await this.resolveMembers([ member ], strict);
|
|
|
|
return result;
|
|
|
|
|
2020-04-11 10:06:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async resolveChannels(channels, strict = false) {
|
|
|
|
|
|
|
|
return await this.client.resolver.resolveChannels(channels, this, strict);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-17 17:23:13 +02:00
|
|
|
async resolveChannel(channel, strict) {
|
|
|
|
|
|
|
|
let [ result ] = await this.resolveMembers([ channel ], strict);
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-11 10:06:39 +02:00
|
|
|
async resolveRoles(roles, strict = false) {
|
|
|
|
|
|
|
|
return await this.client.resolver.resolveRoles(roles, this, strict);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-17 17:23:13 +02:00
|
|
|
async resolveRole(role, strict) {
|
|
|
|
|
|
|
|
let [ result ] = await this.resolveRoles([ role ], strict);
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ExtendedGuild;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Guild;
|