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 { removeReaction } from "../helpers/messages/remove_reaction.ts";
import { removeReactionEmoji } from "../helpers/messages/remove_reaction_emoji.ts"; import { removeReactionEmoji } from "../helpers/messages/remove_reaction_emoji.ts";
import { sendMessage } from "../helpers/messages/send_message.ts"; import { sendMessage } from "../helpers/messages/send_message.ts";
import { CHANNEL_MENTION_REGEX } from "../util/constants";
import { createNewProp } from "../util/utils.ts"; import { createNewProp } from "../util/utils.ts";
const baseMessage: Partial<Message> = { const baseMessage: Partial<Message> = {
@@ -29,8 +30,9 @@ const baseMessage: Partial<Message> = {
return this.member?.guilds.get(this.guildId); return this.member?.guilds.get(this.guildId);
}, },
get link() { get link() {
return `https://discord.com/channels/${this.guildId || return `https://discord.com/channels/${this.guildId || "@me"}/${
"@me"}/${this.channelId}/${this.id}`; this.channelId
}/${this.id}`;
}, },
get mentionedRoles() { get mentionedRoles() {
return this.mentionRoleIds?.map((id) => this.guild?.roles.get(id)) || []; return this.mentionRoleIds?.map((id) => this.guild?.roles.get(id)) || [];
@@ -44,12 +46,7 @@ const baseMessage: Partial<Message> = {
// METHODS // METHODS
delete(reason, delayMilliseconds) { delete(reason, delayMilliseconds) {
return deleteMessage( return deleteMessage(this.channelId!, this.id!, reason, delayMilliseconds);
this.channelId!,
this.id!,
reason,
delayMilliseconds,
);
}, },
edit(content) { edit(content) {
return editMessage(this as Message, content); return editMessage(this as Message, content);
@@ -64,7 +61,8 @@ const baseMessage: Partial<Message> = {
return addReactions(this.channelId!, this.id!, reactions, ordered); return addReactions(this.channelId!, this.id!, reactions, ordered);
}, },
reply(content) { reply(content) {
const contentWithMention = typeof content === "string" const contentWithMention =
typeof content === "string"
? { ? {
content, content,
mentions: { repliedUser: true }, 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 // Discord doesnt give guild id for getMessage() so this will fill it in
const guildIdFinal = guildId || const guildIdFinal =
(await cacheHandlers.get("channels", channelId))?.guildId || ""; guildId || (await cacheHandlers.get("channels", channelId))?.guildId || "";
const message = Object.create(baseMessage, { const message = Object.create(baseMessage, {
...restProps, ...restProps,
@@ -146,12 +144,22 @@ export async function createMessageStruct(data: MessageCreateOptions) {
mentions: createNewProp(data.mentions.map((m) => m.id)), mentions: createNewProp(data.mentions.map((m) => m.id)),
mentionsEveryone: createNewProp(mentionsEveryone), mentionsEveryone: createNewProp(mentionsEveryone),
mentionRoleIds: createNewProp(mentionRoleIds), 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), webhookId: createNewProp(webhookId),
messageReference: createNewProp(messageReference), messageReference: createNewProp(messageReference),
timestamp: createNewProp(Date.parse(data.timestamp)), timestamp: createNewProp(Date.parse(data.timestamp)),
editedTimestamp: createNewProp( 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 SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;
export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g;