mirror of
https://github.com/spacebarchat/server.git
synced 2026-05-14 20:35:17 +00:00
Add some optional chaining to prevent issue with embeds
This commit is contained in:
@@ -502,14 +502,13 @@ export async function postHandleMessage(message: Message) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
data.embeds.forEach((embed) => {
|
||||
data.embeds?.forEach((embed) => {
|
||||
if (!embed.type) {
|
||||
embed.type = EmbedType.rich;
|
||||
}
|
||||
});
|
||||
// Filter out embeds that could be links, start from scratch
|
||||
data.embeds = data.embeds.filter((embed) => embed.type === "rich");
|
||||
data.embeds = data.embeds?.filter((embed) => embed.type === "rich");
|
||||
|
||||
const seenNormalizedUrls = new Set<string>();
|
||||
const uniqueLinks: string[] = [];
|
||||
@@ -534,7 +533,7 @@ export async function postHandleMessage(message: Message) {
|
||||
|
||||
if (uniqueLinks.length === 0) {
|
||||
// No valid unique links found, update message to remove old embeds
|
||||
data.embeds = data.embeds.filter((embed) => embed.type === "rich");
|
||||
data.embeds = data.embeds?.filter((embed) => embed.type === "rich");
|
||||
const author = data.author?.toPublicUser();
|
||||
const event = {
|
||||
event: "MESSAGE_UPDATE",
|
||||
@@ -567,7 +566,7 @@ export async function postHandleMessage(message: Message) {
|
||||
});
|
||||
|
||||
if (cached) {
|
||||
data.embeds.push(cached.embed);
|
||||
data.embeds?.push(cached.embed);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -588,7 +587,7 @@ export async function postHandleMessage(message: Message) {
|
||||
embed: embed,
|
||||
});
|
||||
cachePromises.push(cache.save());
|
||||
data.embeds.push(embed);
|
||||
data.embeds?.push(embed);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[Embeds] Error while generating embed for ${link}`, e);
|
||||
|
||||
Reference in New Issue
Block a user