3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-21 16:55:03 +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 () => {
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 = <any>msg.embeds; // wtb fix
const lastEntry: MessageOptions | undefined = <any>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 });
}
}

View file

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