TG upload with pyrogram.

This commit is contained in:
rozari0 2022-10-28 17:57:06 +06:00
parent ddafb9c769
commit 382a111eb7
2 changed files with 35 additions and 37 deletions

67
.github/tg.py vendored
View File

@ -1,33 +1,34 @@
import telegram
from tgconfig import *
from json import load
import multiprocessing
from os import system
from time import sleep as wait
def deploy():
system(f'./exec --local --api-id={TG_API_ID} --api-hash={TG_API_HASH}')
def bot():
wait(10)
f = open('commit.json')
data = load(f)
f.close()
bot = telegram.Bot(TG_TOKEN, base_url="http://0.0.0.0:8081/bot")
bot.send_photo(TG_POST_ID, open('alpha.png', 'rb'), f'''*Libretube {data['sha'][0:7]} // Alpha*
[{data['commit']['message']}]({data['html_url']})
Signed-off-by: {data['commit']['author']['name']}
''', parse_mode=telegram.ParseMode.MARKDOWN)
bot.send_media_group(TG_POST_ID, [telegram.InputMediaDocument(open('app-universal-debug-signed.apk', 'rb')), telegram.InputMediaDocument(open('app-x86-debug-signed.apk', 'rb')), telegram.InputMediaDocument(open('app-x86_64-debug-signed.apk', 'rb')), telegram.InputMediaDocument(open('app-armeabi-v7a-debug-signed.apk', 'rb')), telegram.InputMediaDocument(open('app-arm64-v8a-debug-signed.apk', 'rb'))])
system('killall -9 python')
if __name__ == '__main__':
multideploy = multiprocessing.Process(target=deploy)
multibot = multiprocessing.Process(target=bot)
multideploy.start()
multibot.start()
multideploy.join()
multibot.join()
import asyncio
from json import load
from os import listdir
from pyrogram import Client
from pyrogram.types import InputMediaDocument
from tgconfig import *
files = listdir()
mediadocuments = [
InputMediaDocument(file) for file in files if file.endswith("signed.apk")
]
with open("commit.json") as f:
data = load(f)
caption = f"""**Libretube {data['sha'][0:7]} // Alpha**
<a href="{data['html_url']}">{data['commit']['message']}</a>
Signed-off-by: {data['commit']['author']['name']}
"""
async def main():
async with Client("libretube", TG_API_ID, TG_API_HASH, bot_token=TG_TOKEN) as app:
await app.send_photo(
int(TG_POST_ID), "https://libre-tube.github.io/images/Alpha.png", caption
)
await app.send_media_group(int(TG_POST_ID), mediadocuments)
asyncio.run(main())

View File

@ -81,15 +81,12 @@ jobs:
continue-on-error: true
run: |
cd archive
curl https://libre-tube.github.io/images/Alpha.png --output alpha.png
chmod 755 ./exec
mv ../tgconfig.py .
echo "TG_TOKEN = '${{ secrets.TG_TOKEN }}'" >> tgconfig.py
echo "TG_API_ID = '${{ secrets.TG_API_ID }}'" >> tgconfig.py
echo "TG_POST_ID = '${{ secrets.TG_POST_ID }}'" >> tgconfig.py
echo "TG_API_HASH = '${{ secrets.TG_API_HASH }}'" >> tgconfig.py
python -m pip install --upgrade pip
pip install python-telegram-bot
python -m pip install --upgrade pip TgCrypto Pyrogram
mv ../.github/tg.py .
mv ../.github/commit.json .
python tg.py