-
Notifications
You must be signed in to change notification settings - Fork 644
/
release.py
59 lines (45 loc) · 1.18 KB
/
release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import json
import requests
TELEGRAM_BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
TAG = os.getenv("TAG")
IS_RELEASE = "+" not in TAG
CHAT_ID = "@FlClash"
API_URL = f"http://localhost:8081/bot{TELEGRAM_BOT_TOKEN}/sendMediaGroup"
DIST_DIR = os.path.join(os.getcwd(), "dist")
release = os.path.join(os.getcwd(), "release.md")
text = ""
media = []
files = {}
i = 1
for file in os.listdir(DIST_DIR):
file_path = os.path.join(DIST_DIR, file)
if os.path.isfile(file_path):
file_key = f"file{i}"
media.append({
"type": "document",
"media": f"attach://{file_key}"
})
files[file_key] = open(file_path, 'rb')
i += 1
if TAG:
text += f"\n**{TAG}**\n"
if IS_RELEASE:
text += f"\nhttps://github.com/chen08209/FlClash/releases/tag/{TAG}\n"
if os.path.exists(release):
text += "\n"
with open(release, 'r') as f:
text += f.read()
text += "\n"
if media:
media[-1]["caption"] = text
media[-1]["parse_mode"] = "Markdown"
response = requests.post(
API_URL,
data={
"chat_id": CHAT_ID,
"media": json.dumps(media)
},
files=files
)
print("Response JSON:", response.json())