Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Send media groups directly using the Local Bot API Server #600

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/build-kernel-a12.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ jobs:
- name: Setup mutex for uploading
uses: ben-z/[email protected]

- name: Setup Telegram Bot Server
env:
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} && env.API_ID != null && env.API_HASH != null
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ env.API_ID }}
api_hash: ${{ env.API_HASH }}

- name: Build boot images
run: |
export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/build-kernel-a13.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ jobs:
- name: Setup mutex for uploading
uses: ben-z/[email protected]

- name: Setup Telegram Bot Server
env:
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} && env.API_ID != null && env.API_HASH != null
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ env.API_ID }}
api_hash: ${{ env.API_HASH }}

- name: Build boot images
run: |
export AVBTOOL=$GITHUB_WORKSPACE/kernel-build-tools/linux-x86/bin/avbtool
Expand All @@ -110,7 +120,7 @@ jobs:
echo "VERSION: $VERSION"
cd -
bash $GITHUB_WORKSPACE/KernelSU/.github/scripts/build_a13.sh

- name: Display structure of boot files
run: ls -R

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/build-kernel-wsa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ jobs:
name: kernel-WSA-${{ matrix.arch }}-${{ matrix.version }}
path: "${{ env.file_path }}"

- name: Setup Telegram Bot Server
env:
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} && env.API_ID != null && env.API_HASH != null
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ env.API_ID }}
api_hash: ${{ env.API_HASH }}

- name: Post to Telegram
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }}
env:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/build-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ jobs:
uses: ben-z/[email protected]
if: github.event_name != 'pull_request' && steps.need_upload.outputs.UPLOAD == 'true'

- name: Setup Telegram Bot Server
env:
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} && env.API_ID != null && env.API_HASH != null
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ env.API_ID }}
api_hash: ${{ env.API_HASH }}

- name: Upload to telegram
if: github.event_name != 'pull_request' && steps.need_upload.outputs.UPLOAD == 'true'
env:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build-su.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ jobs:
- name: Setup mutex for uploading
uses: ben-z/[email protected]
if: github.event_name != 'pull_request' && steps.need_upload.outputs.UPLOAD == 'true'

- name: Setup Telegram Bot Server
env:
API_ID: ${{ secrets.API_ID }}
API_HASH: ${{ secrets.API_HASH }}
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/main' ) || github.ref_type == 'tag' }} && env.API_ID != null && env.API_HASH != null
uses: zjns/telegram-bot-server@v1
with:
api_id: ${{ env.API_ID }}
api_hash: ${{ env.API_HASH }}

- name: Upload to telegram
if: github.event_name != 'pull_request' && steps.need_upload.outputs.UPLOAD == 'true'
env:
Expand Down
19 changes: 8 additions & 11 deletions scripts/ksubot.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,25 @@ async def main():
print("[+] Uploading to telegram")
check_environ()
print("[+] Files:", sys.argv[1:])
bot = telegram.Bot(BOT_TOKEN)
bot = telegram.Bot(BOT_TOKEN, base_url='http://127.0.0.1:8088/bot')
files = []
paths = sys.argv[1:]
caption = get_caption()
print("[+] Caption: ")
print("---")
print(caption)
print("---")
for one in paths:
if not os.path.exists(one):
print("[-] File not exist: " + one)
for file in paths:
if not os.path.exists(file):
print("[-] File not exist: " + file)
continue
print("[+] Upload: " + one)
msg = await bot.send_document(CACHE_CHAT_ID, one, write_timeout=60, connect_timeout=30)
if one == paths[-1]:
files.append(telegram.InputMediaDocument(msg.document,
print("[+] Upload: " + file)
if file == paths[-1]:
files.append(telegram.InputMediaDocument(media=open(file, "rb"),
caption=caption,
parse_mode=telegram.constants.ParseMode.MARKDOWN_V2))
else:
files.append(telegram.InputMediaDocument(msg.document))
await bot.delete_message(CACHE_CHAT_ID, msg.message_id)
files.append(telegram.InputMediaDocument(media=open(file, "rb")))
print("[+] Sending")
await bot.send_media_group(CHAT_ID, files, message_thread_id=MESSAGE_THREAD_ID)
print("[+] Done!")
Expand All @@ -98,4 +96,3 @@ async def main():
if __name__ == "__main__":
loops = asyncio.new_event_loop()
loops.run_until_complete(asyncio.wait([main()]))