@lilybird/transformers
Version:
Event transformers and more for lilybird
55 lines (54 loc) • 2.07 kB
JavaScript
import { User } from "./user.js";
import { CDN } from "lilybird";
export class GuildMember {
user;
nick;
avatar;
roles;
joinedAt;
premiumSince;
deaf;
mute;
flags;
pending;
permissions;
communicationDisabledUntil;
guildId;
client;
constructor(client, member) {
this.client = client;
this.nick = member.nick;
this.avatar = member.avatar;
this.roles = member.roles;
this.deaf = member.deaf;
this.mute = member.mute;
this.joinedAt = new Date(member.joined_at);
this.flags = member.flags ?? 0;
this.pending = member.pending ?? false;
this.permissions = member.permissions;
if (typeof member.user !== "undefined")
this.user = new User(client, member.user);
if (member.premium_since != null)
this.premiumSince = new Date(member.premium_since);
if (member.communication_disabled_until != null)
this.communicationDisabledUntil = new Date(member.communication_disabled_until);
if ("guild_id" in member)
this.guildId = member.guild_id;
}
async modify(options) {
if (!this.guildId)
throw new Error("Something went wrong trying to modify the member");
if (typeof options.communication_disabled_until !== "undefined" && options.communication_disabled_until instanceof Date)
options.communication_disabled_until = options.communication_disabled_until.toISOString();
if (typeof options.flags !== "undefined")
options.flags.reduce((prev, curr) => prev | curr, 0);
await this.client.rest.modifyGuildMember(this.guildId, this.user.id, options);
}
avatarURL(options) {
if (this.avatar == null)
return this.user.avatarURL(options);
if (typeof this.guildId === "undefined")
throw new Error("Something went wrong and the guild id does not exist");
return CDN.guildMemberAvatarURL(this.guildId, this.user.id, this.avatar, options);
}
}