fedimbed: strip zwsp from bridge messages, only suppress embeds if flag isnt existing and after message creation

This commit is contained in:
Cynthia Foxwell 2023-01-05 21:20:31 -07:00
parent ce2e4fd397
commit 44779f7a23

View file

@ -503,32 +503,36 @@ async function processUrl(msg, url) {
} }
} }
// NB: OceanicJS/Oceanic#32 await msg.channel
//await msg.edit({flags: MessageFlags.SUPPRESS_EMBEDS}).catch(() => {}); .createMessage({
await hf.bot.rest content:
.authRequest({ cw && (images.length > 0 || videos.length > 0 || audios.length > 0)
method: "PATCH", ? `:warning: ${cw} || ${url} ||`
path: Routes.CHANNEL_MESSAGE(msg.channel.id, msg.id), : "",
json: { embeds,
flags: MessageFlags.SUPPRESS_EMBEDS, files,
allowedMentions: {
repliedUser: false,
},
messageReference: {
messageID: msg.id,
}, },
}) })
.catch(() => {}); .then(() => {
if ((msg.flags & MessageFlags.SUPPRESS_EMBEDS) === 0) {
await msg.channel.createMessage({ // NB: OceanicJS/Oceanic#32
content: //msg.edit({flags: MessageFlags.SUPPRESS_EMBEDS}).catch(() => {});
cw && (images.length > 0 || videos.length > 0 || audios.length > 0) hf.bot.rest
? `:warning: ${cw} || ${url} ||` .authRequest({
: "", method: "PATCH",
embeds, path: Routes.CHANNEL_MESSAGE(msg.channel.id, msg.id),
files, json: {
allowedMentions: { flags: MessageFlags.SUPPRESS_EMBEDS,
repliedUser: false, },
}, })
messageReference: { .catch(() => {});
messageID: msg.id, }
}, });
});
} }
events.add("messageCreate", "fedimbed", async function (msg) { events.add("messageCreate", "fedimbed", async function (msg) {
@ -540,7 +544,7 @@ events.add("messageCreate", "fedimbed", async function (msg) {
if (URLS_REGEX.test(msg.content)) { if (URLS_REGEX.test(msg.content)) {
const urls = msg.content.match(URLS_REGEX); const urls = msg.content.match(URLS_REGEX);
for (let url of urls) { for (let url of urls) {
url = url.trim(); url = url.trim().replace("@\u200b", "@").replace("@%E2%80%8B", "@");
for (const service of Object.keys(PATH_REGEX)) { for (const service of Object.keys(PATH_REGEX)) {
const regex = PATH_REGEX[service]; const regex = PATH_REGEX[service];
const urlObj = new URL(url); const urlObj = new URL(url);