async def on_snip(event): global last_triggered_filters name = event.raw_text if event.chat_id in last_triggered_filters: if name in last_triggered_filters[event.chat_id]: # avoid userbot spam # "I demand rights for us bots, we are equal to you humans." -Henri Koivuneva (t.me/UserbotTesting/2698) return False snips = get_all_filters(event.chat_id) if snips: for snip in snips: pattern = r"( |^|[^\w])" + re.escape(snip.keyword) + r"( |$|[^\w])" if re.search(pattern, name, flags=re.IGNORECASE): if snip.snip_type == TYPE_PHOTO: media = types.InputPhoto(int(snip.media_id), int(snip.media_access_hash), snip.media_file_reference) elif snip.snip_type == TYPE_DOCUMENT: media = types.InputDocument(int(snip.media_id), int(snip.media_access_hash), snip.media_file_reference) else: media = None message_id = event.message.id if event.reply_to_msg_id: message_id = event.reply_to_msg_id await borg.send_message(event.chat_id, snip.reply, reply_to=message_id, file=media) if event.chat_id not in last_triggered_filters: last_triggered_filters[event.chat_id] = [] last_triggered_filters[event.chat_id].append(name) await asyncio.sleep(DELETE_TIMEOUT) last_triggered_filters[event.chat_id].remove(name)
async def on_snip(event): name = event.raw_text if (event.chat_id in last_triggered_filters and name in last_triggered_filters[event.chat_id]): # avoid userbot spam # "I demand rights for us bots, we are equal to you humans." -Henri Koivuneva (t.me/UserbotTesting/2698) return False snips = get_all_filters(event.chat_id) if snips: for snip in snips: pattern = r"( |^|[^\w])" + re.escape(snip.keyword) + r"( |$|[^\w])" if re.search(pattern, name, flags=re.IGNORECASE): msg_o = await event.client.get_messages( entity=Config.PRIVATE_CHANNEL_BOT_API_ID, ids=int(snip.f_mesg_id)) message_id = event.message.id if event.reply_to_msg_id: message_id = event.reply_to_msg_id await event.client.send_message(event.chat_id, msg_o.message, reply_to=message_id, file=msg_o.media) if event.chat_id not in last_triggered_filters: last_triggered_filters[event.chat_id] = [] last_triggered_filters[event.chat_id].append(name) await asyncio.sleep(DELETE_TIMEOUT) last_triggered_filters[event.chat_id].remove(name)
async def on_snip_list(event): all_snips = get_all_filters(event.chat_id) OUT_STR = "Available Filters in the Current Chat:\n" if len(all_snips) > 0: for a_snip in all_snips: OUT_STR += f"👉 {a_snip.keyword} \n" else: OUT_STR = "No Filters. Start Saving using `.savefilter`" if len(OUT_STR) > Config.MAX_MESSAGE_SIZE_LIMIT: with io.BytesIO(str.encode(OUT_STR)) as out_file: out_file.name = "filters.text" await borg.send_file( event.chat_id, out_file, force_document=True, allow_cache=False, caption="Available Filters in the Current Chat", reply_to=event) await event.delete() else: await event.edit(OUT_STR)