From f0e7d16276301498d0a2cc337e86a16daa98940c Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Thu, 14 Jun 2018 19:20:41 +0000 Subject: [PATCH 1/2] Move aesthetics functionality into markdown --- stdplugins/aesthetics.py | 26 -------------------------- stdplugins/markdown.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 stdplugins/aesthetics.py diff --git a/stdplugins/aesthetics.py b/stdplugins/aesthetics.py deleted file mode 100644 index 0495c5d..0000000 --- a/stdplugins/aesthetics.py +++ /dev/null @@ -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 diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index bee0372..0c8d3df 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -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) ] From 88fd76653a279c86bf26916e8f6b52c59b4f89b4 Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Fri, 15 Jun 2018 00:09:25 +0300 Subject: [PATCH 2/2] Update for newest Telethon master --- stdplugins/all.py | 2 +- stdplugins/headpat.py | 2 +- stdplugins/sed.py | 2 +- uniborg/uniborg.py | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/stdplugins/all.py b/stdplugins/all.py index 65f9528..56fd97a 100644 --- a/stdplugins/all.py +++ b/stdplugins/all.py @@ -6,7 +6,7 @@ from telethon import events @borg.on(events.NewMessage(pattern=r"\.all", outgoing=True)) async def _(event): - if event.forward: + if event.fwd_from: return await event.delete() mentions = "@all" diff --git a/stdplugins/headpat.py b/stdplugins/headpat.py index e7cf3a4..84d88f7 100644 --- a/stdplugins/headpat.py +++ b/stdplugins/headpat.py @@ -17,7 +17,7 @@ oops = "OOPSIE WOOPSIE!! Uwu We madea fucky wucky!! A wittle fucko boingo! " \ @borg.on(events.NewMessage) async def on_pat(event): - if event.forward: + if event.fwd_from: return user = borg.me.username diff --git a/stdplugins/sed.py b/stdplugins/sed.py index fe518a4..e13ab06 100644 --- a/stdplugins/sed.py +++ b/stdplugins/sed.py @@ -81,7 +81,7 @@ async def on_message(event): @borg.on(events.NewMessage( pattern=re.compile(r"^s/((?:\\/|[^/])+)/((?:\\/|[^/])*)(/.*)?"))) async def on_regex(event): - if event.forward: + if event.fwd_from: return if not event.is_private and await group_has_sedbot(await event.input_chat): return diff --git a/uniborg/uniborg.py b/uniborg/uniborg.py index 4f40251..5040b7a 100644 --- a/uniborg/uniborg.py +++ b/uniborg/uniborg.py @@ -38,7 +38,7 @@ class Uniborg(TelegramClient): # precedence self._event_builders = hacks.ReverseList() - self._loop.run_until_complete(self._async_init(bot_token=bot_token)) + self.loop.run_until_complete(self._async_init(bot_token=bot_token)) core_plugin = Path(__file__).parent / "_core.py" self.load_plugin_from_file(core_plugin) @@ -53,7 +53,7 @@ class Uniborg(TelegramClient): self.uid = telethon.utils.get_peer_id(self.me) def run(self): - self._loop.run_forever() + self.loop.run_forever() def load_plugin(self, shortname): self.load_plugin_from_file(f"{self._plugin_path}/{shortname}.py")