Skip to content

Commit 1834605

Browse files
committed
feat: auto-bgi-1.3
新增更新指定脚本功能 读取狗粮版本号,判断是否更新 修改一条龙进度问题 修复一键更新bug
1 parent 8cb71ce commit 1834605

File tree

7 files changed

+120
-45
lines changed

7 files changed

+120
-45
lines changed

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@
4242
| OneLongHour | 每天一条龙启动的小时,前面不能有0,比如1点启动,不能写01 |
4343
| OneLongMinute | 每天一条龙启动的分钟,前面不能有0,比如1分启动,不能写01 |
4444
| | 设置好了OneLongHour和OneLongMinute,将会每天定时启动一条龙 |
45+
| isMoLaSum | 在其他里面有一个收益摩拉统计,是否开启,配合米游社的Cookie统计,如果不需要取消掉,打开网页速度会快点:true/false |
4546
| webhookURL | 企业微信机器人地址 |
4647
| content | 当bgi关闭的时候,会发送通知,这个是需要发送什么 |
4748
| configNames | 这个是你的一条龙配置的名称,根据今天周几,来启动哪一个一条龙,必须要有7个,从星期天开始,例子:"configNames": ["我的","默认配置","我的","我的","我的","我的","我的"]<br />表示星期天启动我的配置单,星期一执行默认配置类推。在一条龙的配置组名称后面加上数字,比如:挖矿-0-2-4。意思是这个配置组将会在星期天,星期二,星期四启动,其他时间不启动。每天都要执行的不用加数字,autobgi只控制加数字的,没有加数字的,原来是怎么样就是怎么样。 |
4849
| BagStatistics | 背包统计功能,需要配合仓库的背包统计js一起使用,将你需要关注的材料填上,英文逗号隔开(如果你导入了摩拉log的脚本,会自动加入统计,这里不需要填写摩拉) |
4950
| post | 修改默认端口,格式:(:8082) |
5051
| backups | 指定备份文件或者文件夹,具体格式看例子,User文件夹是默认备份的,将会打包成一个压缩包,在autobgi目录的Users文件夹下 |
52+
| jsName | js脚本一键更新,自动更新js,此功能不适用所有脚本,谨慎使用,已经测试的脚本我已经加进去了,多个脚本填写方式:["jsName1","jsName2"]。填写脚本的文件名字 |
53+
| isControlGroup | 是否控制调度器,就是配置组带数字的要不要控制,如果是茶包s老师的bgi,请填:false |
54+
| Cookie | 米游社的cookie,如果需要摩拉统计,就填上 |
55+
56+
5157

5258

5359

@@ -58,14 +64,18 @@
5864
"BetterGIAddress": "D:\\subject\\lua\\BetterGI",
5965
"isStartTimeLong": false,
6066
"isMysSignIn": false,
67+
"isMoLaSum": false,
6168
"OneLongHour": 11,
6269
"OneLongMinute": 4,
6370
"webhookURL": "https://qyapi.weixin.qq.com",
6471
"content": "Bgi破溃了",
65-
"configNames": ["我的","默认配置","我的","我的","我的","我的","我的"],
66-
"BagStatistics": "晶核,大英雄的经验,水晶块,魔晶块,萃凝晶,苍晶螺",
72+
"configNames": ["我的","我的","我的","我的","我的","我的","我的"],
73+
"BagStatistics": "晶核,大英雄的经验,水晶块,萃凝晶,苍晶螺,紫晶块,星银矿石",
6774
"post": ":8082",
68-
"backups": ["JsScript\\AutoArtifactsPro\\record.txt","AutoPathing\\矿物\\萃凝晶"]
75+
"backups": ["JsScript\\AutoArtifactsPro\\records\\默认账户.txt"],
76+
"jsName": ["AutoArtifactsPro"],
77+
"isControlGroup": true,
78+
"Cookie": ""
6979
}
7080
```
7181

@@ -75,11 +85,7 @@
7585

7686
这个是测试坐标是否设置对的,通过这个按钮启动的一条龙,配置组将被数字规则控制。这个按钮如果可以正常启动一条龙,那么定时器大概率是没有问题,到时候自动启动。
7787

78-
## 关闭bgi
79-
80-
字面意思
81-
82-
## 关闭原神(启动器)
88+
## 关闭bgi(原神,启动器)
8389

8490
字面意思
8591

@@ -107,6 +113,10 @@
107113

108114
指定备份文件或者文件夹,具体格式看例子,User文件夹是默认备份的,将会打包成一个压缩包,在autobgi目录的Users文件夹下
109115

116+
## 更新指定脚本
117+
118+
可以一键更新填写好的脚本
119+
110120
# 结尾
111121

112122
有任何问题或者想法,可以加我qq:485595674

bgiStatus/BgiStatus.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,31 @@ func GetGroupP(group string) string {
510510
return fmt.Sprintf("%d/%d", gouliangLines, totalLines)
511511
}
512512

513+
// 读取manifest.json的version号
514+
func ReadVersion(filePath string) string {
515+
// 打开文件
516+
Path := filepath.Join(filePath, "manifest.json")
517+
file, err := os.Open(Path)
518+
if err != nil {
519+
fmt.Println("打开文件失败:", err)
520+
}
521+
defer file.Close()
522+
// 文件内容转map
523+
var data map[string]interface{}
524+
decoder := json.NewDecoder(file)
525+
err = decoder.Decode(&data)
526+
if err != nil {
527+
return "未知版本"
528+
}
529+
// 获取version
530+
version, ok := data["version"].(string)
531+
if !ok {
532+
return "未知版本"
533+
}
534+
return version
535+
536+
}
537+
513538
func GetAutoArtifactsPro() ([]DogFood, error) {
514539
// 获取当前目录下所有 .txt 文件
515540
files, err := filepath.Glob(fmt.Sprintf("%s\\User\\JsScript\\AutoArtifactsPro\\records\\*.txt", Config.BetterGIAddress))
@@ -1146,3 +1171,56 @@ func GetGroupPInfo() string {
11461171

11471172
return string(s1)
11481173
}
1174+
1175+
func AutoJs() string {
1176+
1177+
url := "https://github.com/babalae/bettergi-scripts-list/archive/refs/heads/main.zip"
1178+
zipFile := "main.zip"
1179+
err := downloadFile(zipFile, url)
1180+
if err != nil {
1181+
return "下载失败"
1182+
}
1183+
err2 := unzipRepo(zipFile, "repo", "repo/")
1184+
if err2 != nil {
1185+
return "解压失败"
1186+
}
1187+
1188+
jsNames := Config.JsName
1189+
repoDir := "repo/js"
1190+
1191+
for _, jsName := range jsNames {
1192+
subFolderPath, err := findSubFolder(repoDir, jsName)
1193+
if err != nil {
1194+
autoLog.Sugar.Errorf("查找子文件夹失败: %v", err)
1195+
return fmt.Sprintf("未找到子文件夹: %s", jsName)
1196+
}
1197+
1198+
// 找到子文件夹后,执行复制操作
1199+
targetPath := filepath.Join(Config.BetterGIAddress, "User", "JsScript", jsName)
1200+
err2 := copy.Copy(subFolderPath, targetPath)
1201+
if err2 != nil {
1202+
fmt.Println(err2)
1203+
}
1204+
autoLog.Sugar.Infof("Js脚本: %s 已更新", subFolderPath)
1205+
}
1206+
os.RemoveAll("repo")
1207+
os.RemoveAll("main.zip")
1208+
1209+
return "备份成功"
1210+
}
1211+
1212+
// 查找 repo 目录下是否存在名为 targetFolder 的子文件夹
1213+
func findSubFolder(root string, targetFolder string) (string, error) {
1214+
entries, err := os.ReadDir(root)
1215+
if err != nil {
1216+
return "", err
1217+
}
1218+
1219+
for _, entry := range entries {
1220+
if entry.IsDir() && entry.Name() == targetFolder {
1221+
return filepath.Join(root, entry.Name()), nil
1222+
}
1223+
}
1224+
1225+
return "", fmt.Errorf("未找到子文件夹: %s", targetFolder)
1226+
}

config/Config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type config struct {
2727
BasePath string `json:"basePath"`
2828
IsMoLaSum bool `json:"isMoLaSum" comment:"是否计算摩拉"`
2929
IsControlGroup bool `json:"isControlGroup" comment:"是否控制配置组"`
30+
JsName []string `json:"jsName" comment:"需要更新的js名称"`
3031
}
3132

3233
var Cfg config

control/Control.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/vcaesar/imgo"
99
"io"
1010
"net/http"
11-
"net/url"
12-
"os"
1311
"os/exec"
1412
"syscall"
1513
"time"
@@ -217,33 +215,6 @@ func HttpGet(url string) error {
217215
return fmt.Errorf("状态码: %d", resp.StatusCode)
218216
}
219217

220-
func GetMysQDXy() {
221-
currentDir, _ := os.Getwd()
222-
223-
baseURL := "http://127.0.0.1:8888/qdXy"
224-
params := url.Values{}
225-
params.Add("te", currentDir+"\\modeImage\\qdModel.png")
226-
params.Add("ta", currentDir+"\\modeImage\\qdAll.png")
227-
fullURL := fmt.Sprintf("%s?%s", baseURL, params.Encode())
228-
229-
// 发送 GET 请求
230-
resp, err := http.Get(fullURL)
231-
if err != nil {
232-
fmt.Println("请求失败:", err)
233-
return
234-
}
235-
defer resp.Body.Close()
236-
237-
// 读取响应
238-
body, err := io.ReadAll(resp.Body)
239-
if err != nil {
240-
fmt.Println("读取响应失败:", err)
241-
return
242-
}
243-
244-
fmt.Println("响应内容:", string(body))
245-
}
246-
247218
func GetMysSignLog() string {
248219
readLogURL := "http://127.0.0.1:8888/read-log"
249220
resp, err := http.Get(readLogURL)

html/index.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,16 @@ <h1 id="running">软件运行状态:</h1>
145145
<h1 id="jsProgress">JS:</h1>
146146

147147
<button onclick="oneLongBtn()">一条龙启动</button>
148-
<button onclick="closeBgiBtn()">关闭BGI</button>
149-
<button onclick="closeYuanShenBtn()">关闭原神(启动器)</button>
148+
<button onclick="closeBgiBtn()">关闭BGI(原神,启动器)</button>
149+
<!-- <button onclick="closeYuanShenBtn()">关闭原神(启动器)</button>-->
150150
<button onclick="todayHarvestBtn()">查看收获前10</button>
151151
<button onclick="BagStatisticsBtn()">背包统计</button>
152152
<button onclick="listGroupsBtn()">调度器</button>
153153
<button onclick="realTimeLogBtn()">实时日志</button>
154154
<button onclick="getAutoArtifactsProBtn()">查看狗粮日志</button>
155155
<!-- <button onclick="getAutoUpdateJsAndPathingBtn()">更新脚本和地图追踪</button>-->
156156
<button onclick="getBackupBtn()">备份user文件和指定文件</button>
157+
<button onclick="autoJsBtn()">更新指定脚本</button>
157158
<button onclick="otherBtn()">其他</button>
158159
</div>
159160

@@ -238,9 +239,15 @@ <h1 id="jsProgress">JS:</h1>
238239
window.location.href = '/other';
239240
}
240241

242+
function autoJsBtn() {
243+
fetch('/autoJs', { method: 'POST' })
244+
.then(res => alert(res.ok ? "更新成功!" : "更新失败!"))
245+
.catch(err => alert("请求出错:" + err));
246+
}
247+
241248
function getBackupBtn() {
242249
fetch('/backup', { method: 'POST' })
243-
.then(res => alert(res.ok ? "备份成功!" : "备份失败!"))
250+
.then(res => alert(res.ok ? res.data : "备份失败!"))
244251
.catch(err => alert("请求出错:" + err));
245252
}
246253

main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,19 @@ func main() {
479479
pro, err := bgiStatus.GetAutoArtifactsPro()
480480
autoLog.Sugar.Infof("狗粮记录:%s", pro)
481481

482+
//获取版本号
483+
version := bgiStatus.ReadVersion(fmt.Sprintf("%s\\User\\JsScript\\AutoArtifactsPro", Config.BetterGIAddress))
484+
482485
if err != nil {
483486
// 传递给模板
484487
context.HTML(http.StatusOK, "AutoArtifactsPro.html", gin.H{
485-
"title": "狗粮收益查询",
488+
"title": "狗粮收益查询" + "【" + version + "】",
486489
"items": nil,
487490
})
488491
return
489492
}
490493
context.HTML(http.StatusOK, "AutoArtifactsPro.html", gin.H{
491-
"title": "狗粮收益查询",
494+
"title": "狗粮收益查询" + "【" + version + "】",
492495
"items": pro,
493496
})
494497

@@ -586,9 +589,11 @@ func main() {
586589
})
587590
})
588591

589-
//测试
590-
ginServer.GET("/test", func(context *gin.Context) {
591-
control.GetMysQDXy()
592+
//自动更新Js
593+
ginServer.POST("/autoJs", func(context *gin.Context) {
594+
js := bgiStatus.AutoJs()
595+
autoLog.Sugar.Infof("更新Js:%s", js)
596+
context.JSON(http.StatusOK, gin.H{"status": "received", "data": js})
592597
})
593598

594599
//读取statuc文件夹所有的图片

task/Task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ func ChangeTaskEnabledList() error {
214214
//builder.WriteString(fmt.Sprintf("%s:%v", s, true))
215215
builder.WriteString(fmt.Sprintf("%s:%s", s, "执行"))
216216
builder.WriteString("\n")
217+
218+
oneLongLog.WriteString(fmt.Sprintf("%s:%s", s, "执行"))
219+
oneLongLog.WriteString("\n")
217220
continue
218221
} else {
219222
autoLog.Sugar.Infof("配置组:[" + s + "]还未到执行时间")

0 commit comments

Comments
 (0)