use a proper markdown parser

This commit is contained in:
git-bruh 2021-06-28 15:18:59 +05:30
parent 30688bf5b0
commit d864b0cc44
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6
3 changed files with 4 additions and 17 deletions

View file

@ -1,4 +1,5 @@
from dataclasses import dataclass from dataclasses import dataclass
from misc import dict_cls from misc import dict_cls
CDN_URL = "https://cdn.discordapp.com" CDN_URL = "https://cdn.discordapp.com"

View file

@ -7,6 +7,7 @@ import sys
import threading import threading
from typing import Dict, List, Tuple from typing import Dict, List, Tuple
import markdown
import urllib3 import urllib3
import discord import discord
@ -281,23 +282,7 @@ In reply to</a><a href="https://matrix.to/#/{event.sender}">\
return content return content
def get_fmt(self, message: str, emotes: dict) -> str: def get_fmt(self, message: str, emotes: dict) -> str:
replace = [ message = markdown.markdown(message)
# Bold.
("**", "<strong>", "</strong>"),
# Code blocks.
("```", "<pre><code>", "</code></pre>"),
# Spoilers.
("||", "<span data-mx-spoiler>", "</span>"),
# Strikethrough.
("~~", "<del>", "</del>"),
]
for replace_ in replace:
for i in range(1, message.count(replace_[0]) + 1):
if i % 2:
message = message.replace(replace_[0], replace_[1], 1)
else:
message = message.replace(replace_[0], replace_[2], 1)
# Upload emotes in multiple threads so that we don't # Upload emotes in multiple threads so that we don't
# block the Discord bot for too long. # block the Discord bot for too long.

View file

@ -1,3 +1,4 @@
bottle bottle
markdown
urllib3 urllib3
websockets websockets