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 3, 2024
1 parent d8c4881 commit 605dc7d
Show file tree
Hide file tree
Showing 6 changed files with 476 additions and 22 deletions.
43 changes: 43 additions & 0 deletions plugin/mai/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package mai

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

View workflow job for this annotation

GitHub Actions / lint

: # github.com/MoYoez/Lucy_reibot/plugin/mai

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

type LxnsAliases struct {
Aliases []struct {
SongId int `json:"song_id"`
Aliases []string `json:"aliases"`
} `json:"aliases"`
}

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

// RequestAliasFromLxns Get Alias From LXNS Network.
func RequestAliasFromLxns() LxnsAliases {
getData, err := web.RequestDataWithHeaders(web.NewDefaultClient(), "https://maimai.lxns.net/api/v0/maimai/alias/list", "GET", func(request *http.Request) error {
request.Header.Add("Authorization", os.Getenv("lxnskey"))
return nil
}, nil)
if err != nil {
return LxnsAliases{}
}
var handlerData LxnsAliases
json.Unmarshal(getData, &handlerData)
return handlerData
}

// QueryReferSong CASE: In DivingFish Mode this SongID will be added "00" AHEAD IF SONGID IS LOWER THAN 1000 (if lower than 100 then it will be added "000" ) , Otherwise it will be added "1" AHEAD. || LXNS don't need to do anything. (DEFAULT RETURN LXNS SONGDATA)
func (requester *LxnsAliases) QueryReferSong(songAlias string) (status bool, songID int64) {
for i, dataInnner := range requester.Aliases {
for _, v := range dataInnner.Aliases {
if songAlias == v {
return true, int64(requester.Aliases[i].SongId)
}
}
}
return false, 0
}
89 changes: 84 additions & 5 deletions plugin/mai/lxnsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"time"
"unicode/utf8"

"github.com/MoYoez/Lucy_reibot/utils/toolchain"
"github.com/FloatTech/floatbox/web"
"github.com/FloatTech/gg"
"github.com/FloatTech/imgfactory"
"github.com/MoYoez/Lucy_reibot/utils/toolchain"
rei "github.com/fumiama/ReiBot"
"golang.org/x/text/width"
)
Expand Down Expand Up @@ -104,6 +104,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"`
}

// on tg, user use friendCode to bind info.

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

func ReCardRenderBase(data LxnsMaimaiRequestDataPiece, getNum int) image.Image {
func RequestReferSong(friendID int64, songID int64, isSD bool) LxnsMaimaiRequestUserReferBestSong {
var getReferType string
if isSD {
getReferType = "standard"
} else {
getReferType = "dx"
}
getData, err := web.RequestDataWithHeaders(web.NewDefaultClient(), "https://maimai.lxns.net/api/v0/maimai/player/"+strconv.FormatInt(friendID, 10)+"/bests?song_id="+strconv.FormatInt(songID, 10)+"&song_type="+getReferType, "GET", func(request *http.Request) error {
request.Header.Add("Authorization", os.Getenv("lxnskey"))
return nil
}, nil)
if err != nil {
return LxnsMaimaiRequestUserReferBestSong{Success: false}
}
var handlerData LxnsMaimaiRequestUserReferBestSong
json.Unmarshal(getData, &handlerData)
return handlerData
}

func RequestReferSongIndex(friendID int64, songID int64, diff int64, isSD bool) LxnsMaimaiRequestUserReferBestSongIndex {
var getReferType string
if isSD {
getReferType = "standard"
} else {
getReferType = "dx"
}
getData, err := web.RequestDataWithHeaders(web.NewDefaultClient(), "https://maimai.lxns.net/api/v0/maimai/player/"+strconv.FormatInt(friendID, 10)+"/bests?song_id="+strconv.FormatInt(songID, 10)+"&song_type="+getReferType+"&level_index="+strconv.FormatInt(diff, 10), "GET", func(request *http.Request) error {
request.Header.Add("Authorization", os.Getenv("lxnskey"))
return nil
}, nil)
if err != nil {
return LxnsMaimaiRequestUserReferBestSongIndex{Success: false}
}
var handlerData LxnsMaimaiRequestUserReferBestSongIndex
json.Unmarshal(getData, &handlerData)
return handlerData
}

// ReCardRenderBase This Function is same as cardRender, but it convert for LXNS Network Maimai.
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 +308,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 Down Expand Up @@ -399,7 +478,7 @@ func ReFullPageRender(data LxnsMaimaiRequestB50, userData LxnsMaimaiRequestFromF
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 @@ -408,7 +487,7 @@ func ReFullPageRender(data LxnsMaimaiRequestB50, userData LxnsMaimaiRequestFromF
}

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 605dc7d

Please sign in to comment.