22package score
33
44import (
5+ "encoding/base64"
56 "math"
67 "math/rand"
78 "os"
@@ -106,9 +107,20 @@ func init() {
106107 // 如果签到时间是今天
107108 ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text ("今天你已经签到过了!" ))
108109 if file .IsExist (drawedFile ) {
109- ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile ))
110+ //使用"file:"发送图片失败后,使用base64发送
111+ if id := ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile )); id .ID () == 0 {
112+ if file .IsExist (drawedFile ) {
113+ drawedFileData , err := os .ReadFile (file .BOTPATH + "/" + drawedFile )
114+ if err != nil {
115+ ctx .SendChain (message .Text ("ERROR: 无法读取图片文件" , err ))
116+ return
117+ }
118+ drawedFileBase64 := base64 .StdEncoding .EncodeToString (drawedFileData )
119+ ctx .SendChain (message .Image ("base64://" + drawedFileBase64 ))
120+ }
121+ }
122+ return
110123 }
111- return
112124 case siUpdateTimeStr != today :
113125 // 如果是跨天签到就清数据
114126 err := sdb .InsertOrUpdateSignInCountByUID (uid , 0 )
@@ -176,7 +188,18 @@ func init() {
176188 ctx .SendChain (message .Text ("ERROR: " , err ))
177189 return
178190 }
179- ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile ))
191+ //使用"file:"发送图片失败后,使用base64发送
192+ if id := ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile )); id .ID () == 0 {
193+ if file .IsExist (drawedFile ) {
194+ drawedFileData , err := os .ReadFile (file .BOTPATH + "/" + drawedFile )
195+ if err != nil {
196+ ctx .SendChain (message .Text ("ERROR: 无法读取图片文件" , err ))
197+ return
198+ }
199+ drawedFileBase64 := base64 .StdEncoding .EncodeToString (drawedFileData )
200+ ctx .SendChain (message .Image ("base64://" + drawedFileBase64 ))
201+ }
202+ }
180203 })
181204
182205 engine .OnPrefix ("获得签到背景" , zero .OnlyGroup ).Limit (ctxext .LimitByGroup ).SetBlock (true ).
@@ -194,15 +217,33 @@ func init() {
194217 return
195218 }
196219 if id := ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + picFile )); id .ID () == 0 {
197- ctx .SendChain (message .Text ("ERROR: 消息发送失败, 账号可能被风控" ))
220+ //使用"file:"发送图片失败后,使用base64发送
221+ picFileFileData , err := os .ReadFile (file .BOTPATH + "/" + picFile )
222+ if err != nil {
223+ ctx .SendChain (message .Text ("ERROR: 无法读取图片文件" , err ))
224+ return
225+ }
226+ drawedFileBase64 := base64 .StdEncoding .EncodeToString (picFileFileData )
227+ ctx .SendChain (message .Image ("base64://" + drawedFileBase64 ))
198228 }
199229 })
200230 engine .OnFullMatch ("查看等级排名" , zero .OnlyGroup ).Limit (ctxext .LimitByGroup ).SetBlock (true ).
201231 Handle (func (ctx * zero.Ctx ) {
202232 today := time .Now ().Format ("20060102" )
203233 drawedFile := cachePath + today + "scoreRank.png"
204234 if file .IsExist (drawedFile ) {
205- ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile ))
235+ //使用"file:"发送图片失败后,使用base64发送
236+ if id := ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile )); id .ID () == 0 {
237+ if file .IsExist (drawedFile ) {
238+ drawedFileData , err := os .ReadFile (file .BOTPATH + "/" + drawedFile )
239+ if err != nil {
240+ ctx .SendChain (message .Text ("ERROR: 无法读取图片文件" , err ))
241+ return
242+ }
243+ drawedFileBase64 := base64 .StdEncoding .EncodeToString (drawedFileData )
244+ ctx .SendChain (message .Image ("base64://" + drawedFileBase64 ))
245+ }
246+ }
206247 return
207248 }
208249 st , err := sdb .GetScoreRankByTopN (10 )
@@ -267,7 +308,18 @@ func init() {
267308 ctx .SendChain (message .Text ("ERROR: " , err ))
268309 return
269310 }
270- ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile ))
311+ //使用"file:"发送图片失败后,使用base64发送
312+ if id := ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile )); id .ID () == 0 {
313+ if file .IsExist (drawedFile ) {
314+ drawedFileData , err := os .ReadFile (file .BOTPATH + "/" + drawedFile )
315+ if err != nil {
316+ ctx .SendChain (message .Text ("ERROR: 无法读取图片文件" , err ))
317+ return
318+ }
319+ drawedFileBase64 := base64 .StdEncoding .EncodeToString (drawedFileData )
320+ ctx .SendChain (message .Image ("base64://" + drawedFileBase64 ))
321+ }
322+ }
271323 })
272324 engine .OnRegex (`^设置签到预设\s*(\d+)$` , zero .SuperUserPermission ).Limit (ctxext .LimitByUser ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
273325 key := ctx .State ["regex_matched" ].([]string )[1 ]
0 commit comments