|
| 1 | +#(©)Codexbotz |
| 2 | + |
| 3 | +import base64 |
| 4 | +import re |
| 5 | +import asyncio |
| 6 | +from pyrogram import filters |
| 7 | +from config import FORCE_SUB_CHANNEL, ADMINS |
| 8 | +from pyrogram.errors.exceptions.bad_request_400 import UserNotParticipant |
| 9 | +from pyrogram.errors import FloodWait |
| 10 | + |
| 11 | +async def is_subscribed(filter, client, message): |
| 12 | + if not FORCE_SUB_CHANNEL: |
| 13 | + return True |
| 14 | + user_id = message.from_user.id |
| 15 | + if user_id in ADMINS: |
| 16 | + return True |
| 17 | + try: |
| 18 | + member = await client.get_chat_member(chat_id = FORCE_SUB_CHANNEL, user_id = user_id) |
| 19 | + except UserNotParticipant: |
| 20 | + return False |
| 21 | + |
| 22 | + if not member.status in ["creator", "administrator", "member"]: |
| 23 | + return False |
| 24 | + else: |
| 25 | + return True |
| 26 | + |
| 27 | +async def encode(string): |
| 28 | + string_bytes = string.encode("ascii") |
| 29 | + base64_bytes = base64.b64encode(string_bytes) |
| 30 | + base64_string = base64_bytes.decode("ascii") |
| 31 | + return base64_string |
| 32 | + |
| 33 | +async def decode(base64_string): |
| 34 | + base64_bytes = base64_string.encode("ascii") |
| 35 | + string_bytes = base64.b64decode(base64_bytes) |
| 36 | + string = string_bytes.decode("ascii") |
| 37 | + return string |
| 38 | + |
| 39 | +async def get_messages(client, message_ids): |
| 40 | + messages = [] |
| 41 | + total_messages = 0 |
| 42 | + while total_messages != len(message_ids): |
| 43 | + temb_ids = message_ids[total_messages:total_messages+200] |
| 44 | + try: |
| 45 | + msgs = await client.get_messages( |
| 46 | + chat_id=client.db_channel.id, |
| 47 | + message_ids=temb_ids |
| 48 | + ) |
| 49 | + except FloodWait as e: |
| 50 | + await asyncio.sleep(e.x) |
| 51 | + msgs = await client.get_messages( |
| 52 | + chat_id=client.db_channel.id, |
| 53 | + message_ids=temb_ids |
| 54 | + ) |
| 55 | + except: |
| 56 | + pass |
| 57 | + total_messages += len(temb_ids) |
| 58 | + messages.extend(msgs) |
| 59 | + return messages |
| 60 | + |
| 61 | +async def get_message_id(client, message): |
| 62 | + if message.forward_from_chat: |
| 63 | + if first_message.forward_from_chat.id == client.db_channel.id: |
| 64 | + return first_message.forward_from_message_id |
| 65 | + else: |
| 66 | + return 0 |
| 67 | + elif message.forward_sender_name: |
| 68 | + return 0 |
| 69 | + elif message.text: |
| 70 | + pattern = "https://t.me/(?:c/)?(.*)/(\d+)" |
| 71 | + matches = re.match(pattern,message.text) |
| 72 | + if not matches: |
| 73 | + return 0 |
| 74 | + channel_id = matches.group(1) |
| 75 | + msg_id = int(matches.group(2)) |
| 76 | + if channel_id.isdigit(): |
| 77 | + if f"-100{channel_id}" == str(client.db_channel.id): |
| 78 | + return msg_id |
| 79 | + else: |
| 80 | + if channel_id == client.db_channel.username: |
| 81 | + return msg_id |
| 82 | + else: |
| 83 | + return 0 |
| 84 | + |
| 85 | +subscribed = filters.create(is_subscribed) |
0 commit comments