2020-05-07 01:26:16 +02:00
|
|
|
const { Structures } = require('discord.js');
|
|
|
|
|
|
|
|
const GuildMember = Structures.extend('GuildMember', (GuildMember) => {
|
|
|
|
|
|
|
|
class ExtendedGuildMember extends GuildMember {
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
|
|
|
|
super(...args);
|
|
|
|
|
|
|
|
this._cached = Date.now();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-04 12:23:10 +02:00
|
|
|
async _getExpiration(type) {
|
|
|
|
if(!type) return null;
|
|
|
|
const { callbacks } = this.client.moderationManager;
|
|
|
|
const filtered = callbacks.filter((e) => e.infraction.type === type
|
2020-06-16 00:15:13 +02:00
|
|
|
&& e.infraction.target === this.id);
|
|
|
|
|
2020-07-20 00:42:21 +02:00
|
|
|
if(filtered.size > 0) return filtered.first();
|
2020-06-16 00:15:13 +02:00
|
|
|
const result = await this.client.transactionHandler.send({ //Checking for permanent mutes, won't show up in expirations.
|
|
|
|
provider: 'mongodb',
|
|
|
|
request: {
|
|
|
|
collection: 'infractions',
|
|
|
|
type: 'findOne',
|
2020-07-04 12:23:10 +02:00
|
|
|
query: { duration: 0, type, target: this.id },
|
|
|
|
sort: { timestamp: -1 } //latest mute
|
2020-06-16 00:15:13 +02:00
|
|
|
}
|
2020-07-04 12:23:10 +02:00
|
|
|
}).catch((e) => { return null }); //eslint-disable-line
|
2020-06-16 00:15:13 +02:00
|
|
|
if(result) return result;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-19 23:02:59 +02:00
|
|
|
get admin() {
|
|
|
|
return this.user.developer || this.hasPermission('ADMINISTRATOR') || this.hasPermission('MANAGE_GUILD');
|
|
|
|
}
|
|
|
|
|
2020-05-07 01:26:16 +02:00
|
|
|
get timeSinceCached() {
|
|
|
|
return Date.now()-this._cached;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ExtendedGuildMember;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = GuildMember;
|