refactor: 自动截取整页

This commit is contained in:
lixiangwuxian 2024-10-13 16:04:05 +08:00
parent 2290146862
commit 9f5106663f
4 changed files with 19 additions and 7 deletions

View File

@ -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,

View File

@ -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{

View File

@ -16,10 +16,10 @@ func (c Command) ToString() string {
if c.CommandName != "score" {
return ""
}
strWithRank := "玩家 %s 使用 %s 在 %s 的 %s 难度(星级为%.1f)中获得了 %d 分,排名第 %dpp 为 %.2f。"
strWithRank := "玩家 %s 使用 %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分,排名第 %dpp 为 %.2f。"
strWithoutRank := "玩家 %s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,排名第 %d。"
strWithOutDevice := "玩家 %s 在 %s 的 %s 难度(星级为%.1f)中获得了 %d 分,排名第 %dpp 为 %.2f。"
strWithOutDeviceAndRank := "玩家 %s 在 %s 的 %s 难度(星级为%.1f)中获得了 %d 分。"
strWithOutDevice := "玩家 %s 在 %s 的 %s 难度(%.1f🌟)中获得了 %d 分,排名第 %dpp 为 %.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"

View File

@ -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),