From b85a255e2eb70d9ce482df41c23178aaf303d5aa Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Thu, 21 Apr 2022 11:13:33 +0300 Subject: [PATCH] wrappers --- src/structure/client/wrappers/GuildWrapper.js | 19 +++++++ .../client/wrappers/InteractionWrapper.js | 5 ++ .../client/wrappers/MemberWrapper.js | 56 +++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/src/structure/client/wrappers/GuildWrapper.js b/src/structure/client/wrappers/GuildWrapper.js index 15503b8..45b0506 100644 --- a/src/structure/client/wrappers/GuildWrapper.js +++ b/src/structure/client/wrappers/GuildWrapper.js @@ -1,5 +1,6 @@ const { default: Collection } = require("@discordjs/collection"); const { Guild } = require("discord.js"); +const MemberWrapper = require("./MemberWrapper.js"); class GuildWrapper { @@ -11,6 +12,7 @@ class GuildWrapper { this.client = client; this.guild = guild; this.webhooks = new Collection(); + this.memberWrappers = new Collection(); this._settings = 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) { return this.client.resolver.resolveMembers(resolveables, strict, this); } diff --git a/src/structure/client/wrappers/InteractionWrapper.js b/src/structure/client/wrappers/InteractionWrapper.js index 74b3283..99c3b42 100644 --- a/src/structure/client/wrappers/InteractionWrapper.js +++ b/src/structure/client/wrappers/InteractionWrapper.js @@ -158,6 +158,11 @@ class InteractionWrapper { return this.interaction.member; } + async memberWrapper() { + if (!this.guild) return null; + return this.guild.memberWrapper(this.author); + } + get message() { return this.interaction.message; } diff --git a/src/structure/client/wrappers/MemberWrapper.js b/src/structure/client/wrappers/MemberWrapper.js index 46703f2..cf1ce94 100644 --- a/src/structure/client/wrappers/MemberWrapper.js +++ b/src/structure/client/wrappers/MemberWrapper.js @@ -1,5 +1,61 @@ 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; \ No newline at end of file