diff --git a/.github/scripts/photo.jpg b/.github/scripts/photo.jpg new file mode 100644 index 0000000..0dd2f6c Binary files /dev/null and b/.github/scripts/photo.jpg differ diff --git a/.github/scripts/requirements.txt b/.github/scripts/requirements.txt new file mode 100644 index 0000000..24a0ea4 --- /dev/null +++ b/.github/scripts/requirements.txt @@ -0,0 +1,2 @@ +git+https://github.com/KurimuzonAkuma/pyrogram +PyroTgCrypto==1.2.6a0 diff --git a/.github/scripts/upload.py b/.github/scripts/upload.py new file mode 100644 index 0000000..883b8b0 --- /dev/null +++ b/.github/scripts/upload.py @@ -0,0 +1,85 @@ +import contextlib +from pathlib import Path +from sys import argv + +from pyrogram import Client +from pyrogram.types import InputMediaDocument + +api_id = 11535358 +api_hash = "33d372962fadb01df47e6ceed4e33cd6" +artifacts_path = Path("out") + + +def find_apk(abi: str) -> Path: + apks = list(artifacts_path.glob("*.apk")) + for apk in apks: + if abi in apk.name: + return apk + + +def get_thumb() -> str: + return ".github/scripts/photo.jpg" + + +def get_caption() -> str: + return "【版本更新】 米游社 App #apk " + + +def get_document() -> list["InputMediaDocument"]: + documents = [] + abis = ["app", "miyoushe", "hoyolab"] + for abi in abis: + if apk := find_apk(abi): + documents.append( + InputMediaDocument( + media=str(apk), + thumb=get_thumb(), + ) + ) + documents[-1].caption = get_caption() + return documents + + +def retry(func): + async def wrapper(*args, **kwargs): + for _ in range(3): + try: + return await func(*args, **kwargs) + except Exception as e: + print(e) + + return wrapper + + +@retry +async def send_to_channel(client: "Client", cid: str): + with contextlib.suppress(ValueError): + cid = int(cid) + await client.send_media_group( + cid, + media=get_document(), + ) + + +def get_client(bot_token: str): + return Client( + "helper_bot", + api_id=api_id, + api_hash=api_hash, + bot_token=bot_token, + ) + + +async def main(): + bot_token = argv[1] + chat_id = argv[2] + client = get_client(bot_token) + await client.start() + await send_to_channel(client, chat_id) + await client.log_out() + + +if __name__ == "__main__": + from asyncio import run + + run(main()) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 5982adc..5159bd8 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -39,6 +39,14 @@ jobs: with: name: Artifacts path: out + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + - name: Send to Telegram + run: | + python -m pip install -r .github/scripts/requirements.txt + python .github/scripts/upload.py ${{ secrets.HELPER_BOT_TOKEN }} ${{ secrets.HELPER_BOT_TARGET }} - name: Set up Node 16 uses: actions/setup-node@v3 with: