Skip to content

Commit

Permalink
[+] add maimai query
Browse files Browse the repository at this point in the history
  • Loading branch information
moyoez committed Mar 5, 2024
1 parent 9044192 commit 22d8908
Show file tree
Hide file tree
Showing 6 changed files with 469 additions and 10 deletions.
9 changes: 9 additions & 0 deletions compounds/toolchain/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package toolchain

import "strings"

// SplitCommandTo Split Command and Adjust To.
func SplitCommandTo(raw string, setCommandStopper int) (splitCommandLen int, splitInfo []string) {
rawSplit := strings.SplitN(raw, " ", setCommandStopper)
return len(rawSplit), rawSplit
}
99 changes: 99 additions & 0 deletions plugin/mai/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package mai

Check failure on line 1 in plugin/mai/alias.go

View workflow job for this annotation

GitHub Actions / lint

: # github.com/FloatTech/ZeroBot-Plugin/plugin/mai

import (
"encoding/json"
"github.com/FloatTech/floatbox/web"
"os"
)

type AliasesReturnValue struct {
Aliases []struct {
DvId int `json:"dv_id"`
SongName string `json:"song_name"`
SongId []int `json:"song_id"`
Aliases []string `json:"aliases"`
} `json:"aliases"`
}

// only support LXNS because => if DivingFish then need Token.

// QueryReferSong use LocalStorageData.
func QueryReferSong(Alias string, isLxnet bool) (status bool, id []int, needAcc bool) {
// unpackedData
getData, err := os.ReadFile(engine.DataFolder() + "alias.json")
if err != nil {
panic(err)
}
var DataHandler AliasesReturnValue
json.Unmarshal(getData, &DataHandler)
var onloadList [][]int
for _, dataSearcher := range DataHandler.Aliases {
for _, aliasSearcher := range dataSearcher.Aliases {
if aliasSearcher == Alias {
onloadList = append(onloadList, dataSearcher.SongId) // write in memory
}
}
}
// if list is 2,query them is from the same song? | if above 2(3 or more ,means this song need acc.)
switch {
case len(onloadList) == 1: // only one query.
if isLxnet {
for _, listhere := range onloadList[0] {
if listhere < 10000 {
return true, []int{listhere}, false
}
}
} else {
return true, onloadList[0], false
}
// query length is 2,it means this maybe same name but diff id ==> (E.G: Oshama Scramble!)
case len(onloadList) == 2:
for _, listHere := range onloadList[0] {
for _, listAliasTwo := range onloadList[1] {
if listHere == listAliasTwo {
// same list here.
var returnIntList []int
returnIntList = append(returnIntList, onloadList[0]...)
returnIntList = append(returnIntList, onloadList[1]...)
returnIntList = removeIntDuplicates(returnIntList)
if isLxnet {
for _, listhere := range returnIntList {
if listhere < 10000 {
return true, []int{listhere}, false
}
}
} else {
return true, returnIntList, false
}
}
}
}
// if query is none, means it need moreacc
return true, nil, true
case len(onloadList) >= 3:
return true, nil, true
}
// no found.
return false, nil, false
}

// UpdateAliasPackage Use simple action to update alias.
func UpdateAliasPackage() {
getData, err := web.GetData("https://maihook.lemonkoi.one/api/alias")
if err != nil {
panic(err)
}
os.WriteFile(engine.DataFolder()+"alias.json", getData, 0777)
}

func removeIntDuplicates(list []int) []int {
seen := make(map[int]bool)
var result []int
for _, item := range list {
if !seen[item] {
seen[item] = true
result = append(result, item)
}
}
return result
}
50 changes: 45 additions & 5 deletions plugin/mai/lxns_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,44 @@ type LxnsMaimaiRequestDataPiece struct {
UploadTime time.Time `json:"upload_time"`
}

type LxnsMaimaiRequestUserReferBestSong struct {
Success bool `json:"success"`
Code int `json:"code"`
Data []struct {
Id int `json:"id"`
SongName string `json:"song_name"`
Level string `json:"level"`
LevelIndex int `json:"level_index"`
Achievements float64 `json:"achievements"`
Fc *string `json:"fc"`
Fs *string `json:"fs"`
DxScore int `json:"dx_score"`
DxRating float64 `json:"dx_rating"`
Rate string `json:"rate"`
Type string `json:"type"`
UploadTime time.Time `json:"upload_time"`
} `json:"data"`
}

type LxnsMaimaiRequestUserReferBestSongIndex struct {
Success bool `json:"success"`
Code int `json:"code"`
Data struct {
Id int `json:"id"`
SongName string `json:"song_name"`
Level string `json:"level"`
LevelIndex int `json:"level_index"`
Achievements float64 `json:"achievements"`
Fc *string `json:"fc"`
Fs *string `json:"fs"`
DxScore int `json:"dx_score"`
DxRating float64 `json:"dx_rating"`
Rate string `json:"rate"`
Type string `json:"type"`
UploadTime time.Time `json:"upload_time"`
} `json:"data"`
}

// NOTE: lxns network maimai uses qq => friendCode

// RequestBasicDataFromLxns
Expand Down Expand Up @@ -164,7 +202,7 @@ func RequestB50DataByFriendCode(friendCode int64) LxnsMaimaiRequestB50 {
return handlerData
}

func ReCardRenderBase(data LxnsMaimaiRequestDataPiece, getNum int) image.Image {
func ReCardRenderBase(data LxnsMaimaiRequestDataPiece, getNum int, isSimpleRender bool) image.Image {
getType := data.Type
var CardBackGround string
var multiTypeRender sync.WaitGroup
Expand Down Expand Up @@ -231,7 +269,9 @@ func ReCardRenderBase(data LxnsMaimaiRequestDataPiece, getNum int) image.Image {
drawBackGround.Fill()
drawBackGround.SetFontFace(rankFont)
drawBackGround.SetColor(diffColor[data.LevelIndex])
drawBackGround.DrawString("#"+strconv.Itoa(getNum), 130, 111)
if !isSimpleRender {
drawBackGround.DrawString("#"+strconv.Itoa(getNum), 130, 111)
}
drawBackGround.FillPreserve()
// draw rest of card.
drawBackGround.SetFontFace(levelFont)
Expand All @@ -244,7 +284,7 @@ func ReCardRenderBase(data LxnsMaimaiRequestDataPiece, getNum int) image.Image {
drawBackGround.DrawString("▶", 235, 111)
drawBackGround.FillPreserve()
drawBackGround.SetFontFace(ratingFont)
drawBackGround.DrawString(strconv.Itoa(data.DxScore), 250, 111)
drawBackGround.DrawString(strconv.Itoa(int(data.DxRating)), 250, 111)
drawBackGround.FillPreserve()
if data.Fc != nil {
FcPointer := *data.Fc
Expand Down Expand Up @@ -400,7 +440,7 @@ func ReFullPageRender(data LxnsMaimaiRequestB50, userData LxnsMaimaiRequestFromQ
getInitY := 285
var i int
for i = 0; i < getSDLength; i++ {
b50Render.DrawImage(ReCardRenderBase(DataPiecesRepacked(data, true, i), i+1), getInitX, getInitY)
b50Render.DrawImage(ReCardRenderBase(DataPiecesRepacked(data, true, i), i+1, false), getInitX, getInitY)
getInitX += 400
if getInitX == 2045 {
getInitX = 45
Expand All @@ -409,7 +449,7 @@ func ReFullPageRender(data LxnsMaimaiRequestB50, userData LxnsMaimaiRequestFromQ
}

for dx := 0; dx < getDXLength; dx++ {
b50Render.DrawImage(ReCardRenderBase(DataPiecesRepacked(data, false, dx), dx+1), getDXinitX, getDXinitY)
b50Render.DrawImage(ReCardRenderBase(DataPiecesRepacked(data, false, dx), dx+1, false), getDXinitX, getDXinitY)
getDXinitX += 400
if getDXinitX == 2045 {
getDXinitX = 45
Expand Down
Loading

0 comments on commit 22d8908

Please sign in to comment.