Don't allow newlines in short content

This commit is contained in:
Tulir Asokan 2018-10-27 01:50:33 +03:00
parent 27fe50d65c
commit fbc6ece5cf
1 changed files with 7 additions and 4 deletions

View File

@ -108,11 +108,14 @@ class KarmaBot(Plugin):
def parse_content(self, evt: Event) -> str:
if isinstance(evt, MessageEvent):
if evt.content.msgtype in (MessageType.NOTICE, MessageType.TEXT, MessageType.EMOTE):
body = evt.content.body
if evt.content.msgtype == MessageType.EMOTE:
evt.content.body = "/me " + evt.content.body
return (html.escape(evt.content.body[:50]) + " \u2026"
if len(evt.content.body) > 60
else html.escape(evt.content.body))
body = "/me " + body
body = body.split("\n")[0]
if len(body) > 60:
body = body[:50] + " \u2026"
body = html.escape(body)
return body
name = media_reply_fallback_body_map[evt.content.msgtype]
return f"[{name}]({self.client.get_download_url(evt.content.url)})"
elif isinstance(evt, StateEvent):