mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 16:55:03 +00:00
commit
098e57c645
2 changed files with 13 additions and 15 deletions
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue