From dbf561880e2e40d07052481f66b5dbe3af79f7f4 Mon Sep 17 00:00:00 2001 From: Dan Elkouby Date: Sun, 13 May 2018 13:25:52 +0300 Subject: [PATCH] re: add message header to prevent abuse --- stdplugins/re.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stdplugins/re.py b/stdplugins/re.py index fa0eacb..426d82f 100644 --- a/stdplugins/re.py +++ b/stdplugins/re.py @@ -5,7 +5,7 @@ import regex from telethon import events, utils from telethon.tl import types, functions - +HEADER = "[[regex]]\n" KNOWN_RE_BOTS = re.compile( r'(regex|moku|BananaButler_)bot', flags=re.IGNORECASE @@ -42,8 +42,10 @@ def doit(chat_id, match, original): def actually_doit(original): try: - s, i = regex.subn(fr, to, original.message, - count=count, flags=flags) + s = original.message + if s.startswith(HEADER): + s = s[len(HEADER):] + s, i = regex.subn(fr, to, s, count=count, flags=flags) if i > 0: return original, s except Exception as e: @@ -90,6 +92,7 @@ async def on_regex(event): m, s = doit(chat_id, event.pattern_match, await event.reply_message) if m is not None: + s = f"{HEADER}{s}" out = await borg.send_message(await event.input_chat, s, reply_to=m.id) last_msgs[chat_id].appendleft(out) elif s is not None: