3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Improve empty message detection when rendering tags

This commit is contained in:
Dragory 2020-12-23 02:27:45 +02:00
parent 3def728ab5
commit ff98670cf5
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 43 additions and 5 deletions

View file

@ -0,0 +1,35 @@
import { MessageContent } from "eris";
function embedHasContent(embed: any) {
for (const [key, value] of Object.entries(embed)) {
if (typeof value === "string" && value.trim() !== "") {
return true;
}
if (typeof value === "object" && value != null && embedHasContent(value)) {
return true;
}
if (value != null) {
return true;
}
}
return false;
}
export function messageHasContent(content: MessageContent): boolean {
if (typeof content === "string") {
return content.trim() !== "";
}
if (content.content != null && content.content.trim() !== "") {
return true;
}
if (content.embed && embedHasContent(content.embed)) {
return true;
}
return false;
}

View file

@ -0,0 +1,6 @@
import { MessageContent } from "eris";
import { messageHasContent } from "./messageHasContent";
export function messageIsEmpty(content: MessageContent): boolean {
return !messageHasContent(content);
}