Merge pull request #2 from Lonami/master

Add more known sedbots to plugins/re
This commit is contained in:
Dan Elkouby 2018-04-20 11:58:06 +03:00 committed by GitHub
commit cf36b5bd4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -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)