async def force_subscribe_join(event: ChatAction.Event): if not redis_status(): return if not (event.user_joined or event.user_added): return join_chat = redis.get(f"sub.chat_id.{event.chat_id}") if not join_chat: return else: join_chat = join_chat.decode() user = await event.get_user() if user.bot: return if redis.get(f"sub.chat_id.{event.chat_id}.{user.id}"): return try: try: await bot(GetParticipantRequest(join_chat, user.id)) except ValueError: user_input = await event.get_input_user() await bot(GetParticipantRequest(join_chat, user_input)) redis.set(f'sub.chat_id.{event.chat_id}.{user.id}', 'true') redis.expire(f'sub.chat_id.{event.chat_id}.{user.id}', 3600) except UserNotParticipantError: msg = await event.reply( f'[{user.first_name}](tg://user?id={user.id}) 您需要先加入频道 @{join_chat} 才能发言。' ) await sleep(5) await msg.delete() except ChatAdminRequiredError: redis.delete(f"sub.chat_id.{event.chat_id}")
async def force_group_msg(context: Message): if not redis_status(): return join_chat = redis.get(f"group.chat_id.{context.chat_id}") if not join_chat: return if redis.get(f"group.chat_id.{context.chat_id}.{context.sender_id}"): return try: if context.sender.bot: pass except AttributeError: return try: try: await bot(GetParticipantRequest(context.chat, context.sender_id)) except ValueError: await bot.get_participants(context.chat) await bot(GetParticipantRequest(context.chat, context.sender_id)) redis.set(f'group.chat_id.{context.chat_id}.{context.sender_id}', 'true') redis.expire(f'group.chat_id.{context.chat_id}.{context.sender_id}', 3600) except UserNotParticipantError: try: reply = await context.get_reply_message() try: reply = reply.id except AttributeError: reply = None await context.delete() msg = await bot.send_message( context.chat_id, f'[{context.sender.first_name}](tg://user?id={context.sender_id}) ' f'您需要先加入频道讨论群才能发言。', reply_to=reply) await sleep(5) await msg.delete() except ChatAdminRequiredError: redis.delete(f"group.chat_id.{context.chat_id}") except ChatAdminRequiredError: redis.delete(f"group.chat_id.{context.chat_id}")
async def force_subscribe_msg(context: Message): if not redis_status(): return join_chat = redis.get(f"sub.chat_id.{context.chat_id}") if not join_chat: return if redis.get(f"sub.chat_id.{context.chat_id}.{context.sender_id}"): return else: join_chat = join_chat.decode() try: if context.sender.bot: return except AttributeError: return try: try: await bot(GetParticipantRequest(join_chat, context.sender_id)) except ValueError: await bot.get_participants(context.chat) await bot(GetParticipantRequest(join_chat, context.sender_id)) redis.set(f'sub.chat_id.{context.chat_id}.{context.sender_id}', 'true') redis.expire(f'sub.chat_id.{context.chat_id}.{context.sender_id}', 3600) except UserNotParticipantError: try: await context.delete() try: msg = await bot.send_message( context.chat_id, f'[{context.sender.first_name}](tg://user?id={context.sender_id}) ' f'您需要先加入频道 @{join_chat} 才能发言。') await sleep(5) await msg.delete() except ValueError: pass except ChatAdminRequiredError: redis.delete(f"sub.chat_id.{context.chat_id}") except ChatAdminRequiredError: redis.delete(f"sub.chat_id.{context.chat_id}")