From 9ffd9849f6784212fc3aa64fce6137a588002c24 Mon Sep 17 00:00:00 2001 From: MoYoez Date: Tue, 5 Mar 2024 22:21:56 +0800 Subject: [PATCH] fix: mai divingfish data not shown --- plugin/mai/alias.go | 1 + plugin/mai/main.go | 121 ++++++++++++++++++++++++++++++------------- plugin/mai/struct.go | 12 +++++ 3 files changed, 97 insertions(+), 37 deletions(-) diff --git a/plugin/mai/alias.go b/plugin/mai/alias.go index 9454746..dc792b0 100644 --- a/plugin/mai/alias.go +++ b/plugin/mai/alias.go @@ -212,6 +212,7 @@ func UpdateAliasPackage() { } } } + tempList = append(tempList, &MappedListStruct{DingFishId: getInt, SongName: listData[0], Aliases: referListData, SongId: vartiesList}) } GeneratedList := map[string]interface{}{ diff --git a/plugin/mai/main.go b/plugin/mai/main.go index 74fa8ac..d48d4e2 100644 --- a/plugin/mai/main.go +++ b/plugin/mai/main.go @@ -10,6 +10,7 @@ import ( rei "github.com/fumiama/ReiBot" tgba "github.com/go-telegram-bot-api/telegram-bot-api/v5" "github.com/tidwall/gjson" + "github.com/wdvxdr1123/ZeroBot/utils/helper" "image" "math" @@ -373,11 +374,24 @@ func init() { case getSongType == "standard": for numPosition, index := range fullDevData.Records { for _, songID := range songIDList { - if index.Type == "SD" && index.SongId == int(songID) { - ReferSongTypeList = append(ReferSongTypeList, numPosition) + if index.SongId == songID { + if index.Type == "SD" { + ReferSongTypeList = append(ReferSongTypeList, numPosition) + } + } + } + } + if len(ReferSongTypeList) == 0 { // try with added num + for numPosition, index := range fullDevData.Records { + for _, songID := range songIDList { + songID = simpleNumHandler(songID) + if index.SongId == songID { + if index.Type == "SD" { + ReferSongTypeList = append(ReferSongTypeList, numPosition) + } + } } } - } if len(ReferSongTypeList) == 0 { ctx.SendPlainMessage(true, "没有发现游玩过的 SD 谱面~ 如不确定可以忽略请求参数, Lucy会自动识别") @@ -391,11 +405,22 @@ func init() { } } } + if len(ReferSongTypeList) == 0 { + for numPosition, index := range fullDevData.Records { + for _, songID := range songIDList { + songID = simpleNumHandler(songID) + if index.SongId == songID { + if index.Type == "DX" { + ReferSongTypeList = append(ReferSongTypeList, numPosition) + } + } + } + } + } if len(ReferSongTypeList) == 0 { ctx.SendPlainMessage(true, "没有发现游玩过的 DX 谱面~ 如不确定可以忽略请求参数, Lucy会自动识别") return } - default: // no settings. for numPosition, index := range fullDevData.Records { for _, songID := range songIDList { @@ -406,54 +431,76 @@ func init() { if len(ReferSongTypeList) == 0 { for numPositionOn, indexOn := range fullDevData.Records { for _, songID := range songIDList { - if indexOn.Type == "DX" && indexOn.SongId == int(songID) { + if indexOn.Type == "DX" && indexOn.SongId == songID { ReferSongTypeList = append(ReferSongTypeList, numPositionOn) } } } } - if len(ReferSongTypeList) == 0 { - ctx.SendPlainMessage(true, "貌似没有发现你玩过这首歌曲呢(") - return + } + if len(ReferSongTypeList) == 0 { + for numPosition, index := range fullDevData.Records { + for _, songID := range songIDList { + songID = simpleNumHandler(songID) + if index.Type == "SD" && index.SongId == songID { + ReferSongTypeList = append(ReferSongTypeList, numPosition) + } + } + if len(ReferSongTypeList) == 0 { + for numPositionOn, indexOn := range fullDevData.Records { + for _, songID := range songIDList { + songID = simpleNumHandler(songID) + if indexOn.Type == "DX" && indexOn.SongId == songID { + ReferSongTypeList = append(ReferSongTypeList, numPositionOn) + } + } + } + } } } - if !getReferIndexIsOn { - // index a map => level_index = "record_diff" - levelIndexMap := map[int]string{} - for _, dataPack := range ReferSongTypeList { - levelIndexMap[fullDevData.Records[dataPack].LevelIndex] = strconv.Itoa(dataPack) - } - var trulyReturnedData string - for i := 4; i >= 0; i-- { - if levelIndexMap[i] != "" { - trulyReturnedData = levelIndexMap[i] - break - } + if len(ReferSongTypeList) == 0 { + ctx.SendPlainMessage(true, "貌似没有发现你玩过这首歌曲呢(") + return + } + } + + if !getReferIndexIsOn { + // index a map => level_index = "record_diff" + levelIndexMap := map[int]string{} + for _, dataPack := range ReferSongTypeList { + levelIndexMap[fullDevData.Records[dataPack].LevelIndex] = strconv.Itoa(dataPack) + } + var trulyReturnedData string + for i := 4; i >= 0; i-- { + if levelIndexMap[i] != "" { + trulyReturnedData = levelIndexMap[i] + break } - getNum, _ := strconv.Atoi(trulyReturnedData) - // getNum ==> 0 + } + getNum, _ := strconv.Atoi(trulyReturnedData) + // getNum ==> 0 + returnPackage := fullDevData.Records[getNum] + _ = gg.NewContextForImage(RenderCard(returnPackage, 0, true)).SavePNG(engine.DataFolder() + "save/" + strconv.Itoa(songIDList[0]) + "_" + strconv.Itoa(int(getUserID)) + ".png") + ctx.SendPhoto(tgba.FilePath(engine.DataFolder()+"save/"+strconv.Itoa(int(songIDList[0]))+"_"+strconv.Itoa(int(getUserID))+".png"), true, "") + } else { + levelIndexMap := map[int]string{} + for _, dataPack := range ReferSongTypeList { + levelIndexMap[fullDevData.Records[dataPack].LevelIndex] = strconv.Itoa(dataPack) + } + getDiff, _ := strconv.Atoi(userSettingInterface["level_index"]) + + if levelIndexMap[getDiff] != "" { + getNum, _ := strconv.Atoi(levelIndexMap[getDiff]) returnPackage := fullDevData.Records[getNum] _ = gg.NewContextForImage(RenderCard(returnPackage, 0, true)).SavePNG(engine.DataFolder() + "save/" + strconv.Itoa(songIDList[0]) + "_" + strconv.Itoa(int(getUserID)) + ".png") - ctx.SendPhoto(tgba.FilePath(engine.DataFolder()+"save/"+strconv.Itoa(int(songIDList[0]))+"_"+strconv.Itoa(int(getUserID))+".png"), true, "") + ctx.SendPhoto(tgba.FilePath(engine.DataFolder()+"save/"+strconv.Itoa(songIDList[0])+"_"+strconv.Itoa(int(getUserID))+".png"), true, "") } else { - levelIndexMap := map[int]string{} - for _, dataPack := range ReferSongTypeList { - levelIndexMap[fullDevData.Records[dataPack].LevelIndex] = strconv.Itoa(dataPack) - } - getDiff, _ := strconv.Atoi(userSettingInterface["level_index"]) - - if levelIndexMap[getDiff] != "" { - getNum, _ := strconv.Atoi(levelIndexMap[getDiff]) - returnPackage := fullDevData.Records[getNum] - _ = gg.NewContextForImage(RenderCard(returnPackage, 0, true)).SavePNG(engine.DataFolder() + "save/" + strconv.Itoa(songIDList[0]) + "_" + strconv.Itoa(int(getUserID)) + ".png") - ctx.SendPhoto(tgba.FilePath(engine.DataFolder()+"save/"+strconv.Itoa(songIDList[0])+"_"+strconv.Itoa(int(getUserID))+".png"), true, "") - } else { - ctx.SendPlainMessage(true, "貌似你没有玩过这个难度的曲子哦~") - } + ctx.SendPlainMessage(true, "貌似你没有玩过这个难度的曲子哦~") } } } + case getSplitStringList[1] == "aliasupdate": if rei.SuperUserPermission(ctx) { UpdateAliasPackage() diff --git a/plugin/mai/struct.go b/plugin/mai/struct.go index 7e92c17..848870f 100644 --- a/plugin/mai/struct.go +++ b/plugin/mai/struct.go @@ -676,3 +676,15 @@ func ConvertZlib(value, total int) string { func ConvertFloat(data float64) string { return strconv.FormatFloat(data, 'f', 3, 64) } + +func simpleNumHandler(num int) int { + if num < 1000 && num > 100 { + toint, _ := strconv.Atoi(fmt.Sprintf("10%d", num)) + return toint + } + if num > 1000 && num < 10000 { + toint, _ := strconv.Atoi(fmt.Sprintf("1%d", num)) + return toint + } + return num +}