async def _flood(_, message: Message): chat_flood = DATA.get(message.chat.id) if chat_flood is None: data = { "user_id": message.from_user.id, "time": time.time(), "count": 1 } DATA[message.chat.id] = data return cur_user = message.from_user.id if cur_user != chat_flood["user_id"]: data = {"user_id": cur_user, "time": time.time(), "count": 1} DATA[message.chat.id] = data return prev_count = chat_flood["count"] prev_time = chat_flood["time"] if (time.time() - prev_time) < MIN_DELAY: count = prev_count + 1 if count >= MSG_LIMIT: await message.chat.kick_member(cur_user, until_date=int(time.time() + 45)) await message.reply( "**MAX FLOOD LIMIT REACHED**\n User Has been Kicked.") elif count == WARN_LIMIT: await message.reply("**WARN**\n `Flood Detected !`") else: count = 1 DATA[message.chat.id] = { "user_id": cur_user, "time": time.time(), "count": count } message.continue_propagation()
async def _on_conversation(_, msg: RawMessage) -> None: data = _CONV_DICT[msg.chat.id] if isinstance(data, asyncio.Queue): data.put_nowait(msg) elif msg.from_user and msg.from_user.id == data[0]: data[1].put_nowait(msg) msg.continue_propagation()
async def pmPermiat(client: USER, message: Message): chat_id = message.chat.id if not chat_id in pchats: pchats.append(chat_id) await message.reply_text("Approoved to PM") return message.continue_propagation()
async def _verify_msg_(_, msg: Message): """ Verify Msg for New chat Members """ chat_id = msg.chat.id for member in msg.new_chat_members: try: user_status = (await msg.chat.get_member(member.id)).status if user_status in ("restricted", "kicked"): continue except Exception: pass if member.is_bot or not await check_bot_rights(chat_id, "can_restrict_members"): file_id, file_ref, text, buttons = await wc_msg(member) reply = await msg.reply_animation( animation=file_id, file_ref=file_ref, caption=text, reply_markup=buttons ) await asyncio.sleep(120) await reply.delete() else: await bot.restrict_chat_member(chat_id, member.id, ChatPermissions()) try: await bot.get_chat_member("TheUserGe", member.id) except UserNotParticipant: await force_sub(msg, member) else: await verify_keyboard(msg, member) msg.continue_propagation()
async def rmpmPermiat(client: USER, message: Message): chat_id = message.chat.id if chat_id in pchats: pchats.remove(chat_id) await message.reply_text("Dispprooved to PM") return message.continue_propagation()
async def rmpmPermiat(client: USER, message: Message): chat_id = message.chat.id if chat_id in pchats: pchats.remove(chat_id) await message.reply_text("Maaf anda Ditolak untuk Private Message") return message.continue_propagation()
async def pmPermiat(client: USER, message: Message): chat_id = message.chat.id if chat_id not in pchats: pchats.append(chat_id) await message.reply_text("Disetujui untuk Private Message") return message.continue_propagation()
async def globalFloodPrevention(client: lolBot, message: Message): if message.from_user.id in users: message.stop_propagation() users.append(message.from_user.id) t = threading.Thread(target=handleFlood, args=(message.from_user.id, ), daemon=True) t.start() message.continue_propagation()
async def random_react(c: Korone, m: Message): if m.message_id % 100 != 0: m.continue_propagation() react = random.choice(RANDOM_REACT) if isinstance(react, tuple): react = random.choice(react) await c.send_message(m.chat.id, react) m.continue_propagation()
async def stop_user_from_doing_anything(_, message: Message): allowed_users = Common().allowed_users if allowed_users: if message.chat.id in allowed_users or message.chat.id == Common( ).bot_dustbin: message.continue_propagation() else: message.stop_propagation() else: message.continue_propagation()
async def creates_the_user(bot: BmlFireflyBot, message: Message): user = UserDB().find_user(message.from_user) if user is None: UserDB().find_or_create(message.from_user) if message.from_user.last_name and message.from_user.username: full_message = ( f"**A new user has started using {str(BmlFireflyBot)}**\n" "UserID: __[{user_id}](tg://user?id={user_id})__\n" "First Name: __{first_name}__\n" "Last Name: __{last_name}__\n" "Username: @{username}") await bot.send_log( full_message.format( user_id=message.from_user.id, first_name=message.from_user.first_name, last_name=message.from_user.last_name, username=message.from_user.username, )) elif message.from_user.username: username_message = ( f"**A new user has started using {str(BmlFireflyBot)}**\n" "UserID: __[{user_id}](tg://user?id={user_id})__\n" "First Name: __{first_name}__\n" "Username: @{username}") await bot.send_log( username_message.format( user_id=message.from_user.id, first_name=message.from_user.first_name, username=message.from_user.username, )) else: f_name_message = ( f"**A new user has started using {str(BmlFireflyBot)}**\n" "UserID: __[{user_id}](tg://user?id={user_id})__\n" "First Name: __{first_name}__") await bot.send_log( f_name_message.format( user_id=message.from_user.id, first_name=message.from_user.first_name, )) else: UserDB().update_user(message.from_user) message.continue_propagation()
async def _verify_msg_(_, msg: Message): """ Verify Msg for New chat Members """ chat_id = msg.chat.id for member in msg.new_chat_members: if member.is_bot or not await check_bot_rights(chat_id, "can_restrict_members"): file_id, file_ref, text, buttons = await wc_msg(member) reply = await msg.reply_animation( animatiom=file_id, file_ref=file_ref, caption=text, reply_markup=buttons ) await asyncio.sleep(120) await reply.delete() else: await bot.restrict_chat_member(chat_id, member.id, ChatPermissions()) await verify_keyboard(msg, member) msg.continue_propagation()
async def stop_user_from_doing_anything(_, message: Message): """ Checks if user is allowed to use MediaCenterBot """ # Updates user details if they are supposed to be in the system if message.from_user.id in UserDB().all_user_ids(): UserDB().update_user(message) pass if message.from_user.id not in UserDB().all_user_ids(): if message.chat and message.chat.type in {"group", "supergroup"}: await message.reply(GROUPS_NOT_ALLOWED_MESSAGE) Incident().create_incident(message) message.stop_propagation() else: await message.reply(NOT_ALLOWED_MESSAGE) Incident().create_incident(message) message.stop_propagation() else: message.continue_propagation()
async def on_reply_m(c: AndroidRepo, m: Message): answer = m.matches[0]["answer"] reply = m.reply_to_message request = await get_request_by_message_id(message_id=reply.id) if request: user_id = request[0]["user"] request_id = request[0]["request_id"] doc = KanTeXDocument( Section( "Answer to your request", KeyValueItem(Bold("ID"), Code(request_id)), KeyValueItem(Bold("Answer"), Code(answer)), ) ) try: await c.send_message(chat_id=user_id, text=doc) except UserIsBlocked: await m.reply_text("The user has blocked the bot!") return else: m.continue_propagation()
def auto_read(_, message: Message): app.read_history(message.chat.id) message.continue_propagation()
async def pre_check(self, _client: Client, msg: Message) -> None: if await self.query_authorized_user(msg.chat.id): msg.continue_propagation()
async def stop_user_from_doing_anything(_, message: Message): allowed_users = Common().allowed_users if allowed_users and message.from_user.id not in allowed_users: message.stop_propagation() else: message.continue_propagation()
async def pre_check_owner(self, _client: Client, msg: Message) -> None: if msg.chat.id in self.owners: msg.continue_propagation()
async def auto_read(_, message: Message): await UserBot.read_history(message.chat.id) message.continue_propagation()
async def on_message_m(c: AndroidRepo, m: Message): for prefix in PREFIXES: if m.text and m.text.startswith(prefix): m.continue_propagation() await c.forward_messages(chat_id=STAFF_ID, from_chat_id=m.chat.id, message_ids=m.id)