From 37ae57918eb23293d190c83892639d149d9a4357 Mon Sep 17 00:00:00 2001 From: XiaoMengXinX Date: Sun, 17 Jul 2022 22:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=87=AA=E5=8A=A8=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E3=80=8C=E5=9C=A8=E5=8A=A8=E6=80=81=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E6=AD=8C=E6=9B=B2=E3=80=8D=E3=80=81=E3=80=8C=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E7=9A=84=E6=AD=8C=E6=9B=B2=E3=80=8D=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ config_example.json | 3 +++ go.mod | 2 +- go.sum | 4 ++-- main.go | 47 ++++++++++++++++++++++++++++++++++++++++++++- types.go | 3 +++ 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3c3fe09..b6f98b6 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,9 @@ $ ./Fuck163MusicTasks ] } ], + "MusicShareConfig": { // 分享音乐配置 + "MySongID": 114514 // 填入任意一首音乐人名下的歌曲ID + }, "EventSendConfig": { // 发送动态配置 "LagConfig": { // 延时配置,若要完全关闭延时,请将 RandomLag 设为 false,并将 DefaultLag 设为 0 "RandomLag": true, // 是否开启随机延时 diff --git a/config_example.json b/config_example.json index 63376ef..13de3c0 100644 --- a/config_example.json +++ b/config_example.json @@ -18,6 +18,9 @@ ] } ], + "MusicShareConfig": { + "MySongID": 114514 + }, "EventSendConfig": { "LagConfig": { "RandomLag": true, diff --git a/go.mod b/go.mod index b55c1c8..38d47d9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/XiaoMengXinX/Fuck163MusicTasks/v2 go 1.17 require ( - github.com/XiaoMengXinX/Music163Api-Go v0.1.25 + github.com/XiaoMengXinX/Music163Api-Go v0.1.29 github.com/robfig/cron/v3 v3.0.1 github.com/sirupsen/logrus v1.8.1 ) diff --git a/go.sum b/go.sum index 08e5a76..cb9d890 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/XiaoMengXinX/Music163Api-Go v0.1.25 h1:Wli9RTuNTad73cKqLtYQdd1u7B+2MCTNSXF47nlPOXE= -github.com/XiaoMengXinX/Music163Api-Go v0.1.25/go.mod h1:kLU/CkLxKnEJFCge0URvQ0lHt6ImoG1/2aVeNbgV2RQ= +github.com/XiaoMengXinX/Music163Api-Go v0.1.29 h1:c7ekfgo4qgEJ3Wjm9rMhGm7ggN8XqbD1idQka4unJ+Q= +github.com/XiaoMengXinX/Music163Api-Go v0.1.29/go.mod h1:kLU/CkLxKnEJFCge0URvQ0lHt6ImoG1/2aVeNbgV2RQ= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= diff --git a/main.go b/main.go index 3655da2..99fd6e5 100644 --- a/main.go +++ b/main.go @@ -239,6 +239,13 @@ func musicianTasks(userData types.LoginStatusData, data utils.RequestData, autoT } }() switch { + case strings.Contains(autoTasks[i], "分享"): + log.Printf("[%s] 执行分享音乐任务中", userData.Profile.Nickname) + err := shareMusicTask(userData, data) + if err != nil { + log.Println(err) + } + log.Printf("[%s] 分享音乐任务执行完成", userData.Profile.Nickname) case strings.Contains(autoTasks[i], "签到"): log.Printf("[%s] 执行音乐人签到任务中", userData.Profile.Nickname) result, err := api.MusicianSign(data) @@ -306,6 +313,44 @@ func musicianTasks(userData types.LoginStatusData, data utils.RequestData, autoT } } +func shareMusicTask(userData types.LoginStatusData, data utils.RequestData) error { + shareResult, err := api.SongShare(data, config.MusicShareConfig.MySongID) + if err != nil { + return err + } + if shareResult.Code == 200 { + log.Printf("[%s] 分享音乐成功, 歌曲ID: %d", userData.Profile.Nickname, config.MusicShareConfig.MySongID) + } else { + log.Printf("[%s] 分享音乐失败, 原因: %s, 歌曲ID: %d", userData.Profile.Nickname, shareResult.Message, config.MusicShareConfig.MySongID) + } + sendResult, err := api.ShareResource(data, config.MusicShareConfig.MySongID, "song", "") + if err != nil { + return err + } + if sendResult.Code == 200 { + log.Printf("[%s] 发送歌曲分享动态成功, 动态ID: %d, 歌曲ID: %d", userData.Profile.Nickname, sendResult.Event.Id, config.MusicShareConfig.MySongID) + if config.EventSendConfig.LagConfig.LagBetweenSendAndDelete { + randomLag := eventLag.Get() + if randomLag != 0 { + log.Printf("[%s] 延时 %d 秒", userData.Profile.Nickname, randomLag) + time.Sleep(time.Duration(randomLag) * time.Second) + } + } + delResult, err := api.DelEvent(data, sendResult.Event.Id) + if err != nil { + return err + } + if delResult.Code != 200 { + log.Errorf("[%s] 删除动态失败, 动态ID: %d, 代码: %d, 原因: \"%s\"", userData.Profile.Nickname, sendResult.Event.Id, delResult.Code, delResult.Message) + } else { + log.Printf("[%s] 删除动态成功, 动态ID: %d", userData.Profile.Nickname, sendResult.Event.Id) + } + } else { + log.Errorf("[%s] 发送歌曲分享动态, 代码: %d, 原因: \"%s\"", userData.Profile.Nickname, sendResult.Code, sendResult.Message) + } + return nil +} + func getCircleTask(data utils.RequestData) error { if circleID != "" { result, err := api.GetCircle(data, circleID) @@ -671,7 +716,7 @@ func parseCircleID(artistDetail types.ArtistHomepageData) { } func autoTaskAvail(val string) bool { - if strings.Contains(val, "签到") || strings.Contains(val, "动态") || strings.Contains(val, "评论") || strings.Contains(val, "私信") || strings.Contains(val, "mlog") || strings.Contains(val, "主创说") || strings.Contains(val, "云圈") { + if strings.Contains(val, "签到") || strings.Contains(val, "动态") || strings.Contains(val, "评论") || strings.Contains(val, "私信") || strings.Contains(val, "mlog") || strings.Contains(val, "主创说") || strings.Contains(val, "云圈") || strings.Contains(val, "分享") { return true } return false diff --git a/types.go b/types.go index b77f306..72d1b16 100644 --- a/types.go +++ b/types.go @@ -10,6 +10,9 @@ type Config struct { Users []struct { Cookies []*http.Cookie `json:"Cookies"` } `json:"Users"` + MusicShareConfig struct { + MySongID int `json:"MySongID"` + } `json:"MusicShareConfig"` EventSendConfig struct { LagConfig LagConfig `json:"LagConfig"` } `json:"EventSendConfig"`