async def on_new_message(event): name = event.raw_text snips = sql.get_chat_blacklist(event.chat_id) for snip in snips: pattern = r"( |^|[^\w])" + re.escape(snip) + r"( |$|[^\w])" if re.search(pattern, name, flags=re.IGNORECASE): try: await event.delete() except Exception as e: await event.reply( "I do not have DELETE permission in this chat") # TODO: delete chat_id from DB break
async def on_new_message(event): # TODO: exempt admins from locks if borg.me.id == event.from_id: return name = event.raw_text snips = sql.get_chat_blacklist(event.chat_id) for snip in snips: pattern = r"( |^|[^\w])" + re.escape(snip) + r"( |$|[^\w])" if re.search(pattern, name, flags=re.IGNORECASE): try: await event.delete() except Exception as e: await event.reply("I do not have DELETE permission in this chat") sql.rm_from_blacklist(event.chat_id, snip.lower()) break
async def on_new_message(event): chat = await event.get_chat() if chat.admin_rights or chat.creator: # blacklist should not be affected for admins of the group return False name = event.raw_text snips = sql.get_chat_blacklist(event.chat_id) for snip in snips: pattern = r"( |^|[^\w])" + re.escape(snip) + r"( |$|[^\w])" if re.search(pattern, name, flags=re.IGNORECASE): try: await event.delete() except Exception as e: await event.reply( "I do not have DELETE permission in this chat") sql.rm_from_blacklist(event.chat_id, snip.lower()) break
async def on_view_blacklist(event): all_blacklisted = sql.get_chat_blacklist(event.chat_id) OUT_STR = "Blacklists in the Current Chat:\n" if len(all_blacklisted) > 0: for trigger in all_blacklisted: OUT_STR += f"👉 {trigger} \n" else: OUT_STR = "No BlackLists. Start Saving using `.addblacklist`" if len(OUT_STR) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(OUT_STR)) as out_file: out_file.name = "blacklist.text" await borg.send_file(event.chat_id, out_file, force_document=True, allow_cache=False, caption="BlackLists in the Current Chat", reply_to=event) await event.delete() else: await event.edit(OUT_STR)
async def on_new_message(event): # result = await borg(functions.channels.GetParticipantRequest( # channel=event.chat_id, # user_id=event.message.from_id # )) # if not event.is_private and isinstance(result.participant, (types.ChannelParticipantAdmin, types.ChannelParticipantCreator)): # # blacklist should not be affected for admins of the group # return False name = event.raw_text snips = sql.get_chat_blacklist(event.chat_id) for snip in snips: pattern = r"( |^|[^\w])" + re.escape(snip) + r"( |$|[^\w])" if re.search(pattern, name, flags=re.IGNORECASE): try: await event.delete() except Exception as e: await event.reply( "I do not have DELETE permission in this chat") sql.rm_from_blacklist(event.chat_id, snip.lower()) break