64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
const { Structures } = require('discord.js');
|
|
|
|
const GuildMember = Structures.extend('GuildMember', (GuildMember) => {
|
|
|
|
class ExtendedGuildMember extends GuildMember {
|
|
|
|
constructor(...args) {
|
|
|
|
super(...args);
|
|
|
|
this._cached = Date.now();
|
|
|
|
}
|
|
|
|
async _getExpiration(type) {
|
|
if(!type) return null;
|
|
const { callbacks } = this.client.moderationManager;
|
|
const filtered = callbacks.filter((e) => e.infraction.type === type
|
|
&& e.infraction.target === this.id);
|
|
|
|
if(filtered.size > 0) return filtered.first();
|
|
const result = await this.client.storageManager.mongodb.infractions.findOne(
|
|
{ duration: { $gt: 0 }, type, target: this.id },
|
|
{ sort: { timestamp: -1 } }// Finds latest mute.
|
|
).catch((error) => { //eslint-disable-line no-unused-vars
|
|
return null;
|
|
});
|
|
|
|
return result || null;
|
|
}
|
|
|
|
get admin() {
|
|
return this.user.developer || this.hasPermission('ADMINISTRATOR') || this.hasPermission('MANAGE_GUILD');
|
|
}
|
|
|
|
get highestRoleColor() {
|
|
const role = this.roles.cache.filter((role) => role.color !== 0).sort((a, b) => b.rawPosition - a.rawPosition).first();
|
|
if(role) return role.color;
|
|
return 0;
|
|
}
|
|
|
|
get timeSinceCached() {
|
|
return Date.now()-this._cached;
|
|
}
|
|
|
|
get display() {
|
|
return this.user.tag;
|
|
}
|
|
|
|
get mention() {
|
|
return `<@${this.user.id}>`;
|
|
}
|
|
|
|
get developer() {
|
|
return this.user.developer;
|
|
}
|
|
|
|
}
|
|
|
|
return ExtendedGuildMember;
|
|
|
|
});
|
|
|
|
module.exports = GuildMember; |