mirror of
https://github.com/PaiGramTeam/GetToken.git
synced 2024-11-21 14:38:24 +00:00
feat: push to telegram
This commit is contained in:
parent
40717efbf5
commit
020cdb2a81
BIN
.github/scripts/photo.jpg
vendored
Normal file
BIN
.github/scripts/photo.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
2
.github/scripts/requirements.txt
vendored
Normal file
2
.github/scripts/requirements.txt
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
git+https://github.com/KurimuzonAkuma/pyrogram
|
||||
PyroTgCrypto==1.2.6a0
|
85
.github/scripts/upload.py
vendored
Normal file
85
.github/scripts/upload.py
vendored
Normal file
@ -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())
|
8
.github/workflows/android.yml
vendored
8
.github/workflows/android.yml
vendored
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user