Fix batched logs not being separated by newlines
This commit is contained in:
parent
2128b1a089
commit
f733f081e0
2 changed files with 13 additions and 2 deletions
|
@ -102,6 +102,7 @@ export async function log<TLogType extends keyof ILogTypeData>(
|
||||||
channelId,
|
channelId,
|
||||||
new MessageBuffer({
|
new MessageBuffer({
|
||||||
timeout: batchTime,
|
timeout: batchTime,
|
||||||
|
textSeparator: "\n",
|
||||||
consume: (part) => {
|
consume: (part) => {
|
||||||
const parse: MessageMentionTypes[] = pluginData.config.get().allow_user_mentions ? ["users"] : [];
|
const parse: MessageMentionTypes[] = pluginData.config.get().allow_user_mentions ? ["users"] : [];
|
||||||
const promise =
|
const promise =
|
||||||
|
|
|
@ -16,6 +16,7 @@ type Chunk = {
|
||||||
export interface MessageBufferOpts {
|
export interface MessageBufferOpts {
|
||||||
consume?: ConsumeFn;
|
consume?: ConsumeFn;
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
|
textSeparator?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_CHARS_PER_MESSAGE = 2000;
|
const MAX_CHARS_PER_MESSAGE = 2000;
|
||||||
|
@ -30,6 +31,8 @@ export class MessageBuffer {
|
||||||
|
|
||||||
protected timeoutMs: number | null = null;
|
protected timeoutMs: number | null = null;
|
||||||
|
|
||||||
|
protected textSeparator: string = "";
|
||||||
|
|
||||||
protected chunk: Chunk | null = null;
|
protected chunk: Chunk | null = null;
|
||||||
|
|
||||||
protected chunkTimeout: Timeout | null = null;
|
protected chunkTimeout: Timeout | null = null;
|
||||||
|
@ -44,6 +47,10 @@ export class MessageBuffer {
|
||||||
if (opts.timeout) {
|
if (opts.timeout) {
|
||||||
this.timeoutMs = opts.timeout;
|
this.timeoutMs = opts.timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.textSeparator) {
|
||||||
|
this.textSeparator = opts.textSeparator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push(content: MessageBufferContent): void {
|
push(content: MessageBufferContent): void {
|
||||||
|
@ -73,8 +80,11 @@ export class MessageBuffer {
|
||||||
this.startNewChunk(contentType);
|
this.startNewChunk(contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chunk.content.content == null) chunk.content.content = "";
|
if (chunk.content.content == null || chunk.content.content === "") {
|
||||||
chunk.content.content += content.content;
|
chunk.content.content = content.content;
|
||||||
|
} else {
|
||||||
|
chunk.content.content += this.textSeparator + content.content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.embeds) {
|
if (content.embeds) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue