From 2b00c7af986fc3afc5edc945b02894954d43deaa Mon Sep 17 00:00:00 2001 From: Tenko Date: Fri, 28 Jun 2024 14:48:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E6=9D=83=E9=99=90=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/go.mod | 2 +- src/go.sum | 4 +-- src/plugins/gatekeeper/callback_handle.go | 2 +- src/plugins/system/callback_handle.go | 2 +- src/utils/base_utils.go | 30 +++++++++++------------ 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/go.mod b/src/go.mod index 36138f7..75b4f69 100644 --- a/src/go.mod +++ b/src/go.mod @@ -7,7 +7,7 @@ require ( github.com/fsnotify/fsnotify v1.6.0 github.com/gin-gonic/gin v1.9.1 github.com/go-redis/redis/v8 v8.11.5 - github.com/ijnkawakaze/telegram-bot-api v1.0.7 + github.com/ijnkawakaze/telegram-bot-api v1.0.8 github.com/matoous/go-nanoid/v2 v2.0.0 github.com/playwright-community/playwright-go v0.2000.1 github.com/robfig/cron/v3 v3.0.0 diff --git a/src/go.sum b/src/go.sum index 200d574..2cb9449 100644 --- a/src/go.sum +++ b/src/go.sum @@ -181,8 +181,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/ijnkawakaze/telegram-bot-api v1.0.7 h1:QjPDEccFJUa1VjQmsmkwwFSmkJDSjVRz95cSif+/7mU= -github.com/ijnkawakaze/telegram-bot-api v1.0.7/go.mod h1:jXTw4A2ySR+sof3J4R/ODl99MwFqeoXbWyyhWACGh+E= +github.com/ijnkawakaze/telegram-bot-api v1.0.8 h1:8XnoMd0Hnf5JpsqFjxkwZXDVv+/gqmhcyvFh4buwtgM= +github.com/ijnkawakaze/telegram-bot-api v1.0.8/go.mod h1:jXTw4A2ySR+sof3J4R/ODl99MwFqeoXbWyyhWACGh+E= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= diff --git a/src/plugins/gatekeeper/callback_handle.go b/src/plugins/gatekeeper/callback_handle.go index 348b944..6666b52 100644 --- a/src/plugins/gatekeeper/callback_handle.go +++ b/src/plugins/gatekeeper/callback_handle.go @@ -25,7 +25,7 @@ func CallBackData(callBack tgbotapi.Update) error { if d[2] == "PASS" || d[2] == "BAN" { - if !bot.Arknights.IsAdmin(chatId, callbackQuery.From.ID) { + if !bot.Arknights.IsAdminWithPermissions(chatId, callbackQuery.From.ID, 16) { callbackQuery.Answer(true, "无使用权限!") return nil } diff --git a/src/plugins/system/callback_handle.go b/src/plugins/system/callback_handle.go index 4004164..452b54e 100644 --- a/src/plugins/system/callback_handle.go +++ b/src/plugins/system/callback_handle.go @@ -22,7 +22,7 @@ func Report(callBack tgbotapi.Update) error { target, _ := strconv.ParseInt(d[2], 10, 64) targetMessageId, _ := strconv.Atoi(d[3]) - if !bot.Arknights.IsAdmin(chatId, userId) { + if !bot.Arknights.IsAdminWithPermissions(chatId, userId, 16) { callbackQuery.Answer(true, "无使用权限!") return nil } diff --git a/src/utils/base_utils.go b/src/utils/base_utils.go index 8d0fba9..2848384 100644 --- a/src/utils/base_utils.go +++ b/src/utils/base_utils.go @@ -27,6 +27,8 @@ import ( var ctx = context.Background() +var browser playwright.Browser + type GroupInvite struct { Id string `json:"id" gorm:"primaryKey"` GroupName string `json:"groupName"` @@ -247,27 +249,23 @@ func RedisDelSetItem(key string, val string) { // Screenshot 屏幕截图 func Screenshot(url string, waitTime float64, scale float64) []byte { - pw, err := playwright.Run() - if err != nil { - log.Println("未检测到playwright,开始自动安装...") - playwright.Install() - pw, _ = playwright.Run() - } - browser, err := pw.Chromium.Launch() - if err != nil { - log.Println(err) - return nil + if browser == nil { + pw, err := playwright.Run() + if err != nil { + log.Println("未检测到playwright,开始自动安装...") + playwright.Install() + pw, _ = playwright.Run() + } + browser, err = pw.Chromium.Launch() + if err != nil { + log.Println(err) + return nil + } } page, _ := browser.NewPage(playwright.BrowserNewContextOptions{DeviceScaleFactor: &scale}) - if err != nil { - log.Println(err) - return nil - } defer func() { log.Println("关闭playwright") page.Close() - browser.Close() - pw.Stop() }() log.Println("开始进行截图...") page.Goto(url, playwright.PageGotoOptions{