Skip to content

Commit

Permalink
新增我的仓库功能
Browse files Browse the repository at this point in the history
  • Loading branch information
IJNKAWAKAZE committed Jun 13, 2024
1 parent b699266 commit 273ecb5
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions arknights.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
1 change: 1 addition & 0 deletions docs/Features_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
/headhunt - 寻访模拟(需要自己更新卡池信息)
/recruit - 公招计算(指令需附带图片一起发送)
/recruit jp 日服公招计算
/depot - 查看我的仓库
```
## 管理员指令
```
Expand Down
1 change: 1 addition & 0 deletions src/core/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
85 changes: 85 additions & 0 deletions src/core/web/depot.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
1 change: 1 addition & 0 deletions src/core/web/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
1 change: 1 addition & 0 deletions src/core/web/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 38 additions & 0 deletions src/plugins/player/depot_handle.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions src/plugins/player/player_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
"missing": PlayerOperationMissing{},
"base": PlayerOperationBase{},
"redeem": PlayerOperationRedeem{},
"depot": PlayerOperationDepot{},
}
)

Expand Down
56 changes: 56 additions & 0 deletions src/plugins/skland/player_cultivate.go
Original file line number Diff line number Diff line change
@@ -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)
}
43 changes: 43 additions & 0 deletions template/Depot.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<meta name="referrer" content="no-referrer" />
<title>仓库</title>
<style>
body {
margin: 0;
}
#main {
width: 850px;
background-color: #2e3031;
}
.item {
display: inline-flex;
flex-direction: column;
align-items: center;
width: 80px;
}
.icon {
width: 75px;
}
.count {
position: absolute;
color: white;
background-color: rgba(0, 0 ,0 ,0.5);
font-size: 12px;
margin-top: 50px;
margin-right: -30px;
}
</style>
</head>
<body>
<div id="main">
{{range .}}
<div class="item">
<img class="icon" src="{{.Icon}}" onerror="this.src='assets/common/amiya.png'"/>
<div class="count">{{.Count}}</div>
<!--<div>{{.Name}}</div>-->
</div>
{{end}}
</div>
</body>
</html>

0 comments on commit 273ecb5

Please sign in to comment.