Skip to content

Commit

Permalink
fix: sort not right
Browse files Browse the repository at this point in the history
  • Loading branch information
moyoez committed Apr 23, 2024
1 parent 1de8372 commit fa689dd
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 60 deletions.
25 changes: 22 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"
"strconv"
"time"

"github.com/joho/godotenv"

backend "github.com/FloatTech/ZeroBot-Plugin/Backend"

Check failure on line 14 in main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

no required module provides package github.com/FloatTech/ZeroBot-Plugin/Backend; to add it:

Check failure on line 14 in main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

no required module provides package github.com/FloatTech/ZeroBot-Plugin/Backend; to add it:

Check failure on line 14 in main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

no required module provides package github.com/FloatTech/ZeroBot-Plugin/Backend; to add it:

Check failure on line 14 in main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, arm64)

no required module provides package github.com/FloatTech/ZeroBot-Plugin/Backend; to add it:
"github.com/FloatTech/ZeroBot-Plugin/kanban" // 在最前打印 banner
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bottle" // 漂流瓶
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/manager" // 群管
Expand Down Expand Up @@ -69,15 +72,13 @@ func init() {
adana := flag.String("n", os.Getenv("name"), "Set default nickname.")
prefix := flag.String("p", "/", "Set command prefix.")
flag.Parse()

for _, s := range flag.Args() {
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
continue
}
sus = append(sus, i)
}
// 通过代码写死的方式添加主人账号
sus = append(sus, 1292581422)
config.W = []*driver.WSClient{driver.NewWebSocketClient(*url, *token)}
config.Z = zero.Config{
Expand All @@ -95,5 +96,23 @@ func main() {
Handle(func(ctx *zero.Ctx) {
ctx.SendChain(message.Text(kanban.Banner))
})
zero.RunAndBlock(&config.Z, process.GlobalInitMutex.Unlock)
// USAGE : Lucy's Backend Server
http.Handle("/", backend.AuthCode(http.HandlerFunc(backend.AliveTest)))
http.Handle("/api/cici/queryid", backend.AuthCode(http.HandlerFunc(backend.ReturnUserList)))
http.Handle("/api/cici/updater", backend.AuthCode(http.HandlerFunc(backend.Updater)))
port := 51608
address := fmt.Sprintf(":%d", port)
go http.ListenAndServe(address, nil)
go zero.RunAndBlock(&config.Z, process.GlobalInitMutex.Unlock)
fmt.Print("#### RUN SERVER BACKEND\n")
fmt.Printf("Server is running on https://localhost:%d\n", port)
backend.SongUpdater()
timer := time.NewTimer(time.Until(backend.GetNextExecutionTime()))
go func() {
for range timer.C {
backend.SongUpdater()
timer.Reset(time.Until(backend.GetNextExecutionTime()))
}
}()
select {}
}
73 changes: 72 additions & 1 deletion plugin/mai/attract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"math/rand"
"sort"
"strconv"
"time"
Expand Down Expand Up @@ -33,6 +34,11 @@ func init() {
if ctx.Event.GroupID != 686575004 && ctx.Event.GroupID != 621400692 {
return
}
getChecker := CheckerTimeUpper(ctx.MessageString())
if getChecker != "" {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(getChecker))
return
}
getReturnedData, _ := GetSpecifyAttarct(bbwID)

Check failure on line 42 in plugin/mai/attract.go

View workflow job for this annotation

GitHub Actions / lint

undefined: GetSpecifyAttarct

Check failure on line 42 in plugin/mai/attract.go

View workflow job for this annotation

GitHub Actions / lint

undefined: bbwID
var returnValue ReturnValue
err := json.Unmarshal([]byte(getReturnedData), &returnValue)
Expand Down Expand Up @@ -73,7 +79,59 @@ func init() {
} else {
checkerUserLogin = "\n半小时内似乎没有人游玩呢( "
}
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("宝贝王合肥万达广场店的 1 台舞萌 DX:\n"+returnText+checkerUserLogin))
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("* 宝贝王合肥万达广场店的 1 台舞萌 DX:\n"+returnText+checkerUserLogin))
})

engine.OnFullMatchGroup([]string{"thjr", "thj", "tj", "jr", "th几"}).SetBlock(true).Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID != 1083559712 && ctx.Event.GroupID != 621400692 {
return
}
getChecker := CheckerTimeUpper(ctx.MessageString())
if getChecker != "" {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(getChecker))
return
}
getReturnedData, _ := GetSpecifyAttarct(thID)

Check failure on line 94 in plugin/mai/attract.go

View workflow job for this annotation

GitHub Actions / lint

undefined: GetSpecifyAttarct

Check failure on line 94 in plugin/mai/attract.go

View workflow job for this annotation

GitHub Actions / lint

undefined: thID
var returnValue ReturnValue
err := json.Unmarshal([]byte(getReturnedData), &returnValue)
if err != nil {
fmt.Println("Error decoding JSON:", err)
return
}
uniqueMap := make(map[string]bool)
var getExpectList []int
for i := range returnValue.Data {
getInt, err := strconv.Atoi(i)
if err != nil {
panic(err)
}
getExpectList = append(getExpectList, getInt)
}
// sort
sort.Ints(getExpectList)
i := 0
var returnText string
for range returnValue.Data {
uniqueList := make([]string, 0, len(uniqueMap))
for _, userlist := range returnValue.Data[strconv.Itoa(getExpectList[i])] {
uniqueMap[strconv.Itoa(userlist.UserID)] = true
}
for key := range uniqueMap {
uniqueList = append(uniqueList, key)
}
getuserListIDListLength := len(uniqueList)
getUserFullPC := len(returnValue.Data[strconv.Itoa(getExpectList[i])])
getReturnText := PlayReturnText(strconv.Itoa(getExpectList[i]), getuserListIDListLength, getUserFullPC)
returnText = returnText + "\n" + getReturnText
i = i + 1
}
var checkerUserLogin string
if gjson.Get(getReturnedData, "returnValue.30.0.loginTime").String() != "" {
checkerUserLogin = ReturnNewestUser(returnValue.Data["30"][0])
} else {
checkerUserLogin = "\n半小时内似乎没有人游玩呢( "
}
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("* 福州泰禾星际传奇的的 1 台舞萌 DX:\n"+returnText+checkerUserLogin))
})
}

Expand All @@ -97,3 +155,16 @@ func ReturnNewestUser(login UserLogin) string {
minsStr := strconv.Itoa(minsInt)
return "\n距离上一次开始游玩为~: " + minsStr + " 分钟前~"
}

func CheckerTimeUpper(string2 string) string {
switch {
case time.Now().Hour() <= 9 && time.Now().Hour() >= 6:
return []string{"我的天哪还搁着" + string2 + "呢! 你也不看看现在几点啊", "这个时间堵门是不是太早了点??? 妈诶", "要不然先去吃个早饭解决一下堵门过早的问题?(", "哎wmc 天天" + string2, " 没救了都"}[rand.Intn(4)]
case time.Now().Hour() >= 0 && time.Now().Hour() <= 5:
return []string{"哎wmc 怎么这个点还想着打mai哎, 歪, 这个点有人吗?", "我的天哪还搁着" + string2 + "呢! 你也不看看现在几点啊", " 去 睡 觉 ! 你不看看几点了啊歪! "}[rand.Intn(3)]
case time.Now().Hour() >= 23:
return []string{"哎wmc 怎么这个点还想着打mai哎, 歪, 这个点有人吗?", "我的天哪还搁着" + string2 + "呢! 你也不看看现在几点啊", " 去 睡 觉 ! 你不看看几点了啊歪! "}[rand.Intn(3)]
default:
return ""
}
}
4 changes: 2 additions & 2 deletions plugin/mai/lxns_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func ReFullPageRender(data LxnsMaimaiRequestB50, userData LxnsMaimaiRequestFromQ
// show nil
// check again if user use origin plate
if userData.Data.NamePlate.Id != 0 {
getBackground, err := web.GetData("https://maimai.lemonkoi.one/plate/" + strconv.FormatInt(int64(userData.Data.NamePlate.Id), 10) + ".png")
getBackground, err := web.GetData("https://lx-rec-reproxy.lemonkoi.one/maimai/plate/" + strconv.FormatInt(int64(userData.Data.NamePlate.Id), 10) + ".png")
if err != nil {
b50bg = b50bgOriginal
}
Expand Down Expand Up @@ -465,7 +465,7 @@ func GetCoverLxns(id string) (image.Image, error) {
filePath := Root + "coverLxns/" + fileName
if _, err := os.Stat(filePath); os.IsNotExist(err) {
// Auto download cover from diving fish's site
downloadURL := "https://maimai.lemonkoi.one/jacket/" + fileName
downloadURL := "https://lx-rec-reproxy.lemonkoi.one/maimai/jacket/" + fileName
cover, err := downloadImage(downloadURL)
if err != nil {
return LoadPictureWithResize(defaultCoverLink, 90, 90), nil
Expand Down
47 changes: 39 additions & 8 deletions plugin/mai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/FloatTech/ZeroBot-Plugin/compounds/toolchain"
"image"
rand2 "math/rand"
"net/http"
"os"
"strconv"
"strings"

"github.com/FloatTech/ZeroBot-Plugin/compounds/toolchain"

"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/floatbox/web"
"github.com/FloatTech/gg"
Expand Down Expand Up @@ -70,7 +71,7 @@ func init() {
})
engine.OnRegex(`^[! !/](mai|b50)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
if GetUserSwitcherInfoFromDatabase(uid) == true {
if GetUserSwitcherInfoFromDatabase(uid) {
// use lxns checker service.
getUserData := RequestBasicDataFromLxns(uid)
if getUserData.Code != 200 {
Expand Down Expand Up @@ -134,7 +135,7 @@ func init() {
}
var getEventText string
// due to it changed, so reverse.
if getBool == false {
if !getBool {
getEventText = "Lxns查分"
} else {
getEventText = "Diving Fish查分"
Expand Down Expand Up @@ -267,7 +268,12 @@ func init() {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请使用 /mai tokenbind <tokenid> 绑定水鱼查分器,其中 TokenID 从 https://www.diving-fish.com/maimaidx/prober 用户设置中拿到"))
return
}
if !CheckTheTicketIsValid(getTokenId) {
checkertoken := CheckTheTicketIsValid(getTokenId)
if checkertoken == "nil" {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("无法校验 Token 可用性, 可能 Lucy 连接到 水鱼的服务已宕机"))
return
}
if checkertoken == "false" {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("此 Token 不合法 ,请重新绑定"))
return
}
Expand Down Expand Up @@ -316,7 +322,7 @@ func init() {
request.Header.Set("valid", os.Getenv("validauth"))
return nil
}, nil)
if strings.Contains(string(getReplyMsg), "{") == false {
if !strings.Contains(string(getReplyMsg), "{") {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("返回了错误.png, ERROR:"+string(getReplyMsg)))
return
}
Expand All @@ -332,6 +338,31 @@ func init() {
}
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("目前查询到您的游玩记录如下: \n\n"+returnText))
})
engine.OnRegex(`^[! !/](mai|b50)\sautosync`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
// AutoUpdate : ReMaimai Project
// Check UserStatus
getQuery := QueryUserTokenDataByQQ(ctx.Event.UserID).UserID
if getQuery != 0 {
RemoveUserTokenData(ctx.Event.UserID)
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("已经帮你关闭了自动同步了~"))
return
}
getUserID := GetUserIDFromDatabase(ctx.Event.UserID)
if getUserID.Userid == "" {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请前往 https://mai.lemonkoi.one 获取绑定码进行绑定"))
return
}
getToken := GetUserToken(strconv.FormatInt(ctx.Event.UserID, 10))
if getToken == "" {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("请使用 /mai tokenbind <tokenid> 绑定水鱼查分器,其中 TokenID 从 https://www.diving-fish.com/maimaidx/prober 用户设置中拿到"))
return
}
queryIntUserID, _ := strconv.ParseInt(getUserID.Userid, 10, 64)
// Write
InsertQueryParamsToStruct(UserAutoSync{QQ: ctx.Event.UserID, UserID: queryIntUserID})
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("启用自动同步成功~ 在 Lucy 参与加速项目下可自动同步当前游玩歌曲~ "))
})

engine.OnRegex(`^(网咋样|[! !/](mai|b50)\sstatus$)`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
// getWebStatus
// getWebStatus := ReturnWebStatus()
Expand All @@ -353,7 +384,7 @@ func init() {

getZlibWord := "Zlib 压缩跳过率: \n" + "10mins (" + ConvertZlib(getZlibError.ZlibError.Field1, getZlibError.Full.Field1) + " Loss)\n" + "30mins (" + ConvertZlib(getZlibError.ZlibError.Field2, getZlibError.Full.Field2) + " Loss)\n" + "60mins (" + ConvertZlib(getZlibError.ZlibError.Field3, getZlibError.Full.Field3) + " Loss)\n"
getRealStatus := "\n以下数据来源于mai机台的数据反馈\n"
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("* Zlib 压缩跳过率可以很好的反馈当前 MaiNet (Wahlap Service) 当前负载的情况,根据样本 + Lucy处理情况 来判断 \n* 错误率收集则来源于 机台游玩数据,反应各地区真实mai游玩错误情况 \n* 在 1小时 内,Lucy 共处理了 "+getLucyRespHandlerStr+"次 请求💫,其中详细数据如下:\n\n"+getZlibWord+getRealStatus+"\n"+ConvertRealPlayWords(playerStatus)+"\n* Zlib 3% Loss 以下则 基本上可以正常游玩\n* 10% Loss 则会有明显断网现象(请准备小黑屋工具)\n* 30% Loss 则无法正常游玩(即使使用小黑屋工具) "))
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("* Zlib 压缩跳过率可以很好的反馈当前 MaiNet (Wahlap Service) 当前负载的情况,根据样本 + Lucy处理情况 来判断 \n* 错误率收集则来源于 机台游玩数据,反应各地区真实mai游玩错误情况 \n* 在 1小时 内,Lucy 共处理了 "+getLucyRespHandlerStr+"次 请求💫,其中详细数据如下:\n\n"+getZlibWord+getRealStatus+"\n"+ConvertRealPlayWords(playerStatus)))
})
engine.OnRegex(`^[! !/](mai|b50)\squery\s(.*)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
getDefaultInfo := ctx.State["regex_matched"].([]string)[2]
Expand Down Expand Up @@ -395,7 +426,7 @@ func init() {
getReferIndexIsOn = true
}
switch {
case strings.HasPrefix(settedSongAlias, "id") == true:
case strings.HasPrefix(settedSongAlias, "id"):
// useID checker.
isIDChecker = true
getParse, err := strconv.ParseInt(strings.Replace(settedSongAlias, "id", "", 1), 10, 64)
Expand All @@ -409,7 +440,7 @@ func init() {
queryStatus, songIDLists, accStats, returnListHere := QueryReferSong(settedSongAlias, getBool)
songIDList = songIDLists
accStat = accStats
if queryStatus == false {
if !queryStatus {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("未找到对应歌曲,可能是数据库未收录("))
return
}
Expand Down
5 changes: 3 additions & 2 deletions plugin/mai/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"encoding/json"
"errors"
"github.com/FloatTech/floatbox/web"
"io"
"net/http"
"os"

"github.com/FloatTech/floatbox/web"
)

type DivingFishB50 struct {
Expand Down Expand Up @@ -52,7 +53,7 @@ type DivingFishDevFullDataRecords struct {
func QueryMaiBotDataFromQQ(qq int, isB50 bool) (playerdata []byte, err error) {
// packed json and sent.
var jsonStruct interface{}
if isB50 == true {
if isB50 {
jsonStruct = DivingFishB50{QQ: qq, B50: true}
} else {
jsonStruct = DivingFishB40{QQ: qq}
Expand Down
Loading

0 comments on commit fa689dd

Please sign in to comment.