Exemple #1
0
    async def send_welcome_message(self, room_id: RoomID, inviter: br.BaseUser) -> None:
        has_two_members, bridge_bot_in_room = await self._is_direct_chat(room_id)
        is_management = has_two_members and bridge_bot_in_room

        welcome_messages = [self.management_room_text.get("welcome")]

        if is_management:
            if await inviter.is_logged_in():
                welcome_messages.append(self.management_room_text.get("welcome_connected"))
            else:
                welcome_messages.append(self.management_room_text.get("welcome_unconnected"))

            additional_help = self.management_room_text.get("additional_help")
            if additional_help:
                welcome_messages.append(additional_help)
        else:
            cmd_prefix = self.commands.command_prefix
            welcome_messages.append(f"Use `{cmd_prefix} help` for help.")

        if self.management_room_multiple_messages:
            for m in welcome_messages:
                await self.az.intent.send_notice(room_id, text=m, html=markdown.render(m))
        else:
            combined = "\n".join(welcome_messages)
            combined_html = "".join(map(markdown.render, welcome_messages))
            await self.az.intent.send_notice(room_id, text=combined, html=combined_html)
Exemple #2
0
 async def _edit(self, room_id: RoomID, event_id: EventID,
                 text: str) -> None:
     content = TextMessageEventContent(msgtype=MessageType.NOTICE,
                                       body=text,
                                       format=Format.HTML,
                                       formatted_body=markdown.render(text))
     content.set_edit(event_id)
     await self.client.send_message(room_id, content)
Exemple #3
0
def parse_formatted(message: str,
                    allow_html: bool = False,
                    render_markdown: bool = True) -> Tuple[str, str]:
    if render_markdown:
        html = markdown.render(message, allow_html=allow_html)
    elif allow_html:
        html = message
    else:
        return message, escape(message)
    return parse_html(html), html
Exemple #4
0
async def parse_formatted(
    message: str, allow_html: bool = False, render_markdown: bool = True
) -> tuple[str, str]:
    if render_markdown:
        html = markdown.render(message, allow_html=allow_html)
    elif allow_html:
        html = message
    else:
        return message, escape(message)
    return (await MaubotHTMLParser().parse(html)).text, html
Exemple #5
0
    def _render_message(message: str, allow_html: bool,
                        render_markdown: bool) -> str | None:
        """Renders the message as HTML.

        Args:
            allow_html: Flag to allow custom HTML in the message.
            render_markdown: If true, markdown styling is applied to the message.

        Returns:
            The message rendered as HTML.
            None is returned if no styled output is required.
        """
        html = ""
        if render_markdown:
            html = markdown.render(message, allow_html=allow_html)
        elif allow_html:
            html = message
        return ensure_trailing_newline(html) if html else None