mirror of
https://github.com/fumiama/ReiBot.git
synced 2026-06-09 12:30:47 +08:00
fix MustProvidePhoto
This commit is contained in:
46
rules.go
46
rules.go
@@ -367,29 +367,31 @@ func IsPhoto(ctx *Ctx) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MustProvidePhoto 消息不存在图片阻塞120秒至有图片,超时返回 false
|
// MustProvidePhoto 消息不存在图片阻塞120秒至有图片,超时返回 false
|
||||||
func MustProvidePhoto(ctx *Ctx, needphohint, failhint string) bool {
|
func MustProvidePhoto(ctx *Ctx, needphohint, failhint string) Rule {
|
||||||
msg, ok := ctx.Value.(*tgba.Message)
|
return func(ctx *Ctx) bool {
|
||||||
if ok && len(msg.Photo) > 0 { // 确保无空
|
msg, ok := ctx.Value.(*tgba.Message)
|
||||||
ctx.State["photos"] = msg.Photo
|
if ok && len(msg.Photo) > 0 { // 确保无空
|
||||||
return true
|
ctx.State["photos"] = msg.Photo
|
||||||
}
|
return true
|
||||||
// 没有图片就索取
|
}
|
||||||
if needphohint != "" {
|
// 没有图片就索取
|
||||||
_, err := ctx.Caller.Send(tgba.NewMessage(msg.Chat.ID, needphohint))
|
if needphohint != "" {
|
||||||
if err != nil {
|
_, err := ctx.Caller.Send(tgba.NewMessage(msg.Chat.ID, needphohint))
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next := NewFutureEvent("Message", 999, false, ctx.CheckSession(), IsPhoto).Next()
|
||||||
|
select {
|
||||||
|
case <-time.After(time.Second * 120):
|
||||||
|
if failhint != "" {
|
||||||
|
_, _ = ctx.Caller.Send(tgba.NewMessage(msg.Chat.ID, failhint))
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
|
case newCtx := <-next:
|
||||||
|
ctx.State["photos"] = newCtx.State["photos"]
|
||||||
|
ctx.Event = newCtx.Event
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next := NewFutureEvent("message", 999, false, ctx.CheckSession(), IsPhoto).Next()
|
|
||||||
select {
|
|
||||||
case <-time.After(time.Second * 120):
|
|
||||||
if failhint != "" {
|
|
||||||
_, _ = ctx.Caller.Send(tgba.NewMessage(msg.Chat.ID, failhint))
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
case newCtx := <-next:
|
|
||||||
ctx.State["photos"] = newCtx.State["photos"]
|
|
||||||
ctx.Event = newCtx.Event
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user