fix bot safety and tgapi edge cases
This commit is contained in:
+15
-5
@@ -422,13 +422,23 @@ func (ctx *MsgContext) newDraft(parseMode tgapi.ParseMode) *Draft {
|
||||
ctx.Logger.Errorln("can't create draft: ctx.Msg is nil")
|
||||
return nil
|
||||
}
|
||||
|
||||
c, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := ctx.Api.Limiter.Wait(c, ctx.Msg.Chat.ID); err != nil {
|
||||
ctx.Logger.Errorln(err)
|
||||
if ctx.Api == nil {
|
||||
ctx.Logger.Errorln("can't create draft: ctx.Api is nil")
|
||||
return nil
|
||||
}
|
||||
if ctx.draftProvider == nil {
|
||||
ctx.Logger.Errorln("can't create draft: ctx.draftProvider is nil")
|
||||
return nil
|
||||
}
|
||||
|
||||
if ctx.Api.Limiter != nil {
|
||||
c, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := ctx.Api.Limiter.Wait(c, ctx.Msg.Chat.ID); err != nil {
|
||||
ctx.Logger.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
draft := ctx.draftProvider.NewDraft(parseMode).SetChat(ctx.Msg.Chat.ID, ctx.Msg.MessageThreadID)
|
||||
return draft
|
||||
|
||||
Reference in New Issue
Block a user