Skip to content

Commit

Permalink
Merge pull request #242 from Controllerdestiny/caiiiiii
Browse files Browse the repository at this point in the history
工作流:支持TRHUB和BBSTR |  文档:主页文档引导下载
  • Loading branch information
ACaiCat authored Jun 20, 2024
2 parents bcdcab2 + d8618f5 commit 7cb1265
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/plugins_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
sudo pip install beautifulsoup4
- name: 更新论坛
continue-on-error: true
env:
PYTHONIOENCODING: 'utf-8'
run:
Expand Down
154 changes: 151 additions & 3 deletions ForumHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
print(f"论坛自动更新脚本 (by Cai😘)")
print(f"登录名: {name}")
print(f"密码: {password}")


# tr.monika.love
# 创建会话
session = rq.Session()
resp = session.get("https://tr.monika.love/")
Expand Down Expand Up @@ -71,9 +74,154 @@
resp = session.post("https://tr.monika.love/resources/104/edit",data=data)
res = resp.json()
if res['status'] == 'ok':
print(f"修改成功: {res}")
print(f"[MONIKA]修改成功: {res}")
else:
print(f"[MONIKA]修改失败: {res}")
except:
print(f"[MONIKA]修改失败!{resp.text}")

# trhub.cn
# 创建会话
session = rq.Session()
resp = session.get("https://trhub.cn/")

# 获取xf_token
soup = BeautifulSoup(resp.text, 'html.parser')
data_csrf = soup.html['data-csrf']

# 模拟登录
data = {
"_xfToken": data_csrf,
"login":name,
"password": password,
"remember": 0,
"_xfRedirect": "https://trhub.cn/",
}
session.post("https://trhub.cn/login/login",data=data,allow_redirects=True)

# 使用GithubAPI转换MD到Html
with open('README.md', 'r',encoding='utf-8') as file:
md = file.read()
headers = {
"Accept": "application/vnd.github+json",
#"Authorization": "Bearer <YOUR-TOKEN>",
"X-GitHub-Api-Version": "2022-11-28"
}

# 修复插件列表路径
md = re.sub(r'\b[^(\[]*\/README.md\b', lambda x: "https://gitee.com/kksjsj/TShockPlugin/blob/master/" + x.group(), md)

# 编辑论坛仓库帖子
data = {
"text": md
}
html = rq.post("https://api.github.com/markdown", headers=headers, data=json.dumps(data)).text
data = {
"_xfToken": data_csrf,
"prefix_id": 0,
"title": "TShock插件收集仓库(自动更新版)",
"message_html": f"{html}",
# "attachment_hash": "291d0c03815801596ec54fa208a79bfb",
# "attachment_hash_combined": {
# "type": "resource_update",
# "context": {
# "resource_update_id": 130
# },
# "hash": "291d0c03815801596ec54fa208a79bfb"
# },
"_xfRequestUri": "/threads/github-action-test.43/",
"_xfWithData": 1,
"_xfResponseType": "json"
}
try:
resp = session.post("https://trhub.cn/posts/107/edit",data=data)
res = resp.json()
if res['status'] == 'ok':
print(f"[TRHUB]修改成功: {res}")
else:
print(f"[TRHUB]修改失败: {res}")
except:
print(f"[TRHUB]修改失败!{resp.text}")

# BBSTR
name = "Cai233"
# 创建会话
session = rq.Session()
resp = session.get("https://tr.lizigo.cn/")

# 获取xf_token
soup = BeautifulSoup(resp.text, 'html.parser')
data_csrf = soup.html['data-csrf']


# 模拟登录
data = {
"_xfToken": data_csrf,
"login":name,
"password": password,
"remember": 0,
"_xfRedirect": "https://tr.lizigo.cn/",
}
session.post("https://tr.lizigo.cn/login/login",data=data,allow_redirects=True)


# 使用GithubAPI转换MD到Html
with open('README.md', 'r',encoding='utf-8') as file:
md = file.read()
headers = {
"Accept": "application/vnd.github+json",
#"Authorization": "Bearer <YOUR-TOKEN>",
"X-GitHub-Api-Version": "2022-11-28"
}

# 修复插件列表路径
md = re.sub(r'\b[^(\[]*\/README.md\b', lambda x: "https://gitee.com/kksjsj/TShockPlugin/blob/master/" + x.group(), md)

# 编辑论坛仓库帖子
data = {
"text": md
}
html = rq.post("https://api.github.com/markdown", headers=headers, data=json.dumps(data)).text
data = {
"title": "Shock插件收集仓库(自动更新版)",
"tag_line": "此帖会自动更新插件列表",
"custom_fields[1]": "TShock Chinese Plugins Collection",
"custom_fields[2]": "TShock插件收集仓库",
"custom_fields[3]": "2",
"custom_fields[4]": "0",
"custom_fields[5][]": "0",
"custom_fields[5][]": "1",
"custom_fields[5][]": "2",
"custom_fields[5][]": "3",
"custom_fields[5][]": "4",
"custom_fields[5][]": "5",
"custom_fields[5][]": "6",
"custom_fields[5][]": "7",
"custom_fields[6][]": "0",
"custom_fields[7][]": "6",
"custom_fields[8]": "看情况",
"custom_fields[9]": "https://github.com/Controllerdestiny/TShockPlugin/",
"custom_fields[10]": "https://github.com/Controllerdestiny/TShockPlugin/",
"custom_fields[11]": "TShock最新版本",
"description_html": html,
"external_url": "https://github.moeyy.xyz/https://github.com/Controllerdestiny/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip",
"alt_support_url": "",
"icon_action": "custom",
"_xfToken": data_csrf,
"_xfRequestUri": "/resources/167/edit",
"_xfWithData": "1",
"_xfResponseType": "json"
}



try:
resp = session.post("https://tr.lizigo.cn/resources/167/edit",data=data)
res = resp.json()
if res['status'] == 'ok':
print(f"[BBSTR]修改成功: {res}")
else:
print(f"修改失败: {res}")
print(f"[BBSTR]修改失败: {res}")
except:
print(f"修改失败!{resp.text}")
print(f"[BBSTR]修改失败!{resp.text}")

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@
- 我们将持续收集优质的 `TShock` 插件,进行及时的更新。并跟进`TShock`的最新版本。
- 如果你也想加入我们,请按照下方`开发者注意事项`的规定对本仓库`Pull Request`


## 使用者注意事项

- 注意有些插件可能需要前置,请查看下方列表安装前置插件。
- 每个插件都有一个使用说明,在下方列表点击超链查看具体说明事项。
- 听说喜欢给仓库点星星的人,插件都不容易报错

## 下载

- 国内镜像: [Plugins.zip](https://github.moeyy.xyz/https://github.com/Controllerdestiny/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip)
- 本仓库: [Plugins.zip](https://github.com/Controllerdestiny/TShockPlugin/releases/tag/V1.0.0.0)


## 开发者注意事项

> 代码规范
Expand Down

0 comments on commit 7cb1265

Please sign in to comment.