-
Notifications
You must be signed in to change notification settings - Fork 6
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
b699266
commit 273ecb5
Showing
11 changed files
with
229 additions
and
0 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
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,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) | ||
}) | ||
} |
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,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 | ||
} |
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,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) | ||
} |
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,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> |