From 273ecb58d539ead1c2c6824a800ecae1ce084965 Mon Sep 17 00:00:00 2001 From: Tenko Date: Thu, 13 Jun 2024 12:00:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=91=E7=9A=84=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights.example.yaml | 1 + docs/Features.md | 1 + docs/Features_ZH.md | 1 + src/core/bot/bot.go | 1 + src/core/web/depot.go | 85 ++++++++++++++++++++++++++ src/core/web/help.go | 1 + src/core/web/runner.go | 1 + src/plugins/player/depot_handle.go | 38 ++++++++++++ src/plugins/player/player_operation.go | 1 + src/plugins/skland/player_cultivate.go | 56 +++++++++++++++++ template/Depot.tmpl | 43 +++++++++++++ 11 files changed, 229 insertions(+) create mode 100644 src/core/web/depot.go create mode 100644 src/plugins/player/depot_handle.go create mode 100644 src/plugins/skland/player_cultivate.go create mode 100644 template/Depot.tmpl diff --git a/arknights.example.yaml b/arknights.example.yaml index a2e6771..36d827c 100644 --- a/arknights.example.yaml +++ b/arknights.example.yaml @@ -23,6 +23,7 @@ api: telegraph: https://api.telegra.ph/createPage skin_table: https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/excel/skin_table.json nation_table: https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/art/handbookpos_table.json + item_table: https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/zh_CN/gamedata/excel/item_table.json calendar: https://wiki.biligame.com/arknights/index.php?title=MediaWiki:EventCalendar.js&action=raw mysql: diff --git a/docs/Features.md b/docs/Features.md index 0fe96fc..ddd5ce7 100644 --- a/docs/Features.md +++ b/docs/Features.md @@ -49,6 +49,7 @@ This document provides an overview of the features available in the Arknights Te /redeem [code] - Redeem the code. /headhunt - Emulate current gacha pool. /recruit - Check the provided image to find what operator is possible to recruit with provided tags. +/depot - Show the depot items. ``` ## Admin Commands ``` diff --git a/docs/Features_ZH.md b/docs/Features_ZH.md index d57b188..4610b9e 100644 --- a/docs/Features_ZH.md +++ b/docs/Features_ZH.md @@ -50,6 +50,7 @@ /headhunt - 寻访模拟(需要自己更新卡池信息) /recruit - 公招计算(指令需附带图片一起发送) /recruit jp 日服公招计算 +/depot - 查看我的仓库 ``` ## 管理员指令 ``` diff --git a/src/core/bot/bot.go b/src/core/bot/bot.go index a72cd66..bde90e1 100644 --- a/src/core/bot/bot.go +++ b/src/core/bot/bot.go @@ -74,6 +74,7 @@ func Serve() { b.NewCommandProcessor("redeem", player.PlayerHandle) b.NewCommandProcessor("headhunt", system.HeadhuntHandle) b.NewCommandProcessor("calendar", system.CalendarHandle) + b.NewCommandProcessor("depot", player.PlayerHandle) // 图片 b.NewPhotoMessageProcessor("/recruit", system.RecruitHandle) diff --git a/src/core/web/depot.go b/src/core/web/depot.go new file mode 100644 index 0000000..d8ec006 --- /dev/null +++ b/src/core/web/depot.go @@ -0,0 +1,85 @@ +package web + +import ( + "arknights_bot/plugins/account" + "arknights_bot/plugins/skland" + "arknights_bot/utils" + "fmt" + "github.com/gin-gonic/gin" + "github.com/spf13/viper" + "github.com/tidwall/gjson" + "io" + "log" + "net/http" + "sort" + "strconv" +) + +type DepotItem struct { + Name string `json:"name"` + Count string `json:"count"` + Icon string `json:"icon"` + SortId int64 `json:"sortId"` +} + +type ItemTable struct { + Name string `json:"name"` + SortId int64 `json:"sortId"` +} + +var itemMap = make(map[string]ItemTable) + +func init() { + resp, _ := http.Get(viper.GetString("api.item_table")) + r, _ := io.ReadAll(resp.Body) + gjson.ParseBytes(r).Get("items").ForEach(func(key, value gjson.Result) bool { + itemMap[key.String()] = ItemTable{ + Name: value.Get("name").String(), + SortId: value.Get("sortId").Int(), + } + return true + }) +} + +func Depot(r *gin.Engine) { + r.GET("/depot", func(c *gin.Context) { + r.LoadHTMLFiles("./template/Depot.tmpl") + var depotItems []DepotItem + var userAccount account.UserAccount + var skAccount skland.Account + userId, _ := strconv.ParseInt(c.Query("userId"), 10, 64) + uid := c.Query("uid") + sklandId := c.Query("sklandId") + utils.GetAccountByUserIdAndSklandId(userId, sklandId).Scan(&userAccount) + skAccount.Hypergryph.Token = userAccount.HypergryphToken + skAccount.Skland.Token = userAccount.SklandToken + skAccount.Skland.Cred = userAccount.SklandCred + playerCultivate, err := skland.GetPlayerCultivate(uid, skAccount) + if err != nil { + log.Println(err) + return + } + for _, item := range playerCultivate.Items { + if item.Count != "0" { + var depotItem DepotItem + depotItem.Name = itemMap[item.ID].Name + depotItem.Count = item.Count + count, _ := strconv.Atoi(depotItem.Count) + if count >= 10000 { + depotItem.Count = strconv.Itoa(count/10000) + "万" + } + depotItem.SortId = itemMap[item.ID].SortId + // 图标 + paintingName := fmt.Sprintf("道具_带框_%s.png", depotItem.Name) + m := utils.Md5(paintingName) + path := "https://media.prts.wiki/thumb" + fmt.Sprintf("/%s/%s/", m[:1], m[:2]) + depotItem.Icon = path + paintingName + "/75px-" + paintingName + depotItems = append(depotItems, depotItem) + } + } + sort.Slice(depotItems, func(i, j int) bool { + return depotItems[i].SortId < depotItems[j].SortId + }) + c.HTML(http.StatusOK, "Depot.tmpl", depotItems) + }) +} diff --git a/src/core/web/help.go b/src/core/web/help.go index 803ccf6..627144c 100644 --- a/src/core/web/help.go +++ b/src/core/web/help.go @@ -64,6 +64,7 @@ func Help(r *gin.Engine) { publicCmds = append(publicCmds, Cmd{Cmd: "/headhunt", Desc: "寻访模拟", Param: "", IsBind: false}) publicCmds = append(publicCmds, Cmd{Cmd: "/recruit", Desc: "公招计算(图片附带)", Param: "", IsBind: false}) publicCmds = append(publicCmds, Cmd{Cmd: "/calendar", Desc: "活动日历", Param: "", IsBind: false}) + publicCmds = append(publicCmds, Cmd{Cmd: "/depot", Desc: "我的仓库", Param: "", IsBind: true}) // 管理员指令 adminCmds = append(adminCmds, Cmd{Cmd: "/news", Desc: "开启/关闭动态推送", Param: "", IsBind: false}) diff --git a/src/core/web/runner.go b/src/core/web/runner.go index beb659a..d64ac9f 100644 --- a/src/core/web/runner.go +++ b/src/core/web/runner.go @@ -23,6 +23,7 @@ func Start() { Material(r) Recruit(r) Calendar(r) + Depot(r) port := viper.GetString("http.port") err := r.Run(":" + port) if err != nil { diff --git a/src/plugins/player/depot_handle.go b/src/plugins/player/depot_handle.go new file mode 100644 index 0000000..00b6979 --- /dev/null +++ b/src/plugins/player/depot_handle.go @@ -0,0 +1,38 @@ +package player + +import ( + bot "arknights_bot/config" + "arknights_bot/plugins/account" + "arknights_bot/plugins/commandoperation" + "arknights_bot/utils" + "fmt" + tgbotapi "github.com/ijnkawakaze/telegram-bot-api" + "github.com/spf13/viper" +) + +type PlayerOperationDepot struct { + commandoperation.OperationAbstract +} + +// BoxHandle 我的干员 + +func (_ PlayerOperationDepot) Run(uid string, userAccount account.UserAccount, chatId int64, message *tgbotapi.Message) error { + messageId := message.MessageID + sendAction := tgbotapi.NewChatAction(chatId, "upload_document") + bot.Arknights.Send(sendAction) + + port := viper.GetString("http.port") + pic := utils.Screenshot(fmt.Sprintf("http://localhost:%s/depot?userId=%d&uid=%s&sklandId=%s", port, userAccount.UserNumber, uid, userAccount.SklandId), 0, 1.5) + if pic == nil { + sendMessage := tgbotapi.NewMessage(chatId, fmt.Sprintf("生成图片失败,token可能已失效请[重设token](https://t.me/%s)。", viper.GetString("bot.name"))) + sendMessage.ParseMode = tgbotapi.ModeMarkdownV2 + sendMessage.ReplyToMessageID = messageId + bot.Arknights.Send(sendMessage) + return nil + } + + sendDocument := tgbotapi.NewDocument(chatId, tgbotapi.FileBytes{Bytes: pic, Name: "depot.jpg"}) + sendDocument.ReplyToMessageID = messageId + bot.Arknights.Send(sendDocument) + return nil +} diff --git a/src/plugins/player/player_operation.go b/src/plugins/player/player_operation.go index 467d2de..32f0ddb 100644 --- a/src/plugins/player/player_operation.go +++ b/src/plugins/player/player_operation.go @@ -15,6 +15,7 @@ var ( "missing": PlayerOperationMissing{}, "base": PlayerOperationBase{}, "redeem": PlayerOperationRedeem{}, + "depot": PlayerOperationDepot{}, } ) diff --git a/src/plugins/skland/player_cultivate.go b/src/plugins/skland/player_cultivate.go new file mode 100644 index 0000000..52fd166 --- /dev/null +++ b/src/plugins/skland/player_cultivate.go @@ -0,0 +1,56 @@ +package skland + +import ( + "encoding/json" + "github.com/starudream/go-lib/core/v2/gh" + "github.com/tidwall/gjson" + "log" +) + +type PlayerCultivate struct { + Characters []struct { + ID string `json:"id"` + Level int `json:"level"` + EvolvePhase int `json:"evolvePhase"` + MainSkillLevel int `json:"mainSkillLevel"` + Skills []struct { + ID string `json:"id"` + Level int `json:"level"` + } `json:"skills"` + Equips []struct { + ID string `json:"id"` + Level int `json:"level"` + } `json:"equips"` + PotentialRank int `json:"potentialRank"` + } `json:"characters"` + Items []struct { + ID string `json:"id"` + Count string `json:"count"` + } `json:"items"` +} + +func GetPlayerCultivate(uid string, account Account) (*PlayerCultivate, error) { + var playerCultivate *PlayerCultivate + account, err := RefreshToken(account) + if err != nil { + log.Println(err.Error()) + return playerCultivate, err + } + playerCultivateStr, err := getPlayerCultivateStr(uid, account.Skland) + if err != nil { + return playerCultivate, err + } + + json.Unmarshal([]byte(gjson.Get(playerCultivateStr, "data").String()), &playerCultivate) + return playerCultivate, nil +} + +func getPlayerCultivateStr(uid string, skland AccountSkland) (string, error) { + req := SKR().SetQueryParams(gh.MS{"uid": uid}) + return SklandRequestPlayerData(req, "GET", "/api/v1/game/cultivate/player", skland) +} + +func getPlayerCultivateCharacterStr(characterId string, skland AccountSkland) (string, error) { + req := SKR().SetQueryParams(gh.MS{"characterId": characterId}) + return SklandRequestPlayerData(req, "GET", "/api/v1/game/cultivate/character", skland) +} diff --git a/template/Depot.tmpl b/template/Depot.tmpl new file mode 100644 index 0000000..b649225 --- /dev/null +++ b/template/Depot.tmpl @@ -0,0 +1,43 @@ + + + + 仓库 + + + +
+ {{range .}} +
+ +
{{.Count}}
+ +
+ {{end}} +
+ + \ No newline at end of file