From d5f70423a3a2fed7bccc4586129e004781c45283 Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Thu, 8 Nov 2018 11:00:19 +0000 Subject: [PATCH 1/7] stdplugins/who: link user by ID --- stdplugins/who.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdplugins/who.py b/stdplugins/who.py index 309008f..e4f5349 100644 --- a/stdplugins/who.py +++ b/stdplugins/who.py @@ -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) From 5438f95f34dc3985f9099a51178e94eec456d354 Mon Sep 17 00:00:00 2001 From: Lonami Date: Mon, 17 Dec 2018 17:55:53 +0100 Subject: [PATCH 2/7] Actually write the method name to mkdir on storage --- uniborg/storage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniborg/storage.py b/uniborg/storage.py index 70fda9b..2cff9e2 100644 --- a/uniborg/storage.py +++ b/uniborg/storage.py @@ -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) From c35dcbf26d302db9903956af10e5578ee8871468 Mon Sep 17 00:00:00 2001 From: Lonami Date: Mon, 17 Dec 2018 22:21:16 +0100 Subject: [PATCH 3/7] Simplify code (cherry picked from commit 2a5e9aac94429d58806e05dd662c2cb149836f67) --- stdplugins/info.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/stdplugins/info.py b/stdplugins/info.py index 4e8ace0..a22fc5a 100644 --- a/stdplugins/info.py +++ b/stdplugins/info.py @@ -2,15 +2,12 @@ # 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/. -import string - from telethon import events from telethon.utils import add_surrogate from telethon.tl.types import MessageEntityPre from telethon.tl.tlobject import TLObject import datetime -PRINTABLE_SET = set(string.printable.encode()) STR_LEN_MAX = 256 BYTE_LEN_MAX = 64 @@ -61,7 +58,7 @@ def yaml_format(obj, indent=0): return result elif isinstance(obj, bytes): # repr() bytes if it's printable, hex like "FF EE BB" otherwise - if all(c in PRINTABLE_SET for c in obj): + if all(0x20 <= c < 0x7f for c in obj): return repr(obj) else: return ('<…>' if len(obj) > BYTE_LEN_MAX else @@ -91,7 +88,4 @@ async def _(event): return msg = await event.message.get_reply_message() yaml_text = yaml_format(msg) - await event.edit( - yaml_text, - parse_mode=parse_pre - ) + await event.edit(yaml_text, parse_mode=parse_pre) From 2c75fb25a32d006dd7c1dc2b9be0043e2502ca89 Mon Sep 17 00:00:00 2001 From: Lonami Date: Wed, 19 Dec 2018 15:50:12 +0100 Subject: [PATCH 4/7] Support .reload to reload commands --- uniborg/_core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uniborg/_core.py b/uniborg/_core.py index 4679ec3..7475028 100644 --- a/uniborg/_core.py +++ b/uniborg/_core.py @@ -10,7 +10,7 @@ from uniborg import util DELETE_TIMEOUT = 2 -@borg.on(util.admin_cmd(r"^\.load (?P\w+)$")) +@borg.on(util.admin_cmd(r"^\.(?:re)?load (?P\w+)$")) async def load_reload(event): await event.delete() shortname = event.pattern_match["shortname"] From facd4360146fb0a037a4c81315b8a02472f0b5dd Mon Sep 17 00:00:00 2001 From: Lonami Date: Wed, 19 Dec 2018 14:52:09 +0000 Subject: [PATCH 5/7] Strikethrough support in markdown --- stdplugins/markdown.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index 13fec87..57c7b94 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -44,6 +44,10 @@ def parse_aesthetics(m): 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 +82,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) ] From c41792af6b692d302575b6e66dd6e296974e0e86 Mon Sep 17 00:00:00 2001 From: Lonami Date: Wed, 19 Dec 2018 14:58:49 +0000 Subject: [PATCH 6/7] Simplify aesthetify --- stdplugins/markdown.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index 57c7b94..d9e885e 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -31,16 +31,15 @@ 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 From a254c113a70e21c9498dbad7646eddf7414002a0 Mon Sep 17 00:00:00 2001 From: Lonami Date: Fri, 21 Dec 2018 18:25:16 +0000 Subject: [PATCH 7/7] Fix markdown parse edge case --- stdplugins/markdown.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index d9e885e..b56e7ed 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -102,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: