3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-23 09:35:02 +00:00

Merge pull request #4 from almeidx/types

fix type errors
This commit is contained in:
metal 2021-08-29 16:03:52 +01:00 committed by GitHub
commit 098e57c645
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View file

@ -98,36 +98,34 @@ export async function log<TLogType extends keyof ILogTypeData>(
setTimeout(async () => { setTimeout(async () => {
const batch = pluginData.state.batches.get(channel.id); const batch = pluginData.state.batches.get(channel.id);
if (!batch) return; if (!batch) return;
const chunks: ParsedMessageType[] = []; const chunks: ParsedMessageType[] = [];
// this is gonna be messy, i dont know how to write this algo any cleaner, sorry
for (const msg of batch) { for (const msg of batch) {
if (typeof msg === "string") { 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") { if (typeof chunks[chunks.length - 1] === "string") {
chunks[chunks.length - 1] += `\n${msg}`; chunks[chunks.length - 1] += `\n${msg}`;
} else { } else {
chunks.push(msg); chunks.push(msg);
} }
} else { } else {
const embedMsg: MessageEmbed[] | undefined = <any>msg.embeds; // wtb fix const msgEmbeds = msg.embeds;
const lastEntry: MessageOptions | undefined = <any>chunks[chunks.length - 1]; // wtb fix const lastEntry = chunks[chunks.length - 1];
if (!embedMsg || embedMsg.length === 0) continue; if (!msgEmbeds || msgEmbeds.length === 0) continue;
// check if our latest log is still a embed, if not, we need to make a new one // check if the latest chunk is an embed, if not, make it one
if (lastEntry && lastEntry.embeds && typeof lastEntry !== "string") { if (typeof lastEntry !== "string" && lastEntry.embeds) {
// @ts-ignore (chunks[chunks.length - 1] as MessageOptions).embeds!.push(...msgEmbeds);
chunks[chunks.length - 1].embeds.push(...embedMsg); // wtb fix
} else { } else {
chunks.push({ embeds: embedMsg }); chunks.push({ embeds: msgEmbeds });
} }
} }
} }
for (const chunk of chunks) { for (const chunk of chunks) {
if (typeof chunk === "string") { if (typeof chunk === "string") {
await createChunkedMessage(channel, chunk, { parse }); await createChunkedMessage(channel, chunk, { parse });
} else { } else if (chunk.embeds) {
// @ts-ignore await createChunkedEmbedMessage(channel, chunk.embeds, { parse });
await createChunkedEmbedMessage(channel, chunk.embeds, { parse }); // wtb fix
} }
} }

View file

@ -1014,11 +1014,11 @@ export async function createChunkedMessage(
export async function createChunkedEmbedMessage( export async function createChunkedEmbedMessage(
channel: TextChannel | ThreadChannel | User, channel: TextChannel | ThreadChannel | User,
messageEmbeds: MessageEmbed[], messageEmbeds: Array<MessageEmbed | MessageEmbedOptions>,
allowedMentions?: MessageMentionOptions, allowedMentions?: MessageMentionOptions,
maxChunkLength = 10, maxChunkLength = 10,
) { ) {
const chunks = chunkArray<MessageEmbed>(messageEmbeds, maxChunkLength); const chunks = chunkArray(messageEmbeds, maxChunkLength);
for (const chunk of chunks) { for (const chunk of chunks) {
await channel.send({ embeds: chunk, allowedMentions }); await channel.send({ embeds: chunk, allowedMentions });
} }