galactic-bot/structure/extensions/GuildMember.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

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
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();
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;
2020-06-16 00:15:13 +02:00
}
2020-06-19 23:02:59 +02:00
get admin() {
return this.user.developer || this.hasPermission('ADMINISTRATOR') || this.hasPermission('MANAGE_GUILD');
}
2021-05-10 22:52:48 +02:00
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}>`;
}
2020-09-30 18:24:28 +02:00
get developer() {
return this.user.developer;
}
}
return ExtendedGuildMember;
});
module.exports = GuildMember;