forked from kate/uniborg
Move aesthetics functionality into markdown
This commit is contained in:
parent
def5d5d651
commit
f0e7d16276
|
@ -1,26 +0,0 @@
|
|||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
from telethon import events
|
||||
|
||||
PRINTABLE_ASCII = range(0x21, 0x7f)
|
||||
|
||||
|
||||
def aesthetify(string):
|
||||
for c in string:
|
||||
c = ord(c)
|
||||
if c in PRINTABLE_ASCII:
|
||||
c += 0xFF00 - 0x20
|
||||
elif c == ord(" "):
|
||||
c = 0x3000
|
||||
yield chr(c)
|
||||
|
||||
|
||||
@borg.on(events.NewMessage(pattern=r'\.ae\s+(.+)', outgoing=True))
|
||||
@borg.on(events.MessageEdited(pattern=r'\.ae\s+(.+)', outgoing=True))
|
||||
async def _(event):
|
||||
text = event.pattern_match.group(1)
|
||||
text = "".join(aesthetify(text))
|
||||
await event.edit(text=text, parse_mode=None, link_preview=False)
|
||||
raise events.StopPropagation
|
|
@ -32,6 +32,19 @@ def get_tag_parser(tag, entity):
|
|||
return re.compile(tag + r'(.+?)' + tag, re.DOTALL), tag_parser
|
||||
|
||||
|
||||
PRINTABLE_ASCII = range(0x21, 0x7f)
|
||||
def parse_aesthetics(m):
|
||||
def aesthetify(string):
|
||||
for c in string:
|
||||
c = ord(c)
|
||||
if c in PRINTABLE_ASCII:
|
||||
c += 0xFF00 - 0x20
|
||||
elif c == ord(" "):
|
||||
c = 0x3000
|
||||
yield chr(c)
|
||||
return "".join(aesthetify(m[1])), None
|
||||
|
||||
|
||||
def parse_subreddit(m):
|
||||
text = '/' + m.group(3)
|
||||
entity = MessageEntityTextUrl(
|
||||
|
@ -65,6 +78,7 @@ MATCHERS = [
|
|||
(get_tag_parser('__', MessageEntityItalic)),
|
||||
(get_tag_parser('```', partial(MessageEntityPre, language=''))),
|
||||
(get_tag_parser('`', MessageEntityCode)),
|
||||
(re.compile(r'\+\+(.+?)\+\+'), parse_aesthetics),
|
||||
(re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit),
|
||||
(re.compile(r'(!\w+)'), parse_snip)
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue