async def monitorpms(event): sender = await event.get_sender() current_message_text = event.message.message.lower() if current_message_text == BAALAJI_TG_USER_BOT or \ current_message_text == TG_COMPANION_USER_BOT or \ current_message_text == THETGBOT_USER_BOT_WARN_ZERO: # userbot's should not reply to other userbot's # https://core.telegram.org/bots/faq#why-doesn-39t-my-bot-see-messages-from-other-bots return False if ENV.ANTI_PM_SPAM and not sender.bot: chat = await event.get_chat() if not is_approved(chat.id) and chat.id != client.uid: logger.info(chat.stringify()) logger.info(client.storage.PM_WARNS) if chat.id in ENV.SUDO_USERS: await event.edit("Oh wait, that looks like my master!") await event.edit("Approving..") approve(chat.id, "SUDO_USER") if chat.id not in client.storage.PM_WARNS: client.storage.PM_WARNS.update({chat.id: 0}) if client.storage.PM_WARNS[chat.id] == ENV.MAX_PM_FLOOD: r = await event.reply(THETGBOT_USER_BOT_WARN_ZERO) await asyncio.sleep(3) await client(functions.contacts.BlockRequest(chat.id)) if chat.id in client.storage.PREV_REPLY_MESSAGE: await client.storage.PREV_REPLY_MESSAGE[chat.id].delete() client.storage.PREV_REPLY_MESSAGE[chat.id] = r return r = await event.reply( f"{THETGBOT_USER_BOT_NO_WARN}\n`Messages remaining: {int(ENV.MAX_PM_FLOOD - client.storage.PM_WARNS[chat.id])} out of {int(ENV.MAX_PM_FLOOD)}`" ) client.storage.PM_WARNS[chat.id] += 1 if chat.id in client.storage.PREV_REPLY_MESSAGE: await client.storage.PREV_REPLY_MESSAGE[chat.id].delete() client.storage.PREV_REPLY_MESSAGE[chat.id] = r
async def auto_approve(event): #sanity check here #if any outgoing text contain bot module invocator then do not autoapprove #for eg if outgoing text has .xyz then due to . current chat wont be auto approved if event.text[0] == Config.COMMAND_HANDLER[1]: return False reason = "auto_approve" chat = await event.get_chat() if Config.ANTI_PM_SPAM: if not is_approved(chat.id): approve(chat.id, reason) logger.info("Auto approved user: " + str(chat.id))
async def auto_approve(event): if "block" in event.text or "disapprove" in event.text: return False reason = "auto_approve" chat = await event.get_chat() if ENV.ANTI_PM_SPAM: if not is_approved(chat.id): if chat.id in client.storage.PM_WARNS: del client.storage.PM_WARNS[chat.id] if chat.id in client.storage.PREV_REPLY_MESSAGE: await client.storage.PREV_REPLY_MESSAGE[chat.id].delete() del client.storage.PREV_REPLY_MESSAGE[chat.id] approve(chat.id, reason) logger.info("Auto approved user: " + str(chat.id))
async def approve_pm(event): if event.fwd_from: return reason = event.pattern_match.group(1) chat = await event.get_chat() if ENV.ANTI_PM_SPAM: if event.is_private: if not is_approved(chat.id): if chat.id in client.storage.PM_WARNS: del client.storage.PM_WARNS[chat.id] if chat.id in client.storage.PREV_REPLY_MESSAGE: await client.storage.PREV_REPLY_MESSAGE[chat.id].delete() del client.storage.PREV_REPLY_MESSAGE[chat.id] approve(chat.id, reason) await event.edit("PM accepted.") await asyncio.sleep(3) await event.delete()
async def auto_approve(event): user = await event.get_chat() if ("block" in event.text or "disapprove" in event.text or user.bot): return False reason = "auto_approve" if ENV.ANTI_PM_SPAM: if not is_approved(user.id): if user.id in client.storage.PM_WARNS: del client.storage.PM_WARNS[user.id] if user.id in client.storage.PREV_REPLY_MESSAGE: await client.storage.PREV_REPLY_MESSAGE[user.id].delete() del client.storage.PREV_REPLY_MESSAGE[user.id] approve(user.id, reason) msg = await client.send_message( event.chat_id, f"__Approved {user.first_name}, cuz outgoing message__", silent=True) logger.info("Auto approved user: " + str(user.id)) await asyncio.sleep(2) await msg.delete()