From a1832f372101be04050375aa41fbc10708eef345 Mon Sep 17 00:00:00 2001 From: Skillz Date: Mon, 16 Nov 2020 22:20:06 -0500 Subject: [PATCH] needs testing --- src/handlers/channel.ts | 19 ++++++++++++++++++- src/structures/message.ts | 3 +++ src/types/channel.ts | 4 ++++ src/types/message.ts | 7 +++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/handlers/channel.ts b/src/handlers/channel.ts index b74965be7..a3f639731 100644 --- a/src/handlers/channel.ts +++ b/src/handlers/channel.ts @@ -182,6 +182,17 @@ export async function sendMessage( content.mentions.roles = content.mentions.roles.slice(0, 100); } } + + if (content.mentions.repliedUser) { + if ( + !(await botHasChannelPermissions( + channelID, + [Permissions.READ_MESSAGE_HISTORY], + )) + ) { + throw new Error(Errors.MISSING_SEND_MESSAGES); + } + } } const channel = await cacheHandlers.get("channels", channelID); @@ -197,7 +208,13 @@ export async function sendMessage( endpoints.CHANNEL_MESSAGES(channelID), { ...content, - allowed_mentions: content.mentions, + allowed_mentions: content.mentions + ? { + ...content.mentions, + replied_user: content.mentions.repliedUser === true, + } + : undefined, + message_reference: content.replyMessageID, }, ); diff --git a/src/structures/message.ts b/src/structures/message.ts index 3c2fab5e5..7dd515a01 100644 --- a/src/structures/message.ts +++ b/src/structures/message.ts @@ -11,11 +11,14 @@ export async function createMessage(data: MessageCreateOptions) { webhook_id: webhookID, message_reference: messageReference, edited_timestamp: editedTimestamp, + referenced_message: referencedMessageID, ...rest } = data; const message = { ...rest, + /** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */ + referencedMessageID, channelID, guildID: guildID || "", mentions: data.mentions.map((m) => m.id), diff --git a/src/types/channel.ts b/src/types/channel.ts index d81d8c810..a58f1d381 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -101,6 +101,8 @@ export interface MessageContent { roles?: string[]; /** Array of user_ids to mention (Max size of 100) */ users?: string[]; + /** Should the message author from the original message be mention. By default this is false. */ + repliedUser?: boolean; }; /** The message contents, up to 2000 characters */ content?: string; @@ -114,6 +116,8 @@ export interface MessageContent { embed?: Embed; /** JSON encoded body of any additional request fields. */ payload_json?: string; + /** If you want to send a reply message, provide the original message id here */ + replyMessageID?: string; } export interface GetMessages { diff --git a/src/types/message.ts b/src/types/message.ts index 1e631d3cc..18c774be0 100644 --- a/src/types/message.ts +++ b/src/types/message.ts @@ -154,6 +154,11 @@ export enum MessageTypes { USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_2, USER_PREMIUM_GUILD_SUBSCRIPTION_TIER_3, CHANNEL_FOLLOW_ADD, + GUILD_DISCOVERY_DISQUALIFIED = 14, + GUILD_DISCOVERY_REQUALIFIED, + GUILD_DISCOVERY_GRACE_PERIOD_INITIAL_WARNING, + GUILD_DISCOVERY_GRACE_PERIOD_FINAL_WARNING, + REPLY = 19, } export enum ActivityTypes { @@ -275,6 +280,8 @@ export interface MessageCreateOptions { message_reference?: Reference; /** The message flags combined like permission bits describe extra features of the message */ flags?: 1 | 2 | 4 | 8 | 16; + /** The message id of the original message if this message was sent as a reply. If null, the original message was deleted. */ + referenced_message?: MessageCreateOptions | null; } export interface BaseMessageDeletePayload {