| 5 |
| from pyrogram import Client |
| 6 | from pyrogram.types import InputMediaDocument |
| 7 |
| 8 | api_id = 11535358 |
| 9 | api_hash = "33d372962fadb01df47e6ceed4e33cd6" |
| 10 | artifacts_path = Path("artifacts") |
| 11 | test_version = argv[3] == "test" if len(argv) > 2 else None |
| 12 |
| 13 |
| 14 | def find_apk(abi: str) -> Path: |
| 15 | dirs = list(artifacts_path.glob("*")) |
| 16 | for dir in dirs: |
| 17 | if dir.is_dir(): |
| 18 | apks = list(dir.glob("*.apk")) |
| 19 | for apk in apks: |
| 20 | if abi in apk.name: |
| 21 | return apk |
| 22 |
| 23 |
| 24 | def get_thumb() -> str: |
| 25 | return "TMessagesProj/src/main/" + "ic_launcher_nagram_round_blue-playstore.png" |
| 26 |
| 27 |
| 28 | def get_caption() -> str: |
| 29 | pre = "Test version, " if test_version else "" |
| 30 | with open(artifacts_path / "caption.txt", "r", encoding="utf-8") as f: |
| 31 | return pre + f.read() |
| 32 |
| 33 |
| 34 | def get_document() -> list["InputMediaDocument"]: |
| 35 | documents = [] |
| 36 | abis = ["arm64-v8a", "armeabi-v7a"] |
| 37 | for abi in abis: |
| 38 | if apk := find_apk(abi): |
| 39 | documents.append( |
| 40 | InputMediaDocument( |
| 41 | media=str(apk), |
| 42 | thumb=get_thumb(), |
| 43 | ) |
| 44 | ) |
| 45 | documents[-1].caption = get_caption() |
| 46 | return documents |
| 47 |
| 48 |
| 49 | def retry(func): |
| 50 | async def wrapper(*args, **kwargs): |
| 51 | for _ in range(3): |
| 52 | try: |
| 53 | return await func(*args, **kwargs) |
| 54 | except Exception as e: |
| 55 | print(e) |
| 56 |
| 57 | return wrapper |
| 58 |
| 59 |
| 60 | @retry |
| 61 | async def send_to_channel(client: "Client", cid: str): |
| 62 | with contextlib.suppress(ValueError): |
| 63 | cid = int(cid) |
| 64 | await client.send_media_group( |
| 65 | cid, |
| 66 | media=get_document(), |
| 67 | ) |
| 68 |
| 69 |
| 70 | def get_client(bot_token: str): |
| 71 | return Client( |
| 72 | "helper_bot", |
| 73 | api_id=api_id, |
| 74 | api_hash=api_hash, |
| 75 | bot_token=bot_token, |
| 76 | ) |
| 77 |
| 78 |
| 79 | async def main(): |
| 80 | bot_token = argv[1] |
| 81 | chat_id = argv[2] |
| 82 | client = get_client(bot_token) |
| 83 | await client.start() |
| 84 | await send_to_channel(client, chat_id) |
| 85 | await client.log_out() |
| 86 |
| 87 |
| 88 | if __name__ == "__main__": |
| 89 | from asyncio import run |
| 90 |
| 91 | run(main()) |
| 92 |