From 052479f3aff60dc30725b91c05a30d185f0bd98a Mon Sep 17 00:00:00 2001 From: almeidx Date: Sun, 29 Aug 2021 15:51:30 +0100 Subject: [PATCH] fix type errors --- backend/src/plugins/Logs/util/log.ts | 24 +++++++++++------------- backend/src/utils.ts | 4 ++-- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/backend/src/plugins/Logs/util/log.ts b/backend/src/plugins/Logs/util/log.ts index 3d697b0c..9092dfa9 100644 --- a/backend/src/plugins/Logs/util/log.ts +++ b/backend/src/plugins/Logs/util/log.ts @@ -98,36 +98,34 @@ export async function log( setTimeout(async () => { const batch = pluginData.state.batches.get(channel.id); if (!batch) return; + const chunks: ParsedMessageType[] = []; - // this is gonna be messy, i dont know how to write this algo any cleaner, sorry for (const msg of batch) { if (typeof msg === "string") { - // check if our latest log is still a string, if not, we need to make a new one + // check if the latest chunk is a string, if not, make it one if (typeof chunks[chunks.length - 1] === "string") { chunks[chunks.length - 1] += `\n${msg}`; } else { chunks.push(msg); } } else { - const embedMsg: MessageEmbed[] | undefined = msg.embeds; // wtb fix - const lastEntry: MessageOptions | undefined = chunks[chunks.length - 1]; // wtb fix + const msgEmbeds = msg.embeds; + const lastEntry = chunks[chunks.length - 1]; - if (!embedMsg || embedMsg.length === 0) continue; - // check if our latest log is still a embed, if not, we need to make a new one - if (lastEntry && lastEntry.embeds && typeof lastEntry !== "string") { - // @ts-ignore - chunks[chunks.length - 1].embeds.push(...embedMsg); // wtb fix + if (!msgEmbeds || msgEmbeds.length === 0) continue; + // check if the latest chunk is an embed, if not, make it one + if (typeof lastEntry !== "string" && lastEntry.embeds) { + (chunks[chunks.length - 1] as MessageOptions).embeds!.push(...msgEmbeds); } else { - chunks.push({ embeds: embedMsg }); + chunks.push({ embeds: msgEmbeds }); } } } for (const chunk of chunks) { if (typeof chunk === "string") { await createChunkedMessage(channel, chunk, { parse }); - } else { - // @ts-ignore - await createChunkedEmbedMessage(channel, chunk.embeds, { parse }); // wtb fix + } else if (chunk.embeds) { + await createChunkedEmbedMessage(channel, chunk.embeds, { parse }); } } diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 97e0bdbb..af4f7cd0 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -1014,11 +1014,11 @@ export async function createChunkedMessage( export async function createChunkedEmbedMessage( channel: TextChannel | ThreadChannel | User, - messageEmbeds: MessageEmbed[], + messageEmbeds: Array, allowedMentions?: MessageMentionOptions, maxChunkLength = 10, ) { - const chunks = chunkArray(messageEmbeds, maxChunkLength); + const chunks = chunkArray(messageEmbeds, maxChunkLength); for (const chunk of chunks) { await channel.send({ embeds: chunk, allowedMentions }); }