diff --git a/hotdog/models.py b/hotdog/models.py index 89d937d..8142a0f 100644 --- a/hotdog/models.py +++ b/hotdog/models.py @@ -1,12 +1,13 @@ import asyncio from dataclasses import dataclass, field +from itertools import dropwhile from random import random from time import time as now from typing import * import nio -from .html import HtmlDocument, parse_html +from .html import HtmlDocument, detach, find, parse_html JobCallback = Callable[["Job"], None] @@ -106,6 +107,18 @@ class Message: else None ) + # Remove any "reply" preamble. + is_reply = plain.startswith("> <@") + if is_reply: + lines = dropwhile( + lambda l: l.startswith("> "), plain.splitlines(keepends=False) + ) + nextline = next(lines) + if nextline == "": + plain = "\n".join(lines) + if html and (reply := next(find(html, "mx-reply"), None)): + detach(reply) + self.text = plain self.html = html self.tokens = Tokens.from_str(plain)