fix: channel mentions includes all valid mentions

This commit is contained in:
Skillz4Killz
2021-04-04 03:23:26 +00:00
committed by GitHub
parent cc46698245
commit 210f89ec4e
2 changed files with 34 additions and 25 deletions
+21 -13
View File
@@ -9,6 +9,7 @@ import { removeAllReactions } from "../helpers/messages/remove_all_reactions.ts"
import { removeReaction } from "../helpers/messages/remove_reaction.ts";
import { removeReactionEmoji } from "../helpers/messages/remove_reaction_emoji.ts";
import { sendMessage } from "../helpers/messages/send_message.ts";
import { CHANNEL_MENTION_REGEX } from "../util/constants";
import { createNewProp } from "../util/utils.ts";
const baseMessage: Partial<Message> = {
@@ -29,8 +30,9 @@ const baseMessage: Partial<Message> = {
return this.member?.guilds.get(this.guildId);
},
get link() {
return `https://discord.com/channels/${this.guildId ||
"@me"}/${this.channelId}/${this.id}`;
return `https://discord.com/channels/${this.guildId || "@me"}/${
this.channelId
}/${this.id}`;
},
get mentionedRoles() {
return this.mentionRoleIds?.map((id) => this.guild?.roles.get(id)) || [];
@@ -44,12 +46,7 @@ const baseMessage: Partial<Message> = {
// METHODS
delete(reason, delayMilliseconds) {
return deleteMessage(
this.channelId!,
this.id!,
reason,
delayMilliseconds,
);
return deleteMessage(this.channelId!, this.id!, reason, delayMilliseconds);
},
edit(content) {
return editMessage(this as Message, content);
@@ -64,7 +61,8 @@ const baseMessage: Partial<Message> = {
return addReactions(this.channelId!, this.id!, reactions, ordered);
},
reply(content) {
const contentWithMention = typeof content === "string"
const contentWithMention =
typeof content === "string"
? {
content,
mentions: { repliedUser: true },
@@ -134,8 +132,8 @@ export async function createMessageStruct(data: MessageCreateOptions) {
}
// Discord doesnt give guild id for getMessage() so this will fill it in
const guildIdFinal = guildId ||
(await cacheHandlers.get("channels", channelId))?.guildId || "";
const guildIdFinal =
guildId || (await cacheHandlers.get("channels", channelId))?.guildId || "";
const message = Object.create(baseMessage, {
...restProps,
@@ -146,12 +144,22 @@ export async function createMessageStruct(data: MessageCreateOptions) {
mentions: createNewProp(data.mentions.map((m) => m.id)),
mentionsEveryone: createNewProp(mentionsEveryone),
mentionRoleIds: createNewProp(mentionRoleIds),
mentionChannelIds: createNewProp(mentionChannelIds.map((m) => m.id)),
mentionChannelIds: createNewProp(
[
// Keep any ids that discord sends
...mentionChannelIds,
// Add any other ids that can be validated in a channel mention format
...(rest.content.match(CHANNEL_MENTION_REGEX) || []).map((text) =>
// converts the <#123> into 123
text.substring(2, text.length - 1)
),
].map((m) => m.id)
),
webhookId: createNewProp(webhookId),
messageReference: createNewProp(messageReference),
timestamp: createNewProp(Date.parse(data.timestamp)),
editedTimestamp: createNewProp(
editedTimestamp ? Date.parse(editedTimestamp) : undefined,
editedTimestamp ? Date.parse(editedTimestamp) : undefined
),
});
+1
View File
@@ -177,3 +177,4 @@ export const endpoints = {
};
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;
export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g;