@@ -142,7 +142,7 @@ func deletePicture(ctx context.Context, bot *telego.Bot, message telego.Message)
142
142
channelMessageID = originChannel .MessageID
143
143
}
144
144
if cmd == "del" {
145
- if ! service .CheckAdminPermission (ctx , message .From .ID , types .DeletePicture ) {
145
+ if ! service .CheckAdminPermission (ctx , message .From .ID , types .PermissionDeleteArtwork ) {
146
146
telegram .ReplyMessage (bot , message , "你没有删除图片的权限" )
147
147
return
148
148
}
@@ -164,7 +164,7 @@ func deletePicture(ctx context.Context, bot *telego.Bot, message telego.Message)
164
164
}
165
165
return
166
166
}
167
- if ! service .CheckAdminPermission (ctx , message .From .ID , types .DeleteArtwork ) {
167
+ if ! service .CheckAdminPermission (ctx , message .From .ID , types .PermissionDeleteArtwork ) {
168
168
telegram .ReplyMessage (bot , message , "你没有删除作品的权限" )
169
169
return
170
170
}
@@ -196,7 +196,7 @@ func deletePicture(ctx context.Context, bot *telego.Bot, message telego.Message)
196
196
}
197
197
198
198
func fetchArtwork (ctx context.Context , bot * telego.Bot , message telego.Message ) {
199
- if ! service .CheckAdminPermission (ctx , message .From .ID , types .FetchArtwork ) {
199
+ if ! service .CheckAdminPermission (ctx , message .From .ID , types .PermissionFetchArtwork ) {
200
200
telegram .ReplyMessage (bot , message , "你没有拉取作品的权限" )
201
201
return
202
202
}
@@ -206,7 +206,7 @@ func fetchArtwork(ctx context.Context, bot *telego.Bot, message telego.Message)
206
206
}
207
207
208
208
func postArtwork (ctx context.Context , bot * telego.Bot , query telego.CallbackQuery ) {
209
- if ! service .CheckAdminPermission (ctx , query .From .ID , types .PostArtwork ) {
209
+ if ! service .CheckAdminPermission (ctx , query .From .ID , types .PermissionPostArtwork ) {
210
210
bot .AnswerCallbackQuery (& telego.AnswerCallbackQueryParams {
211
211
CallbackQueryID : query .ID ,
212
212
Text : "你没有发布作品的权限" ,
@@ -227,18 +227,39 @@ func postArtwork(ctx context.Context, bot *telego.Bot, query telego.CallbackQuer
227
227
return
228
228
}
229
229
Logger .Infof ("posting artwork: %s" , sourceURL )
230
- artwork , err := service .GetCachedArtworkByURL (ctx , sourceURL )
230
+
231
+ var artwork * types.Artwork
232
+ cachedArtwork , err := service .GetCachedArtworkByURL (ctx , sourceURL )
231
233
if err != nil {
232
234
artwork , err = sources .GetArtworkInfo (sourceURL )
233
- }
234
- if err != nil {
235
- bot .AnswerCallbackQuery (& telego.AnswerCallbackQueryParams {
236
- CallbackQueryID : query .ID ,
237
- Text : "获取作品信息失败" + err .Error (),
238
- ShowAlert : true ,
239
- CacheTime : 60 ,
240
- })
241
- return
235
+ if err != nil {
236
+ bot .AnswerCallbackQuery (& telego.AnswerCallbackQueryParams {
237
+ CallbackQueryID : query .ID ,
238
+ Text : "获取作品信息失败" + err .Error (),
239
+ ShowAlert : true ,
240
+ CacheTime : 60 ,
241
+ })
242
+ return
243
+ }
244
+ } else {
245
+ if cachedArtwork .Status == types .ArtworkStatusPosting {
246
+ bot .AnswerCallbackQuery (& telego.AnswerCallbackQueryParams {
247
+ CallbackQueryID : query .ID ,
248
+ Text : "该作品正在发布中" ,
249
+ ShowAlert : true ,
250
+ CacheTime : 60 ,
251
+ })
252
+ return
253
+ }
254
+ if err := service .UpdateCachedArtworkByURL (ctx , sourceURL , types .ArtworkStatusPosting ); err != nil {
255
+ Logger .Errorf ("更新缓存作品状态失败: %s" , err )
256
+ }
257
+ artwork = cachedArtwork .Artwork
258
+ defer func () {
259
+ if err := service .UpdateCachedArtworkByURL (ctx , sourceURL , types .ArtworkStatusCached ); err != nil {
260
+ Logger .Errorf ("更新缓存作品状态失败: %s" , err )
261
+ }
262
+ }()
242
263
}
243
264
go bot .EditMessageCaption (& telego.EditMessageCaptionParams {
244
265
ChatID : telegoutil .ID (query .Message .GetChat ().ID ),
0 commit comments