@@ -49,23 +49,31 @@ func init() {
49
49
siUpdateTimeStr := si .UpdatedAt .Format ("20060102" )
50
50
if siUpdateTimeStr != today {
51
51
if err := sdb .InsertOrUpdateSignInCountByUID (uid , 0 ); err != nil {
52
- log .Errorln ("[score]:" , err )
52
+ ctx .SendChain (message .Text ("ERROR:" , err ))
53
+ return
53
54
}
54
55
}
56
+
57
+ drawedFile := cachePath + strconv .FormatInt (uid , 10 ) + today + "signin.png"
55
58
if si .Count >= signinMax && siUpdateTimeStr == today {
56
59
ctx .SendChain (message .Reply (ctx .Event .MessageID ), message .Text ("今天你已经签到过了!" ))
60
+ if file .IsExist (drawedFile ) {
61
+ ctx .SendChain (message .Image ("file:///" + file .BOTPATH + "/" + drawedFile ))
62
+ }
57
63
return
58
64
}
59
65
60
66
picFile := cachePath + strconv .FormatInt (uid , 10 ) + today + ".png"
61
67
initPic (picFile )
62
68
63
69
if err := sdb .InsertOrUpdateSignInCountByUID (uid , si .Count + 1 ); err != nil {
64
- log .Errorln ("[score]:" , err )
70
+ ctx .SendChain (message .Text ("ERROR:" , err ))
71
+ return
65
72
}
66
73
back , err := gg .LoadImage (picFile )
67
74
if err != nil {
68
- log .Errorln ("[score]:" , err )
75
+ ctx .SendChain (message .Text ("ERROR:" , err ))
76
+ return
69
77
}
70
78
canvas := gg .NewContext (back .Bounds ().Size ().X , int (float64 (back .Bounds ().Size ().Y )* 1.7 ))
71
79
canvas .SetRGB (1 , 1 , 1 )
@@ -75,14 +83,16 @@ func init() {
75
83
monthWord := now .Format ("01/02" )
76
84
hourWord := getHourWord (now )
77
85
if err = canvas .LoadFontFace (txt2img .BoldFontFile , float64 (back .Bounds ().Size ().X )* 0.1 ); err != nil {
78
- log .Println ("[score]:" , err )
86
+ ctx .SendChain (message .Text ("ERROR:" , err ))
87
+ return
79
88
}
80
89
canvas .SetRGB (0 , 0 , 0 )
81
90
canvas .DrawString (hourWord , float64 (back .Bounds ().Size ().X )* 0.1 , float64 (back .Bounds ().Size ().Y )* 1.2 )
82
91
canvas .DrawString (monthWord , float64 (back .Bounds ().Size ().X )* 0.6 , float64 (back .Bounds ().Size ().Y )* 1.2 )
83
92
nickName := ctxext .CardOrNickName (ctx , uid )
84
93
if err = canvas .LoadFontFace (txt2img .FontFile , float64 (back .Bounds ().Size ().X )* 0.04 ); err != nil {
85
- log .Println ("[score]:" , err )
94
+ ctx .SendChain (message .Text ("ERROR:" , err ))
95
+ return
86
96
}
87
97
add := 1
88
98
canvas .DrawString (nickName + fmt .Sprintf (" 小熊饼干+%d" , add ), float64 (back .Bounds ().Size ().X )* 0.1 , float64 (back .Bounds ().Size ().Y )* 1.3 )
@@ -93,7 +103,8 @@ func init() {
93
103
ctx .SendChain (message .At (uid ), message .Text ("你获得的小熊饼干已经达到上限" ))
94
104
}
95
105
if err := sdb .InsertOrUpdateScoreByUID (uid , score ); err != nil {
96
- log .Println ("[score]:" , err )
106
+ ctx .SendChain (message .Text ("ERROR:" , err ))
107
+ return
97
108
}
98
109
level := getLevel (score )
99
110
canvas .DrawString ("当前小熊饼干:" + strconv .FormatInt (int64 (score ), 10 ), float64 (back .Bounds ().Size ().X )* 0.1 , float64 (back .Bounds ().Size ().Y )* 1.4 )
@@ -112,11 +123,25 @@ func init() {
112
123
canvas .SetRGB255 (102 , 102 , 102 )
113
124
canvas .Fill ()
114
125
canvas .DrawString (fmt .Sprintf ("%d/%d" , score , nextLevelScore ), float64 (back .Bounds ().Size ().X )* 0.75 , float64 (back .Bounds ().Size ().Y )* 1.62 )
115
- canvasBase64 , err := txt2img.TxtCanvas {Canvas : canvas }.ToBase64 ()
126
+
127
+ f , err := os .Open (drawedFile )
128
+ txtc := txt2img.TxtCanvas {Canvas : canvas }
129
+ if err != nil {
130
+ log .Errorln ("[score]" , err )
131
+ canvasBase64 , err := txtc .ToBase64 ()
132
+ if err != nil {
133
+ ctx .SendChain (message .Text ("ERROR:" , err ))
134
+ return
135
+ }
136
+ ctx .SendChain (message .Image ("base64://" + helper .BytesToString (canvasBase64 )))
137
+ return
138
+ }
139
+ _ , err = txtc .WriteTo (f )
116
140
if err != nil {
117
- log .Println ("[score]:" , err )
141
+ ctx .SendChain (message .Text ("ERROR:" , err ))
142
+ return
118
143
}
119
- ctx .SendChain (message .Image ("base64 ://" + helper . BytesToString ( canvasBase64 ) ))
144
+ ctx .SendChain (message .Image ("file :/// " + file . BOTPATH + "/" + drawedFile ))
120
145
})
121
146
engine .OnPrefix ("获得签到背景" , zero .OnlyGroup ).SetBlock (true ).SetPriority (20 ).
122
147
Handle (func (ctx * zero.Ctx ) {
@@ -168,16 +193,16 @@ func initPic(picFile string) {
168
193
if file .IsNotExist (picFile ) {
169
194
data , err := web .ReqWith (backgroundURL , "GET" , referer , ua )
170
195
if err != nil {
171
- log .Errorln ("[score]: " , err )
196
+ log .Errorln ("[score]" , err )
172
197
}
173
198
picURL := gjson .Get (string (data ), "pic" ).String ()
174
199
data , err = web .ReqWith (picURL , "GET" , "" , ua )
175
200
if err != nil {
176
- log .Errorln ("[score]: " , err )
201
+ log .Errorln ("[score]" , err )
177
202
}
178
203
err = os .WriteFile (picFile , data , 0666 )
179
204
if err != nil {
180
- log .Errorln ("[score]: " , err )
205
+ log .Errorln ("[score]" , err )
181
206
}
182
207
}
183
208
}
0 commit comments