From 598f41c01a56e907b34ed49807dca2a8e588d328 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 20 Apr 2018 10:54:37 +0200 Subject: [PATCH] Add more known sedbots to plugins/re --- stdplugins/re.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/stdplugins/re.py b/stdplugins/re.py index 4b95b5e..fa0eacb 100644 --- a/stdplugins/re.py +++ b/stdplugins/re.py @@ -3,6 +3,13 @@ import re import regex from telethon import events, utils +from telethon.tl import types, functions + + +KNOWN_RE_BOTS = re.compile( + r'(regex|moku|BananaButler_)bot', + flags=re.IGNORECASE +) # Heavily based on # https://github.com/SijmenSchoon/regexbot/blob/master/regexbot.py @@ -54,8 +61,14 @@ def doit(chat_id, match, original): async def group_has_regex(group): - return any(getattr(x, 'username', None) == 'regexbot' - for x in await borg.get_participants(group, search='@regexbot')) + if isinstance(group, types.InputPeerChannel): + full = await borg(functions.channels.GetFullChannelRequest(group)) + elif isinstance(group, types.InputPeerChat): + full = await borg(functions.messages.GetFullChatRequest(group.chat_id)) + else: + return False + + return any(KNOWN_RE_BOTS.match(x.username or '') for x in full.users) @borg.on(events.NewMessage)