Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
[+] add maimai status
Browse files Browse the repository at this point in the history
  • Loading branch information
MoYoez committed Feb 1, 2024
1 parent 6f35cd1 commit e2d300c
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 8 deletions.
6 changes: 3 additions & 3 deletions kanban/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package kanban
// Banner ...
var Banner = "* Telegram + ReiBot \n" +
"* Unofficial Fork of Lucy (HiMoYo Bot.)\n" +
"* Copyright © 2020 - 2023 FloatTech. All Rights Reserved.\n" +
"* ManualBook : https://side-lucy.lemonkoi.one\n" +
"* Project: https://github.com/MoYoez/lucy_reibot"
"* Copyright © 2020 - 2024 FloatTech. All Rights Reserved.\n" +
"* Project: https://github.com/MoYoez/lucy_reibot\n" +
"* ManualBook : https://side-lucy.lemonkoi.one"
48 changes: 43 additions & 5 deletions plugin/mai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"os"
"strconv"
"strings"

"github.com/FloatTech/ReiBot-Plugin/utils/toolchain"
"github.com/FloatTech/floatbox/web"
Expand Down Expand Up @@ -102,6 +103,45 @@ func init() {
SetUserDefaultPlateToDatabase(ctx, getSplitStringList[2])
case getSplitStringList[1] == "switch":
MaimaiSwitcherService(ctx)
case getSplitStringList[1] == "region":
getID, _ := toolchain.GetChatUserInfoID(ctx)
getMaiID := GetUserIDFromDatabase(getID)
if getMaiID.Userid == "" {
ctx.SendPlainMessage(true, "没有绑定UserID~ 绑定方式: /mai userbind <maiTempID>")
return
}
getIntID, _ := strconv.ParseInt(getMaiID.Userid, 10, 64)
getReplyMsg := GetUserRegion(getIntID)

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, 386)

undefined: GetUserRegion

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: GetUserRegion

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

undefined: GetUserRegion

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: GetUserRegion

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

undefined: GetUserRegion

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm)

undefined: GetUserRegion

Check failure on line 114 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: GetUserRegion
if strings.Contains(getReplyMsg, "{") == false {
ctx.SendPlainMessage(true, "返回了错误.png, ERROR:"+getReplyMsg)
return
}
var MixedMagic GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, 386)

undefined: GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

undefined: GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

undefined: GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm)

undefined: GetUserRegionStruct

Check failure on line 119 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: GetUserRegionStruct
json.Unmarshal(helper.StringToBytes(getReplyMsg), &MixedMagic)
var returnText string
for _, onlistLoader := range MixedMagic.UserRegionList {
returnText = returnText + MixedRegionWriter(onlistLoader.RegionId-1, onlistLoader.PlayCount, onlistLoader.Created) + "\n\n"
}
if returnText == "" {
ctx.SendPlainMessage(true, "目前 Lucy 没有查到您的游玩记录哦~")
return
}
ctx.SendPlainMessage(true, "目前查询到您的游玩记录如下: \n\n"+returnText)
case getSplitStringList[1] == "status":
// getWebStatus
getWebStatus := ReturnWebStatus()
getZlibError := ReturnZlibError()
// 20s one request.
var getLucyRespHandler int
if getZlibError.Full.Field3 < 180 {
getLucyRespHandler = getZlibError.Full.Field3
} else {
getLucyRespHandler = getZlibError.Full.Field3 - 180
}
getLucyRespHandlerStr := strconv.Itoa(getLucyRespHandler)
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"
getWebStatusCount := "Web Uptime Ping:\n * MaimaiDXCN: " + ConvertFloat(getWebStatus.Details.MaimaiDXCN.Uptime*100) + "%\n * MaimaiDXCN Main Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNMain.Uptime*100) + "%\n * MaimaiDXCN Title Server: " + ConvertFloat(float64(getWebStatus.Details.MaimaiDXCNTitle.Uptime*100)) + "%\n * MaimaiDXCN Update Server: " + ConvertFloat(float64(getWebStatus.Details.MaimaiDXCNUpdate.Uptime*100)) + "%\n * MaimaiDXCN NetLogin Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNNetLogin.Uptime*100) + "%\n * MaimaiDXCN Net Server: " + ConvertFloat(getWebStatus.Details.MaimaiDXCNDXNet.Uptime*100) + "%\n"
ctx.SendPlainMessage(true, "* Zlib 压缩跳过率可以很好的反馈当前 MaiNet (Wahlap Service) 当前负载的情况\n* Web Uptime Ping 则可以反馈 MaiNet 在外部原因(DDOS) 下造成的负载详情 ( 100% 即代表服务器为稳定, uptime 越低则代表可用性越差 ) \n* 在 1小时 内,Lucy 共处理了 "+getLucyRespHandlerStr+"次 请求💫,其中详细数据如下:\n\n"+getZlibWord+getWebStatusCount+"\n* Title Server 爆炸 容易造成数据获取失败\n* Zlib 3% Loss 以下则 基本上可以正常游玩\n* 10% Loss 则会有明显断网现象(请准备小黑屋工具)\n* 30% Loss 则无法正常游玩(即使使用小黑屋工具) ")
case getSplitStringList[1] == "update":
getID, _ := toolchain.GetChatUserInfoID(ctx)
getMaiID := GetUserIDFromDatabase(getID)
Expand All @@ -120,16 +160,13 @@ func init() {
}
// token is valid, get data.
getIntID, _ := strconv.ParseInt(getMaiID.Userid, 10, 64)
getFullData := GetMusicList(getIntID, 0, 300)
if gjson.Get(getFullData, "length").Int() > 300 {
getFullData = GetMusicList(getIntID, 0, gjson.Get(getFullData, "length").Int())
}
// getFullData := GetMusicList(getIntID, 0, 600)
getFullData := GetMusicList(getIntID, 0, 1000)

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, 386)

undefined: GetMusicList

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: GetMusicList

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

undefined: GetMusicList

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: GetMusicList

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

undefined: GetMusicList

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm)

undefined: GetMusicList

Check failure on line 164 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: GetMusicList
var unmashellData UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, 386)

undefined: UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (windows, amd64)

undefined: UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm64)

undefined: UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, arm)

undefined: UserMusicListStruct

Check failure on line 165 in plugin/mai/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: UserMusicListStruct
json.Unmarshal(helper.StringToBytes(getFullData), &unmashellData)
getFullDataStruct := convert(unmashellData)
jsonDumper := getFullDataStruct
jsonDumperFull, err := json.Marshal(jsonDumper)
os.WriteFile(engine.DataFolder()+"dump.json", jsonDumperFull, 0777)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -346,6 +383,7 @@ func MaimaiSwitcherService(ctx *rei.Ctx) {
}
var getEventText string
// due to it changed, so reverse.
// due to it changed, so reverse.
if getBool == false {
getEventText = "Lxns查分"
} else {
Expand Down
150 changes: 150 additions & 0 deletions plugin/mai/struct.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mai

import (
"encoding/json"
"fmt"
"image"
"image/color"
Expand All @@ -24,6 +25,48 @@ import (
"golang.org/x/text/width"
)

type WebPingStauts struct {
Details struct {
MaimaiDXCN struct {
Uptime float64 `json:"uptime"`
} `json:"maimai DX CN"`
MaimaiDXCNDXNet struct {
Uptime float64 `json:"uptime"`
} `json:"maimai DX CN DXNet"`
MaimaiDXCNMain struct {
Uptime float64 `json:"uptime"`
} `json:"maimai DX CN Main"`
MaimaiDXCNNetLogin struct {
Uptime float64 `json:"uptime"`
} `json:"maimai DX CN NetLogin"`
MaimaiDXCNTitle struct {
Uptime float64 `json:"uptime"`
} `json:"maimai DX CN Title"`
MaimaiDXCNUpdate struct {
Uptime float64 `json:"uptime"`
} `json:"maimai DX CN Update"`
} `json:"details"`
Status bool `json:"status"`
}

type ZlibErrorStatus struct {
Full struct {
Field1 int `json:"10"`
Field2 int `json:"30"`
Field3 int `json:"60"`
} `json:"full"`
FullError struct {
Field1 int `json:"10"`
Field2 int `json:"30"`
Field3 int `json:"60"`
} `json:"full_Error"`
ZlibError struct {
Field1 int `json:"10"`
Field2 int `json:"30"`
Field3 int `json:"60"`
} `json:"zlib_Error"`
}

type player struct {
AdditionalRating int `json:"additional_rating"`
Charts struct {
Expand Down Expand Up @@ -524,3 +567,110 @@ func getRatingBg(rating int) string {
}
return ratingBgFilenames[index]
}

// MixedRegionWriter Some Mixed Magic, looking for your region information.
func MixedRegionWriter(regionID int, playCount int, createdDate string) string {
getCountryID := returnCountryID(regionID)
return fmt.Sprintf(" - 在 regionID 为 %d (%s) 的省/直辖市 游玩过 %d 次, 第一次游玩时间于 %s", regionID+1, getCountryID, playCount, createdDate)
}

// ReportToEndPoint Report Some Error To Wahlap Server.
func ReportToEndPoint(getReport int, getReportType string) string {
url := "https://maihook.lemonkoi.one/api/zlib?report=" + strconv.Itoa(getReport) + "&reportType=" + getReportType
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)
if err != nil {
fmt.Println(err)
return ""
}
req.Header.Add("authkey", authKey)
req.Header.Add("Accept", "*/*")
req.Header.Add("Host", "maihook.lemonkoi.one")
req.Header.Add("Connection", "keep-alive")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return ""
}
defer res.Body.Close()

body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return ""
}
return string(body)
}

// ReturnZlibError Return Zlib ERROR
func ReturnZlibError() ZlibErrorStatus {
url := "https://maihook.lemonkoi.one/api/zlib"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)

if err != nil {
fmt.Println(err)
return ZlibErrorStatus{}
}
req.Header.Add("Accept", "*/*")
req.Header.Add("Host", "maihook.lemonkoi.one")
req.Header.Add("Connection", "keep-alive")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return ZlibErrorStatus{}
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return ZlibErrorStatus{}
}
var returnData ZlibErrorStatus
json.Unmarshal(body, &returnData)
return returnData
}

// ReturnWebStatus Get Web Uptime Status.
func ReturnWebStatus() WebPingStauts {
url := "https://maihook.lemonkoi.one/api/ping"
method := "GET"
client := &http.Client{}
req, err := http.NewRequest(method, url, nil)

if err != nil {
fmt.Println(err)
return WebPingStauts{}
}
req.Header.Add("Accept", "*/*")
req.Header.Add("Host", "maihook.lemonkoi.one")
req.Header.Add("Connection", "keep-alive")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return WebPingStauts{}
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return WebPingStauts{}
}
var returnData WebPingStauts
json.Unmarshal(body, &returnData)
return returnData
}

func ConvertZlib(value, total int) string {
if total == 0 {
return "0.000%"
}
percentage := float64(value) / float64(total) * 100
return fmt.Sprintf("%.3f%%", percentage)
}

func ConvertFloat(data float64) string {
return strconv.FormatFloat(data, 'f', 3, 64)
}

0 comments on commit e2d300c

Please # to comment.