1

Fix another lock after first received update

This commit is contained in:
Vladimir Hodakov 2019-01-10 05:36:06 +04:00
parent f2dc39b2d7
commit 3c9390a295
Signed by: Vladimir Hodakov
GPG Key ID: 673980B6882F82C6

View File

@ -24,54 +24,56 @@ func ZookeeperReceiver(client *tdlib.Client) {
receiver := client.AddEventReceiver(&tdlib.UpdateNewMessage{}, fwMessagesFilter, 5) receiver := client.AddEventReceiver(&tdlib.UpdateNewMessage{}, fwMessagesFilter, 5)
log.Debug().Msg("Receiver added") log.Debug().Msg("Receiver added")
for newMsg := range receiver.Chan { go func() {
updateMsg := (newMsg).(*tdlib.UpdateNewMessage) for newMsg := range receiver.Chan {
// Check if message text contains needed battle data updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
msgText := updateMsg.Message.Content.(*tdlib.MessageText) // Check if message text contains needed battle data
if strings.HasPrefix(msgText.Text.Text, "Я встретил") { msgText := updateMsg.Message.Content.(*tdlib.MessageText)
log.Debug().Msgf("%s", msgText.Text.Text) if strings.HasPrefix(msgText.Text.Text, "Я встретил") {
battleType := "" log.Debug().Msgf("%s", msgText.Text.Text)
battleTag := "" battleType := ""
if strings.Contains(msgText.Text.Text, "Огров") { battleTag := ""
battleType = "Огры!" if strings.Contains(msgText.Text.Text, "Огров") {
} battleType = "Огры!"
if strings.Contains(msgText.Text.Text, "Буйволов") { }
battleType = "Буйволы!" if strings.Contains(msgText.Text.Text, "Буйволов") {
} battleType = "Буйволы!"
if strings.Contains(msgText.Text.Text, "Кабанов") { }
battleType = "Кабаны!" if strings.Contains(msgText.Text.Text, "Кабанов") {
} battleType = "Кабаны!"
switch updateMsg.Message.ReplyMarkup.(type) { }
case *tdlib.ReplyMarkupInlineKeyboard: switch updateMsg.Message.ReplyMarkup.(type) {
keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard) case *tdlib.ReplyMarkupInlineKeyboard:
if len(keyboard.Rows) > 0 { keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard)
if len(keyboard.Rows[0]) > 0 { if len(keyboard.Rows) > 0 {
button := keyboard.Rows[0][0] if len(keyboard.Rows[0]) > 0 {
switch button.Type.(type) { button := keyboard.Rows[0][0]
case *tdlib.InlineKeyboardButtonTypeSwitchInline: switch button.Type.(type) {
buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline) case *tdlib.InlineKeyboardButtonTypeSwitchInline:
battleTag = string(buttonQuery.Query) buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline)
default: battleTag = string(buttonQuery.Query)
log.Error().Msg("Invalid button type") default:
log.Error().Msg("Invalid button type")
}
} }
} }
default:
log.Error().Msg("Invalid keyboard type")
} }
default: log.Debug().Msgf("Battle type: %s", battleType)
log.Error().Msg("Invalid keyboard type") log.Debug().Msgf("Battle tag: %s", battleTag)
}
log.Debug().Msgf("Battle type: %s", battleType)
log.Debug().Msgf("Battle tag: %s", battleTag)
replyText := battleType + " " + battleTag replyText := battleType + " " + battleTag
reply := tdlib.NewInputMessageText(tdlib.NewFormattedText(replyText, nil), true, true) reply := tdlib.NewInputMessageText(tdlib.NewFormattedText(replyText, nil), true, true)
_, err := client.SendMessage(announcerID, 0, false, true, nil, reply) _, err := client.SendMessage(announcerID, 0, false, true, nil, reply)
if err != nil { if err != nil {
log.Error().Err(err) log.Error().Err(err)
}
} }
} }
<-c.ShutdownDone <-c.ShutdownDone
return return
} }()
} }