MessageBuffer: take embed length into account
This commit is contained in:
parent
bd87e1f000
commit
a26eaa480c
2 changed files with 29 additions and 2 deletions
17
backend/src/utils/calculateEmbedSize.ts
Normal file
17
backend/src/utils/calculateEmbedSize.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { MessageEmbedOptions } from "discord.js";
|
||||
|
||||
function sumStringLengthsRecursively(obj: any): number {
|
||||
if (obj == null) return 0;
|
||||
if (typeof obj === "string") return obj.length;
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.reduce((sum, item) => sum + sumStringLengthsRecursively(item), 0);
|
||||
}
|
||||
if (typeof obj === "object") {
|
||||
return Array.from(Object.values(obj)).reduce((sum: number, item) => sum + sumStringLengthsRecursively(item), 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function calculateEmbedSize(embed: MessageEmbedOptions): number {
|
||||
return sumStringLengthsRecursively(embed);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue