Skip to content

Commit

Permalink
update:ad处理后直接删除验证消息
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashang committed Dec 15, 2022
1 parent 183542e commit d2be616
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions telegram/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ var (
)

var (
gMessageTokenMap sync.Map
gMessageTokenMap sync.Map
gUserIdToJoinCaptchaMessageIdMap sync.Map
)

// StartCaptcha 开始验证
Expand Down Expand Up @@ -177,9 +178,15 @@ func AdBlock(c tb.Context) error {
}, isManageMiddleware)
//删除验证消息
go func() {
userIdStr := strconv.FormatInt(userId, 10)
captchaCode := gUserCaptchaCodeTable.Get(userIdStr)
if err = Bot.Delete(captchaCode.CaptchaMessage); err != nil {
msgObj, ok := gUserIdToJoinCaptchaMessageIdMap.Load(userId)
if !ok {
return
}
delPendingMsg, ok := msgObj.(*tb.Message)
if !ok {
return
}
if err = Bot.Delete(delPendingMsg); err != nil {
log.Sugar.Error("[AdBlock] delete captcha message err:", err)
}
}()
Expand Down Expand Up @@ -271,6 +278,7 @@ func UserJoinGroup(c tb.Context) error {
}
// 设置token对于验证消息
gMessageTokenMap.Store(chatToken, fmt.Sprintf("%d|%d|%s", captchaMessage.ID, c.Chat().ID, c.Chat().Title))
gUserIdToJoinCaptchaMessageIdMap.Store(c.Sender().ID, captchaMessage)
captchaDataVal := &service.CaptchaPending{
PendingMessage: captchaMessage,
UserId: c.Message().UserJoined.ID,
Expand Down

0 comments on commit d2be616

Please sign in to comment.