This commit is contained in:
Erik 2022-04-21 11:13:33 +03:00
parent f1ebfbaa46
commit b85a255e2e
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB
3 changed files with 80 additions and 0 deletions

View File

@ -1,5 +1,6 @@
const { default: Collection } = require("@discordjs/collection"); const { default: Collection } = require("@discordjs/collection");
const { Guild } = require("discord.js"); const { Guild } = require("discord.js");
const MemberWrapper = require("./MemberWrapper.js");
class GuildWrapper { class GuildWrapper {
@ -11,6 +12,7 @@ class GuildWrapper {
this.client = client; this.client = client;
this.guild = guild; this.guild = guild;
this.webhooks = new Collection(); this.webhooks = new Collection();
this.memberWrappers = new Collection();
this._settings = null; this._settings = null;
this._permissions = null; this._permissions = null;
@ -141,6 +143,23 @@ class GuildWrapper {
} }
async userWrapper() {
if (this._userWrapper) return this._userWrapper;
this._userWrapper = await this.client.getUserWrapper(this.author.id);
return this._userWrapper;
}
async memberWrapper(user) {
const member = await this.resolveMember(user);
if (!member) return Promise.reject(new Error('No member found'));
if (this.memberWrappers.has(member.id)) return this.memberWrappers.get(member.id);
const wrapper = new MemberWrapper(this.client, member);
this.memberWrappers.set(wrapper.id, wrapper);
return wrapper;
}
resolveMembers(resolveables, strict) { resolveMembers(resolveables, strict) {
return this.client.resolver.resolveMembers(resolveables, strict, this); return this.client.resolver.resolveMembers(resolveables, strict, this);
} }

View File

@ -158,6 +158,11 @@ class InteractionWrapper {
return this.interaction.member; return this.interaction.member;
} }
async memberWrapper() {
if (!this.guild) return null;
return this.guild.memberWrapper(this.author);
}
get message() { get message() {
return this.interaction.message; return this.interaction.message;
} }

View File

@ -1,5 +1,61 @@
class MemberWrapper { class MemberWrapper {
constructor(client, member) {
this.client = client;
this.member = member;
this._user = null;
}
async userWrapper() {
if (this._user) return this._user;
this._user = await this.client.getUserWrapper(this.id);
return this._user;
}
async isAdmin() {
return (await this.userWrapper()).developer || this.permissions.missing(['ADMINISTRATOR', 'MANAGE_GUILD']).length === 2;
}
get id() {
return this.member.id;
}
get permissions() {
return this.member.permissions;
}
get roles() {
return this.member.roles;
}
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 presence() {
return this.member.presence;
}
get nickname() {
return this.member.nickname;
}
get joinedAt() {
return this.member.joinedAt;
}
get joinedTimestamp() {
return this.member.joinedTimestamp;
}
get lastMessage() {
return this.member.lastMessage;
}
} }
module.exports = MemberWrapper; module.exports = MemberWrapper;