mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
fix: channel mentions includes all valid mentions
This commit is contained in:
+33
-25
@@ -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,19 +61,20 @@ const baseMessage: Partial<Message> = {
|
||||
return addReactions(this.channelId!, this.id!, reactions, ordered);
|
||||
},
|
||||
reply(content) {
|
||||
const contentWithMention = typeof content === "string"
|
||||
? {
|
||||
content,
|
||||
mentions: { repliedUser: true },
|
||||
replyMessageId: this.id,
|
||||
failReplyIfNotExists: false,
|
||||
}
|
||||
: {
|
||||
...content,
|
||||
mentions: { ...(content.mentions || {}), repliedUser: true },
|
||||
replyMessageId: this.id,
|
||||
failReplyIfNotExists: content.failReplyIfNotExists === true,
|
||||
};
|
||||
const contentWithMention =
|
||||
typeof content === "string"
|
||||
? {
|
||||
content,
|
||||
mentions: { repliedUser: true },
|
||||
replyMessageId: this.id,
|
||||
failReplyIfNotExists: false,
|
||||
}
|
||||
: {
|
||||
...content,
|
||||
mentions: { ...(content.mentions || {}), repliedUser: true },
|
||||
replyMessageId: this.id,
|
||||
failReplyIfNotExists: content.failReplyIfNotExists === true,
|
||||
};
|
||||
|
||||
if (this.guildId) return sendMessage(this.channelId!, contentWithMention);
|
||||
return sendDirectMessage(this.author!.id, contentWithMention);
|
||||
@@ -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
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
@@ -177,3 +177,4 @@ export const endpoints = {
|
||||
};
|
||||
|
||||
export const SLASH_COMMANDS_NAME_REGEX = /^[\w-]{1,32}$/;
|
||||
export const CHANNEL_MENTION_REGEX = /<#[0-9]+>/g;
|
||||
Reference in New Issue
Block a user