Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
新增自动完成「在动态分享歌曲」、「分享自己的歌曲」任务
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoMengXinX committed Jul 17, 2022
1 parent d72a16e commit 37ae579
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ $ ./Fuck163MusicTasks
]
}
],
"MusicShareConfig": { // 分享音乐配置
"MySongID": 114514 // 填入任意一首音乐人名下的歌曲ID
},
"EventSendConfig": { // 发送动态配置
"LagConfig": { // 延时配置,若要完全关闭延时,请将 RandomLag 设为 false,并将 DefaultLag 设为 0
"RandomLag": true, // 是否开启随机延时
Expand Down
3 changes: 3 additions & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
]
}
],
"MusicShareConfig": {
"MySongID": 114514
},
"EventSendConfig": {
"LagConfig": {
"RandomLag": true,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
47 changes: 46 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 37ae579

Please sign in to comment.