Skip to content

Commit

Permalink
Merge branch 'dev' into dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC authored Jul 16, 2024
2 parents 71175dd + 0135689 commit 81ee288
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 14 deletions.
16 changes: 16 additions & 0 deletions lib/structures/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default class Member extends Base {
avatar: string | null;
/** The data for this user's avatar decoration. */
avatarDecorationData: AvatarDecorationData | null;
/** The member's banner hash, if they have set a guild banner. */
banner: string | null;
/** When the member's [timeout](https://support.discord.com/hc/en-us/articles/4413305239191-Time-Out-FAQ) will expire, if active. */
communicationDisabledUntil: Date | null;
/** If this member is server deafened. */
Expand Down Expand Up @@ -66,6 +68,7 @@ export default class Member extends Base {
super(user.id, client);
this.avatar = null;
this.avatarDecorationData = null;
this.banner = null;
this.communicationDisabledUntil = null;
this.deaf = !!data.deaf;
this.flags = 0;
Expand Down Expand Up @@ -94,6 +97,9 @@ export default class Member extends Base {
skuID: data.avatar_decoration_data.sku_id
} : null;
}
if (data.banner !== undefined) {
this.banner = data.banner;
}
if (data.communication_disabled_until !== undefined) {
this.communicationDisabledUntil = data.communication_disabled_until === null ? null : new Date(data.communication_disabled_until);
}
Expand Down Expand Up @@ -231,6 +237,15 @@ export default class Member extends Base {
await this.client.rest.guilds.createBan(this.guildID, this.id, options);
}

/**
* The url of this user's guild banner (or their user banner if no guild banner is set).
* @param format The format the url should be.
* @param size The dimensions of the image.
*/
bannerURL(format?: ImageFormat, size?: number): string | null {
return this.banner === null ? this.user.bannerURL(format, size) : this.client.util.formatImage(Routes.MEMBER_BANNER(this.guildID, this.id, this.banner), format, size);
}

/**
* Disable the `BYPASSES_VERIFICATION` flag for this member. Requires any of the following permission sets:
* * MANAGE_GUILD
Expand Down Expand Up @@ -288,6 +303,7 @@ export default class Member extends Base {
...super.toJSON(),
avatar: this.avatar,
avatarDecorationData: this.avatarDecorationData,
banner: this.banner,
communicationDisabledUntil: this.communicationDisabledUntil?.getTime() ?? null,
deaf: this.deaf,
flags: this.flags,
Expand Down
56 changes: 42 additions & 14 deletions lib/structures/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ import type {
RoleSubscriptionData,
MessageInteractionMetadata,
GetPollAnswerUsersOptions,
Call
Call,
MessageSnapshot,
MessageMentions
} from "../types/channels";
import type { RawMember } from "../types/guilds";
import type { DeleteWebhookMessageOptions, EditWebhookMessageOptions } from "../types/webhooks";
Expand Down Expand Up @@ -95,20 +97,11 @@ export default class Message<T extends AnyTextableChannel | Uncached = AnyTextab
/** Channels mentioned in a `CROSSPOSTED` channel follower message. See [Discord's docs](https://discord.com/developers/docs/resources/channel#channel-mention-object) for more information. */
mentionChannels?: Array<ChannelMention>;
/** The mentions in this message. */
mentions: {
/** The ids of the channels mentioned in this message. */
channels: Array<string>;
/** If @everyone/@here is mentioned in this message. */
everyone: boolean;
/** The members mentioned in this message. */
members: Array<Member>;
/** The ids of the roles mentioned in this message. */
roles: Array<string>;
/** The users mentioned in this message. */
users: Array<User>;
};
mentions: MessageMentions;
/** If this message is a `REPLY` or `THREAD_STARTER_MESSAGE`, some info about the referenced message. */
messageReference?: MessageReference;
/** If this message is a forwarded message, the partial contents of that message. */
messageSnapshots?: Array<MessageSnapshot>;
/** A nonce for ensuring a message was sent. */
nonce?: number | string;
/** If this message is pinned. */
Expand Down Expand Up @@ -279,6 +272,25 @@ export default class Message<T extends AnyTextableChannel | Uncached = AnyTextab
};
}

if (data.message_snapshots) {
this.messageSnapshots = data.message_snapshots.map(s => ({
message: {
attachments: s.message.attachments.map(a => new Attachment(a, this.client)),
content: s.message.content,
editedTimestamp: s.message.edited_timestamp ? new Date(s.message.edited_timestamp) : null,
embeds: this.client.util.embedsToParsed(s.message.embeds),
flags: s.message.flags ?? 0,
mentions: {
channels: (s.message.content.match(/<#\d{17,21}>/g) ?? []).map(mention => mention.slice(2, -1)),
roles: s.message.mention_roles,
users: s.message.mentions.map(u => this.client.users.update(u))
},
timestamp: new Date(s.message.timestamp),
type: s.message.type
}
}));
}

if (data.nonce !== undefined) {
this.nonce = data.nonce;
}
Expand Down Expand Up @@ -533,7 +545,23 @@ export default class Message<T extends AnyTextableChannel | Uncached = AnyTextab
roles: this.mentions.roles,
users: this.mentions.users.map(user => user.toJSON())
},
messageReference: this.messageReference,
messageReference: this.messageReference,
messageSnapshots: this.messageSnapshots?.map(s => ({
message: {
attachments: s.message.attachments.map(a => a.toJSON()),
content: s.message.content,
editedTimestamp: s.message.editedTimestamp?.getTime() ?? null,
embeds: s.message.embeds,
flags: s.message.flags,
mentions: {
channels: s.message.mentions.channels,
roles: s.message.mentions.roles,
users: s.message.mentions.users.map(u => u.toJSON())
},
timestamp: s.message.timestamp.getTime(),
type: s.message.type
}
})),
nonce: this.nonce,
pinned: this.pinned,
position: this.position,
Expand Down
13 changes: 13 additions & 0 deletions lib/structures/OAuthGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default class OAuthGuild extends Base {
approximateMemberCount?: number;
/** The approximate number of non-offline members in this guild (if retrieved with counts). */
approximatePresenceCount?: number;
/** The hash of this guild's banner. */
banner: string | null;
/** The [features](https://discord.com/developers/docs/resources/guild#guild-object-guild-features) this guild has. */
features: Array<GuildFeature>;
/** The icon hash of this guild. */
Expand All @@ -28,6 +30,7 @@ export default class OAuthGuild extends Base {
super(data.id, client);
this.approximateMemberCount = data.approximate_member_count;
this.approximatePresenceCount = data.approximate_presence_count;
this.banner = data.banner;
this.features = data.features;
this.name = data.name;
this.icon = data.icon;
Expand All @@ -40,6 +43,15 @@ export default class OAuthGuild extends Base {
return this._cachedCompleteGuild ??= this.client.guilds.get(this.id);
}

/**
* The url of this guild's banner.
* @param format The format the url should be.
* @param size The dimensions of the image.
*/
bannerURL(format?: ImageFormat, size?: number): string | null {
return this.banner === null ? null : this.client.util.formatImage(Routes.BANNER(this.id, this.banner), format, size);
}

/**
* The url of this guild's icon.
* @param format The format the url should be.
Expand All @@ -54,6 +66,7 @@ export default class OAuthGuild extends Base {
...super.toJSON(),
approximateMemberCount: this.approximateMemberCount,
approximatePresenceCount: this.approximatePresenceCount,
banner: this.banner,
features: this.features,
icon: this.icon,
name: this.name,
Expand Down
35 changes: 35 additions & 0 deletions lib/types/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import type ForumChannel from "../structures/ForumChannel";
import type Message from "../structures/Message";
import type Guild from "../structures/Guild";
import type Invite from "../structures/Invite";
import type Attachment from "../structures/Attachment";

export interface RawChannel {
application_id?: string;
Expand Down Expand Up @@ -704,6 +705,7 @@ export interface RawMessage {
mention_roles: Array<string>;
mentions: Array<RawUserWithMember>;
message_reference?: RawMessageReference;
message_snapshots?: Array<RawMessageSnapshot>;
nonce?: number | string;
pinned: boolean;
poll?: RawPoll;
Expand Down Expand Up @@ -1271,3 +1273,36 @@ export interface EventReaction {
emoji: PartialEmoji;
type: ReactionType;
}

export interface RawMessageSnapshotMessage extends Pick<RawMessage, "type" | "content" | "embeds" | "attachments" | "timestamp" | "edited_timestamp" | "flags" | "mentions" | "mention_roles"> {}

export interface RawMessageSnapshot {
message: RawMessageSnapshotMessage;
}
export interface MessageSnapshotMessage {
attachments: Array<Attachment>;
content: string;
editedTimestamp: Date | null;
embeds: Array<Embed>;
flags: number;
mentions: Omit<MessageMentions, "everyone" | "members">;
timestamp: Date;
type: MessageTypes;
}

export interface MessageSnapshot {
message: MessageSnapshotMessage;
}

export interface MessageMentions {
/** The ids of the channels mentioned in this message. */
channels: Array<string>;
/** If @everyone/@here is mentioned in this message. */
everyone: boolean;
/** The members mentioned in this message. */
members: Array<Member>;
/** The ids of the roles mentioned in this message. */
roles: Array<string>;
/** The users mentioned in this message. */
users: Array<User>;
}
2 changes: 2 additions & 0 deletions lib/types/guilds.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export interface Sticker {
export interface RawMember {
avatar?: string | null;
avatar_decoration_data?: RawAvatarDecorationData | null;
banner?: string | null;
communication_disabled_until?: string | null;
deaf: boolean;
/** undocumented */
Expand Down Expand Up @@ -734,6 +735,7 @@ export interface StickerPack {
export interface RawOAuthGuild {
approximate_member_count?: number;
approximate_presence_count?: number;
banner: string | null;
features: Array<GuildFeature>;
icon: string | null;
id: string;
Expand Down
18 changes: 18 additions & 0 deletions lib/types/json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export interface JSONMediaChannel extends JSONThreadOnlyChannel {
export interface JSONMember extends JSONBase {
avatar: string | null;
avatarDecorationData: AvatarDecorationData | null;
banner: string | null;
communicationDisabledUntil: number | null;
deaf: boolean;
flags?: number;
Expand Down Expand Up @@ -499,6 +500,22 @@ export interface JSONMessage extends JSONBase {
users: Array<JSONUser>;
};
messageReference?: MessageReference;
messageSnapshots?: Array<{
message: {
attachments: Array<JSONAttachment>;
content: string;
editedTimestamp: number | null;
embeds: Array<Embed>;
flags: number;
mentions: {
channels: Array<string>;
roles: Array<string>;
users: Array<JSONUser>;
};
timestamp: number;
type: MessageTypes;
};
}>;
nonce?: number | string;
pinned: boolean;
position?: number;
Expand Down Expand Up @@ -553,6 +570,7 @@ export interface JSONOAuthApplication extends JSONBase {
export interface JSONOAuthGuild extends JSONBase {
approximateMemberCount?: number;
approximatePresenceCount?: number;
banner: string | null;
features: Array<GuildFeature>;
icon: string | null;
name: string;
Expand Down

0 comments on commit 81ee288

Please sign in to comment.