forked from Galactic/galactic-bot
35 lines
891 B
JavaScript
35 lines
891 B
JavaScript
const { Structures } = require('discord.js');
|
|
|
|
const User = Structures.extend('User', (User) => {
|
|
|
|
class ExtendedUser extends User {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
|
|
this._settings = null; //internal cache of current users' settings; should ALWAYS stay the same as database.
|
|
this._cached = Date.now();
|
|
|
|
}
|
|
|
|
get timeSinceCached() {
|
|
return Date.now()-this._cached;
|
|
}
|
|
|
|
async settings() {
|
|
|
|
if (!this._settings) this._settings = this.client.transactionHandler.send({ provider: 'mongodb', request: { collection: 'users', type: 'findOne', query: { user: this.id } } });
|
|
if (this._settings instanceof Promise) this._settings = await this._settings || {};
|
|
return this._settings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ExtendedUser;
|
|
|
|
});
|
|
|
|
module.exports = User; |