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 { 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,19 +61,20 @@ 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,
|
? {
|
||||||
mentions: { repliedUser: true },
|
content,
|
||||||
replyMessageId: this.id,
|
mentions: { repliedUser: true },
|
||||||
failReplyIfNotExists: false,
|
replyMessageId: this.id,
|
||||||
}
|
failReplyIfNotExists: false,
|
||||||
: {
|
}
|
||||||
...content,
|
: {
|
||||||
mentions: { ...(content.mentions || {}), repliedUser: true },
|
...content,
|
||||||
replyMessageId: this.id,
|
mentions: { ...(content.mentions || {}), repliedUser: true },
|
||||||
failReplyIfNotExists: content.failReplyIfNotExists === true,
|
replyMessageId: this.id,
|
||||||
};
|
failReplyIfNotExists: content.failReplyIfNotExists === true,
|
||||||
|
};
|
||||||
|
|
||||||
if (this.guildId) return sendMessage(this.channelId!, contentWithMention);
|
if (this.guildId) return sendMessage(this.channelId!, contentWithMention);
|
||||||
return sendDirectMessage(this.author!.id, 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
|
// 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
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user