This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d48e6f
commit 844d046
Showing
8 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package kuro | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/starudream/go-lib/core/v2/gh" | ||
|
||
"github.com/starudream/kuro-task/config" | ||
) | ||
|
||
type SignForumData struct { | ||
GainVoList []*GainVo `json:"gainVoList"` | ||
ContinueDays int `json:"continueDays"` | ||
} | ||
|
||
type GainVo struct { | ||
GainTyp int `json:"gainTyp"` | ||
GainValue int `json:"gainValue"` | ||
} | ||
|
||
func SignForum(gid int, account config.Account) (*SignForumData, error) { | ||
req := R(account).SetFormData(gh.MS{"gameId": strconv.Itoa(gid)}) | ||
return Exec[*SignForumData](req, "POST", "/user/signIn") | ||
} | ||
|
||
type GetSignForumData struct { | ||
ContinueDays int `json:"continueDays"` | ||
HasSignIn bool `json:"hasSignIn"` | ||
} | ||
|
||
func GetSignForum(gid int, account config.Account) (*GetSignForumData, error) { | ||
req := R(account).SetFormData(gh.MS{"gameId": strconv.Itoa(gid)}) | ||
return Exec[*GetSignForumData](req, "POST", "/user/signIn/info") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kuro | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/starudream/go-lib/core/v2/utils/testutil" | ||
|
||
"github.com/starudream/kuro-task/config" | ||
) | ||
|
||
func TestSignForum(t *testing.T) { | ||
data, err := SignForum(GameIdMC, config.C().FirstAccount()) | ||
testutil.LogNoErr(t, err, data) | ||
} | ||
|
||
func TestGetSignForum(t *testing.T) { | ||
data, err := GetSignForum(GameIdMC, config.C().FirstAccount()) | ||
testutil.LogNoErr(t, err, data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package job | ||
|
||
import ( | ||
"cmp" | ||
"fmt" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/starudream/go-lib/core/v2/slog" | ||
|
||
"github.com/starudream/kuro-task/api/kuro" | ||
"github.com/starudream/kuro-task/config" | ||
) | ||
|
||
type SignForumRecord struct { | ||
GameId int | ||
GameName string | ||
HasSigned bool | ||
} | ||
|
||
type SignForumRecords []SignForumRecord | ||
|
||
func (rs SignForumRecords) Name() string { | ||
return "库街区每日任务" | ||
} | ||
|
||
func (rs SignForumRecords) Success() string { | ||
vs := []string{rs.Name() + "完成"} | ||
for i := 0; i < len(rs); i++ { | ||
vs = append(vs, | ||
fmt.Sprintf("在版区【%s】", rs[i].GameName), | ||
fmt.Sprintf(" 打卡成功"), | ||
) | ||
} | ||
return strings.Join(vs, "\n") | ||
} | ||
|
||
func SignForum(account config.Account) (SignForumRecords, error) { | ||
_, err := kuro.GetUser(account) | ||
if err != nil { | ||
return nil, fmt.Errorf("get user error: %w", err) | ||
} | ||
return SignForumGames(account) | ||
} | ||
|
||
func SignForumGames(account config.Account) (SignForumRecords, error) { | ||
var records []SignForumRecord | ||
for id, name := range kuro.GameNames { | ||
record, err := SignForumGame(kuro.GameIdMC, account) | ||
record.GameId = id | ||
record.GameName = name | ||
slog.Info("sign forum record: %+v", record) | ||
if err != nil { | ||
slog.Error("sign forum error: %w", err) | ||
continue | ||
} | ||
records = append(records, record) | ||
} | ||
slices.SortFunc(records, func(a, b SignForumRecord) int { | ||
return cmp.Compare(a.GameId, b.GameId) | ||
}) | ||
return records, nil | ||
} | ||
|
||
func SignForumGame(gid int, account config.Account) (record SignForumRecord, err error) { | ||
today, err := kuro.GetSignForum(gid, account) | ||
if err != nil { | ||
err = fmt.Errorf("get sign forum error: %w", err) | ||
return | ||
} | ||
|
||
record.HasSigned = today.HasSignIn | ||
|
||
if today.HasSignIn { | ||
return | ||
} | ||
|
||
_, err = kuro.SignForum(gid, account) | ||
if err != nil { | ||
err = fmt.Errorf("sign forum error: %w", err) | ||
return | ||
} | ||
|
||
// todo: daily task for forum posts | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters