diff --git a/src/structures/guild.ts b/src/structures/guild.ts index eb1147f16..05e68a8c2 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -63,7 +63,7 @@ export const guildToggles = { }; const baseGuild: Partial = { - 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; /** 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 }; } diff --git a/src/structures/member.ts b/src/structures/member.ts index 0a5daae9b..f839caa10 100644 --- a/src/structures/member.ts +++ b/src/structures/member.ts @@ -100,6 +100,32 @@ const baseMember: Partial = { 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 { addRole(guildId: bigint, roleId: bigint, reason?: string): ReturnType; /** Remove a role from the member */ removeRole(guildId: bigint, roleId: bigint, reason?: string): ReturnType; + /** Converts to a json object */ + toJSON(): (GuildMemberWithUser & { guildId: string })[]; } diff --git a/src/structures/message.ts b/src/structures/message.ts index defeea935..1fd6643b3 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -143,6 +143,54 @@ const baseMessage: Partial = { 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; /** Removes a reaction from the given user on this message, defaults to bot */ removeReaction(reaction: string, userId?: bigint): ReturnType; + /** Convert to json */ + toJSON(): Message; }