Include attachment count in fedi previews
This commit is contained in:
parent
225862a401
commit
497a8dc2b7
1 changed files with 8 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
This module takes misskey links (e.g.) and provides a preview in a reply.
|
||||
This module takes fediverse links (e.g.) and provides a preview in a reply.
|
||||
"""
|
||||
import logging
|
||||
import niobot
|
||||
|
@ -11,15 +11,15 @@ if typing.TYPE_CHECKING:
|
|||
from ..main import TortoiseIntegratedBot
|
||||
|
||||
|
||||
class MisskeyPreviewModule(niobot.Module):
|
||||
class FediversePreviewModule(niobot.Module):
|
||||
bot: "TortoiseIntegratedBot"
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@niobot.event("message")
|
||||
async def on_message(self, room: niobot.MatrixRoom, event: niobot.RoomMessage):
|
||||
supported_prefixes = self.bot.cfg.get("misskey_preview", {})
|
||||
supported_prefixes = self.bot.cfg.get("fediverse_preview")
|
||||
supported_prefixes = supported_prefixes.get("urls", ["https://fedi.transgender.ing"])
|
||||
ignore = self.bot.cfg.get("misskey_preview", {}).get("ignore", [])
|
||||
ignore = supported_prefixes.get("ignore", [])
|
||||
if not isinstance(event, niobot.RoomMessageText):
|
||||
return
|
||||
if event.sender in ignore or room.room_id in ignore or event.sender == self.bot.user_id:
|
||||
|
@ -51,7 +51,7 @@ class MisskeyPreviewModule(niobot.Module):
|
|||
self.log.warning("No text for post %s", post_id)
|
||||
continue
|
||||
|
||||
self.log.info("Detected misskey post %s: %r", post_id, text)
|
||||
self.log.info("Detected fediverse post %s: %r", post_id, text)
|
||||
rendered = await self.bot._markdown_to_html(text)
|
||||
text_body = "<blockquote>%s</blockquote>" % rendered
|
||||
body = "<a href=\"%s\">@%s:</a><br>%s" % (
|
||||
|
@ -59,7 +59,9 @@ class MisskeyPreviewModule(niobot.Module):
|
|||
username,
|
||||
text_body,
|
||||
)
|
||||
self.log.info("Sending misskey post %s", post_id)
|
||||
if data.get("media_attachments"):
|
||||
body += "<p>{:,} attachments</p>".format(len(data["media_attachments"]))
|
||||
self.log.info("Sending fediverse post %s", post_id)
|
||||
await self.bot.send_message(
|
||||
room,
|
||||
body,
|
Loading…
Reference in a new issue