From 9f5106663f9050ed0607a419315593a0f0c2b70e Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sun, 13 Oct 2024 16:04:05 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=87=AA=E5=8A=A8=E6=88=AA?= =?UTF-8?q?=E5=8F=96=E6=95=B4=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/getweb/getweb.go | 2 +- handler/urlparser/url.go | 9 ++++++++- service/scoresaber/model.go | 10 +++++----- util/web_page_shot.go | 5 +++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/handler/getweb/getweb.go b/handler/getweb/getweb.go index 09beb7d..4b6b818 100644 --- a/handler/getweb/getweb.go +++ b/handler/getweb/getweb.go @@ -15,7 +15,7 @@ func getweb(msg model.Message) (reply model.Reply) { return model.Reply{} } url := msg.RawMsg[len("上网 "):] - if err := util.ScreenshotURL(url, "./tmp/getweb/url.png", 1920, 1080, 0, 0, 0, 0, ""); err != nil { + if err := util.ScreenshotURL(url, "./tmp/getweb/url.png", 0, 0, 0, 0, 0, 0, ""); err != nil { return model.Reply{ ReplyMsg: err.Error(), ReferOriginMsg: true, diff --git a/handler/urlparser/url.go b/handler/urlparser/url.go index a0b8d4f..191374a 100644 --- a/handler/urlparser/url.go +++ b/handler/urlparser/url.go @@ -26,7 +26,14 @@ func plainTextUrlParser(msg model.Message) (reply model.Reply) { url = strings.Split(url, "\r")[0] url = strings.Split(url, "\t")[0] url, _ = removeTrackingParams(url) - newUrl, _ := resolveFinalURL(url) + newUrl, err := resolveFinalURL(url) + if err != nil { + return model.Reply{ + ReplyMsg: "", + ReferOriginMsg: false, + FromMsg: msg, + } + } newUrl, _ = removeTrackingParams(newUrl) if util.IsEquivalentURL(url, newUrl) { return model.Reply{ diff --git a/service/scoresaber/model.go b/service/scoresaber/model.go index 1a9406e..ed3f966 100644 --- a/service/scoresaber/model.go +++ b/service/scoresaber/model.go @@ -16,10 +16,10 @@ func (c Command) ToString() string { if c.CommandName != "score" { return "" } - strWithRank := "玩家 %s 使用 %s 在 %s 的 %s 难度(星级为%.1f)中获得了 %d 分,排名第 %d,pp 为 %.2f。" + strWithRank := "玩家 %s 使用 %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分,排名第 %d,pp 为 %.2f。" strWithoutRank := "玩家 %s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,排名第 %d。" - strWithOutDevice := "玩家 %s 在 %s 的 %s 难度(星级为%.1f)中获得了 %d 分,排名第 %d,pp 为 %.2f。" - strWithOutDeviceAndRank := "玩家 %s 在 %s 的 %s 难度(星级为%.1f)中获得了 %d 分。" + strWithOutDevice := "玩家 %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分,排名第 %d,pp 为 %.2f。" + strWithOutDeviceAndRank := "玩家 %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分。" hardStr := strings.Split(c.CommandData.Leaderboard.Difficulty.DifficultyRaw, "_")[1] if c.CommandData.Leaderboard.Ranked && c.CommandData.Score.DeviceHmd != nil { return fmt.Sprintf(strWithRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, *c.CommandData.Score.DeviceHmd, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.ModifiedScore, c.CommandData.Score.Rank, c.CommandData.Score.Pp) @@ -138,9 +138,9 @@ type RecordDataLite struct { } func (r RecordDataLite) ToString() string { - formatedStrRanked := "%s,%s 使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。" + formatedStrRanked := "%s,%s 使用 %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分,pp 为 %.2f,准度为 %s。" formatedStrUnranked := "%s, %s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。" - formatedStrWithoutDevice := "%s, %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。" + formatedStrWithoutDevice := "%s, %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分,pp 为 %.2f,准度为 %s。" formatedStrWithoutDeviceAndRank := "%s, %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。" hardStr := strings.Split(r.DifficultyRaw, "_")[1] layout := "2006-01-02 15:04:05.999999999-07:00" diff --git a/util/web_page_shot.go b/util/web_page_shot.go index b62a903..ed67cfb 100644 --- a/util/web_page_shot.go +++ b/util/web_page_shot.go @@ -76,6 +76,11 @@ func ScreenshotURL(url, output string, width, height int, marginTop, marginBotto ignoreErrors(queryAction), // 等待指定元素 chromedp.Sleep(5*time.Second), chromedp.ActionFunc(func(ctx context.Context) error { // 自定义截图逻辑 + layoutViewport, _, _, _, _, _, _ := page.GetLayoutMetrics().Do(ctx) + if width == 0 || height == 0 { + width = int(layoutViewport.ClientWidth) + height = int(layoutViewport.ClientHeight) + } // 计算调整后的截图区域 clip := &page.Viewport{ X: float64(marginLeft),