2020-04-08 18:08:46 +02:00
|
|
|
const { Structures } = require('discord.js');
|
|
|
|
|
|
|
|
const User = Structures.extend('User', (User) => {
|
|
|
|
|
|
|
|
class ExtendedUser extends User {
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
|
|
|
|
super(...args);
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
this._settings = null; //internal cache of current users' settings; should ALWAYS stay the same as database.
|
2020-04-09 23:08:28 +02:00
|
|
|
this._cached = Date.now();
|
2020-04-08 18:08:46 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-09 23:08:28 +02:00
|
|
|
get timeSinceCached() {
|
|
|
|
return Date.now()-this._cached;
|
|
|
|
}
|
|
|
|
|
2020-04-19 21:54:57 +02:00
|
|
|
async settings() {
|
|
|
|
|
|
|
|
if (!this._settings) this._settings = this.client.transactionHandler._send({ provider: 'mongodb', request: { collection: 'user_settings', type: 'findOne', query: { user: this.id } } });
|
|
|
|
if (this._settings instanceof Promise) this._settings = await this._settings || {};
|
|
|
|
return this._settings;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-08 18:08:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ExtendedUser;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = User;
|