add member, message and fix guild toJSON

This commit is contained in:
Skillz4Killz
2021-05-23 13:31:35 +00:00
committed by GitHub
parent cffbaf05c5
commit d01602f12d
3 changed files with 80 additions and 2 deletions
+2 -2
View File
@@ -63,7 +63,7 @@ export const guildToggles = {
};
const baseGuild: Partial<DiscordenoGuild> = {
get toJSON() {
toJSON() {
return {
shardId: this.shardId!,
id: this.id?.toString(),
@@ -430,5 +430,5 @@ export interface DiscordenoGuild
/** Get all the invites for this guild. Requires MANAGE_GUILD permission */
invites(): ReturnType<typeof getInvites>;
/** Get the JSON version of the Guild object used to create this. Includes the shardId as well */
toJSON: Guild & { shardId: number };
toJSON(): Guild & { shardId: number };
}
+28
View File
@@ -100,6 +100,32 @@ const baseMember: Partial<DiscordenoMember> = {
get animatedAvatar() {
return Boolean(this.bitfield! & memberToggles.animatedAvatar);
},
toJSON() {
return (this.guilds?.map((g) => ({
user: {
id: this.id?.toString(),
username: this.username,
discriminator: this.discriminator?.toString(),
avatar: this.avatar,
bot: this.bot,
system: this.system,
mfaEnabled: this.mfaEnabled,
locale: this.locale,
verified: this.verified,
email: this.email,
flags: this.flags,
premiumType: this.premiumType,
publicFlags: this.publicFlags,
},
nick: g.nick,
roles: g.roles.map((id) => id.toString()),
joinedAt: g.joinedAt ? new Date(g.joinedAt).toISOString() : undefined,
premiumSince: g.premiumSince,
deaf: g.deaf,
mute: g.mute,
pending: g.pending,
})) || []) as (GuildMemberWithUser & { guildId: string })[];
},
};
export async function createDiscordenoMember(
@@ -220,4 +246,6 @@ export interface DiscordenoMember extends Omit<User, "discriminator" | "id"> {
addRole(guildId: bigint, roleId: bigint, reason?: string): ReturnType<typeof addRole>;
/** Remove a role from the member */
removeRole(guildId: bigint, roleId: bigint, reason?: string): ReturnType<typeof removeRole>;
/** Converts to a json object */
toJSON(): (GuildMemberWithUser & { guildId: string })[];
}
+50
View File
@@ -143,6 +143,54 @@ const baseMessage: Partial<DiscordenoMessage> = {
get pinned() {
return Boolean(this.bitfield! & messageToggles.pinned);
},
toJSON() {
return {
id: this.id?.toString(),
channelId: this.channelId?.toString(),
guildId: this.guildId?.toString(),
author: {
id: this.authorId?.toString(),
username: this.tag?.substring(0, this.tag.length - 5),
discriminator: this.tag?.substring(this.tag.length - 4),
avatar: this.member?.avatar,
bot: this.member?.bot,
system: this.member?.system,
mfaEnabled: this.member?.mfaEnabled,
locale: this.member?.locale,
verified: this.member?.verified,
email: this.member?.email,
flags: this.member?.flags,
premiumType: this.member?.premiumType,
publicFlags: this.member?.publicFlags,
},
member: this.member,
content: this.content,
timestamp: this.timestamp ? new Date(this.timestamp).toISOString() : undefined,
editedTimestamp: this.editedTimestamp ? new Date(this.editedTimestamp).toISOString() : undefined,
tts: this.tts,
mentionEveryone: this.mentionEveryone,
mentions: this.mentions,
mentionRoles: this.mentionRoles,
mentionChannels: this.mentionChannels,
attachments: this.attachments,
embeds: this.embeds,
reactions: this.reactions,
nonce: this.nonce,
pinned: this.pinned,
webhookId: this.webhookId,
type: this.type,
activity: this.activity,
application: this.application,
applicationId: this.applicationId,
messageReference: this.messageReference,
flags: this.flags,
stickers: this.stickers,
referencedMessage: this.referencedMessage,
interaction: this.interaction,
thread: this.thread,
components: this.components,
} as Message;
}
};
export async function createDiscordenoMessage(data: Message) {
@@ -314,4 +362,6 @@ export interface DiscordenoMessage
removeReactionEmoji(reaction: string): ReturnType<typeof removeReactionEmoji>;
/** Removes a reaction from the given user on this message, defaults to bot */
removeReaction(reaction: string, userId?: bigint): ReturnType<typeof removeReaction>;
/** Convert to json */
toJSON(): Message;
}