mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Escape RoyalCode in Matrix messages
This commit is contained in:
parent
2fa90fc4e0
commit
1633ff006c
4 changed files with 21 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
from .matrixserf import MatrixSerf
|
||||
from .escape import escape
|
||||
|
||||
__all__ = [
|
||||
"MatrixSerf",
|
||||
"escape",
|
||||
]
|
15
royalnet/serf/matrix/escape.py
Normal file
15
royalnet/serf/matrix/escape.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
def escape(string: str) -> str:
|
||||
"""Escape a string to be sent through Matrix, and format it using RoyalCode.
|
||||
|
||||
Underlines are currently unsupported.
|
||||
|
||||
Warning:
|
||||
Currently escapes everything, even items in code blocks."""
|
||||
return string.replace("[b]", "**") \
|
||||
.replace("[/b]", "**") \
|
||||
.replace("[i]", "_") \
|
||||
.replace("[/i]", "_") \
|
||||
.replace("[c]", "`") \
|
||||
.replace("[/c]", "`") \
|
||||
.replace("[p]", "```") \
|
||||
.replace("[/p]", "```")
|
|
@ -6,6 +6,7 @@ import royalnet.backpack as rb
|
|||
import royalnet.commands as rc
|
||||
import royalnet.utils as ru
|
||||
from ..serf import Serf
|
||||
from .escape import escape
|
||||
|
||||
|
||||
try:
|
||||
|
@ -77,7 +78,7 @@ class MatrixSerf(Serf):
|
|||
async def reply(data, text: str):
|
||||
await self.client.room_send(room_id=data.room.room_id, message_type="m.room.message", content={
|
||||
"msgtype": "m.text",
|
||||
"body": text
|
||||
"body": escape(text)
|
||||
})
|
||||
|
||||
async def get_author(data, error_if_none=False):
|
||||
|
|
|
@ -1 +1 @@
|
|||
semantic = "5.2.1"
|
||||
semantic = "5.2.2"
|
||||
|
|
Loading…
Reference in a new issue