forked from uniborg/uniborg
Compare commits
No commits in common. "a254c113a70e21c9498dbad7646eddf7414002a0" and "c35dcbf26d302db9903956af10e5578ee8871468" have entirely different histories.
a254c113a7
...
c35dcbf26d
|
@ -31,22 +31,19 @@ def get_tag_parser(tag, entity):
|
||||||
return re.compile(tag + r'(.+?)' + tag, re.DOTALL), tag_parser
|
return re.compile(tag + r'(.+?)' + tag, re.DOTALL), tag_parser
|
||||||
|
|
||||||
|
|
||||||
|
PRINTABLE_ASCII = range(0x21, 0x7f)
|
||||||
def parse_aesthetics(m):
|
def parse_aesthetics(m):
|
||||||
def aesthetify(string):
|
def aesthetify(string):
|
||||||
for c in string:
|
for c in string:
|
||||||
if " " < c <= "~":
|
c = ord(c)
|
||||||
yield chr(ord(c) + 0xFF00 - 0x20)
|
if c in PRINTABLE_ASCII:
|
||||||
elif c == " ":
|
c += 0xFF00 - 0x20
|
||||||
yield "\u3000"
|
elif c == ord(" "):
|
||||||
else:
|
c = 0x3000
|
||||||
yield c
|
yield chr(c)
|
||||||
return "".join(aesthetify(m[1])), None
|
return "".join(aesthetify(m[1])), None
|
||||||
|
|
||||||
|
|
||||||
def parse_strikethrough(m):
|
|
||||||
return ("\u0336".join(m[1]) + "\u0336"), None
|
|
||||||
|
|
||||||
|
|
||||||
def parse_subreddit(m):
|
def parse_subreddit(m):
|
||||||
text = '/' + m.group(3)
|
text = '/' + m.group(3)
|
||||||
entity = MessageEntityTextUrl(
|
entity = MessageEntityTextUrl(
|
||||||
|
@ -81,7 +78,6 @@ MATCHERS = [
|
||||||
(get_tag_parser('```', partial(MessageEntityPre, language=''))),
|
(get_tag_parser('```', partial(MessageEntityPre, language=''))),
|
||||||
(get_tag_parser('`', MessageEntityCode)),
|
(get_tag_parser('`', MessageEntityCode)),
|
||||||
(re.compile(r'\+\+(.+?)\+\+'), parse_aesthetics),
|
(re.compile(r'\+\+(.+?)\+\+'), parse_aesthetics),
|
||||||
(re.compile(r'~~(.+?)~~'), parse_strikethrough),
|
|
||||||
(re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit),
|
(re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit),
|
||||||
(re.compile(r'(!\w+)'), parse_snip)
|
(re.compile(r'(!\w+)'), parse_snip)
|
||||||
]
|
]
|
||||||
|
@ -102,8 +98,6 @@ def parse(message, old_entities=None):
|
||||||
# Skip already existing entities if we're at one
|
# Skip already existing entities if we're at one
|
||||||
if i == e.offset:
|
if i == e.offset:
|
||||||
i += e.length
|
i += e.length
|
||||||
else:
|
|
||||||
after += 1
|
|
||||||
|
|
||||||
# Find the first pattern that matches
|
# Find the first pattern that matches
|
||||||
for pattern, parser in MATCHERS:
|
for pattern, parser in MATCHERS:
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from telethon import events
|
from telethon import events
|
||||||
from telethon.tl.types import InputPeerSelf
|
|
||||||
import telethon.utils
|
import telethon.utils
|
||||||
|
|
||||||
from uniborg import util
|
from uniborg import util
|
||||||
|
@ -21,8 +20,6 @@ async def get_target_message(event):
|
||||||
|
|
||||||
|
|
||||||
async def await_read(chat, message):
|
async def await_read(chat, message):
|
||||||
if isinstance(chat, InputPeerSelf):
|
|
||||||
return
|
|
||||||
chat = telethon.utils.get_peer_id(chat)
|
chat = telethon.utils.get_peer_id(chat)
|
||||||
|
|
||||||
async def read_filter(read_event):
|
async def read_filter(read_event):
|
||||||
|
|
|
@ -22,6 +22,6 @@ async def _(event):
|
||||||
who_string = utils.get_display_name(who)
|
who_string = utils.get_display_name(who)
|
||||||
if isinstance(who, (types.User, types.Channel)) and who.username:
|
if isinstance(who, (types.User, types.Channel)) and who.username:
|
||||||
who_string += f" (@{who.username})"
|
who_string += f" (@{who.username})"
|
||||||
who_string += f", [#{who.id}](tg://user?id={who.id})"
|
who_string += f", #{who.id}"
|
||||||
|
|
||||||
await event.edit(who_string)
|
await event.edit(who_string)
|
||||||
|
|
|
@ -10,7 +10,7 @@ from uniborg import util
|
||||||
DELETE_TIMEOUT = 2
|
DELETE_TIMEOUT = 2
|
||||||
|
|
||||||
|
|
||||||
@borg.on(util.admin_cmd(r"^\.(?:re)?load (?P<shortname>\w+)$"))
|
@borg.on(util.admin_cmd(r"^\.load (?P<shortname>\w+)$"))
|
||||||
async def load_reload(event):
|
async def load_reload(event):
|
||||||
await event.delete()
|
await event.delete()
|
||||||
shortname = event.pattern_match["shortname"]
|
shortname = event.pattern_match["shortname"]
|
||||||
|
|
|
@ -48,6 +48,6 @@ class Storage:
|
||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
if not self._root.is_dir():
|
if not self._root.is_dir():
|
||||||
self._root.mkdir(parents=True, exist_ok=True)
|
self._root(parents=True, exist_ok=True)
|
||||||
with open(self._root / FILE_NAME, 'w') as fp:
|
with open(self._root / FILE_NAME, 'w') as fp:
|
||||||
json.dump(self._data, fp)
|
json.dump(self._data, fp)
|
||||||
|
|
Loading…
Reference in New Issue