Compare commits

...

9 Commits

Author SHA1 Message Date
Lonami a254c113a7 Fix markdown parse edge case 2018-12-21 18:25:16 +00:00
Lonami c41792af6b Simplify aesthetify 2018-12-19 14:58:49 +00:00
Lonami facd436014 Strikethrough support in markdown 2018-12-19 14:52:13 +00:00
Lonami 2c75fb25a3 Support .reload to reload commands 2018-12-19 15:50:12 +01:00
Lonami ca7b636696 Merge branch 'ninja_fix' of kate/uniborg into master 2018-12-18 00:02:40 +01:00
Lonami f46a08adf1 Merge branch 'master' of kate/uniborg into master 2018-12-18 00:01:45 +01:00
Lonami 5438f95f34 Actually write the method name to mkdir on storage 2018-12-17 17:55:53 +01:00
udf 74f0cea230
Fix ninja in saved messages
I'm not sure why you'd use ninja in your own chat, but it shouldn't raise anyways.
2018-11-21 23:24:33 +02:00
Dan Elkouby d5f70423a3 stdplugins/who: link user by ID 2018-11-08 11:00:19 +00:00
5 changed files with 19 additions and 10 deletions

View File

@ -31,19 +31,22 @@ 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)
if " " < c <= "~":
yield chr(ord(c) + 0xFF00 - 0x20)
elif c == " ":
yield "\u3000"
else:
yield c
return "".join(aesthetify(m[1])), None
def parse_strikethrough(m):
return ("\u0336".join(m[1]) + "\u0336"), None
def parse_subreddit(m):
text = '/' + m.group(3)
entity = MessageEntityTextUrl(
@ -78,6 +81,7 @@ MATCHERS = [
(get_tag_parser('```', partial(MessageEntityPre, language=''))),
(get_tag_parser('`', MessageEntityCode)),
(re.compile(r'\+\+(.+?)\+\+'), parse_aesthetics),
(re.compile(r'~~(.+?)~~'), parse_strikethrough),
(re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit),
(re.compile(r'(!\w+)'), parse_snip)
]
@ -98,6 +102,8 @@ def parse(message, old_entities=None):
# Skip already existing entities if we're at one
if i == e.offset:
i += e.length
else:
after += 1
# Find the first pattern that matches
for pattern, parser in MATCHERS:

View File

@ -5,6 +5,7 @@
import asyncio
from telethon import events
from telethon.tl.types import InputPeerSelf
import telethon.utils
from uniborg import util
@ -20,6 +21,8 @@ async def get_target_message(event):
async def await_read(chat, message):
if isinstance(chat, InputPeerSelf):
return
chat = telethon.utils.get_peer_id(chat)
async def read_filter(read_event):

View File

@ -22,6 +22,6 @@ async def _(event):
who_string = utils.get_display_name(who)
if isinstance(who, (types.User, types.Channel)) and who.username:
who_string += f" (@{who.username})"
who_string += f", #{who.id}"
who_string += f", [#{who.id}](tg://user?id={who.id})"
await event.edit(who_string)

View File

@ -10,7 +10,7 @@ from uniborg import util
DELETE_TIMEOUT = 2
@borg.on(util.admin_cmd(r"^\.load (?P<shortname>\w+)$"))
@borg.on(util.admin_cmd(r"^\.(?:re)?load (?P<shortname>\w+)$"))
async def load_reload(event):
await event.delete()
shortname = event.pattern_match["shortname"]

View File

@ -48,6 +48,6 @@ class Storage:
def _save(self):
if not self._root.is_dir():
self._root(parents=True, exist_ok=True)
self._root.mkdir(parents=True, exist_ok=True)
with open(self._root / FILE_NAME, 'w') as fp:
json.dump(self._data, fp)