Try to gracefully stop all existing goroutines
This commit is contained in:
parent
f240def745
commit
86ddbb26f8
@ -24,56 +24,54 @@ func ZookeeperReceiver(client *tdlib.Client) {
|
||||
receiver := client.AddEventReceiver(&tdlib.UpdateNewMessage{}, fwMessagesFilter, 5)
|
||||
log.Debug().Msg("Receiver added")
|
||||
|
||||
go func() {
|
||||
for newMsg := range receiver.Chan {
|
||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
||||
// Check if message text contains needed battle data
|
||||
msgText := updateMsg.Message.Content.(*tdlib.MessageText)
|
||||
if strings.HasPrefix(msgText.Text.Text, "Я встретил") {
|
||||
log.Debug().Msgf("%s", msgText.Text.Text)
|
||||
battleType := ""
|
||||
battleTag := ""
|
||||
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:
|
||||
keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard)
|
||||
if len(keyboard.Rows) > 0 {
|
||||
if len(keyboard.Rows[0]) > 0 {
|
||||
button := keyboard.Rows[0][0]
|
||||
switch button.Type.(type) {
|
||||
case *tdlib.InlineKeyboardButtonTypeSwitchInline:
|
||||
buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline)
|
||||
battleTag = string(buttonQuery.Query)
|
||||
default:
|
||||
log.Error().Msg("Invalid button type")
|
||||
}
|
||||
for newMsg := range receiver.Chan {
|
||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
||||
// Check if message text contains needed battle data
|
||||
msgText := updateMsg.Message.Content.(*tdlib.MessageText)
|
||||
if strings.HasPrefix(msgText.Text.Text, "Я встретил") {
|
||||
log.Debug().Msgf("%s", msgText.Text.Text)
|
||||
battleType := ""
|
||||
battleTag := ""
|
||||
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:
|
||||
keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard)
|
||||
if len(keyboard.Rows) > 0 {
|
||||
if len(keyboard.Rows[0]) > 0 {
|
||||
button := keyboard.Rows[0][0]
|
||||
switch button.Type.(type) {
|
||||
case *tdlib.InlineKeyboardButtonTypeSwitchInline:
|
||||
buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline)
|
||||
battleTag = string(buttonQuery.Query)
|
||||
default:
|
||||
log.Error().Msg("Invalid button type")
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Error().Msg("Invalid keyboard type")
|
||||
}
|
||||
log.Debug().Msgf("Battle type: %s", battleType)
|
||||
log.Debug().Msgf("Battle tag: %s", battleTag)
|
||||
|
||||
replyText := battleType + " " + battleTag
|
||||
|
||||
reply := tdlib.NewInputMessageText(tdlib.NewFormattedText(replyText, nil), true, true)
|
||||
_, err := client.SendMessage(announcerID, 0, false, true, nil, reply)
|
||||
if err != nil {
|
||||
log.Error().Err(err)
|
||||
}
|
||||
default:
|
||||
log.Error().Msg("Invalid keyboard type")
|
||||
}
|
||||
log.Debug().Msgf("Battle type: %s", battleType)
|
||||
log.Debug().Msgf("Battle tag: %s", battleTag)
|
||||
|
||||
<-c.ShutdownDone
|
||||
return
|
||||
replyText := battleType + " " + battleTag
|
||||
|
||||
reply := tdlib.NewInputMessageText(tdlib.NewFormattedText(replyText, nil), true, true)
|
||||
_, err := client.SendMessage(announcerID, 0, false, true, nil, reply)
|
||||
if err != nil {
|
||||
log.Error().Err(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
<-c.ShutdownDone
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,9 @@ func Authenticate() {
|
||||
func Connect() {
|
||||
go func() {
|
||||
announcesv1.ZookeeperReceiver(client)
|
||||
|
||||
<-c.ShutdownDone
|
||||
return
|
||||
}()
|
||||
rawUpdates := client.GetRawUpdatesChannel(100)
|
||||
log.Debug().Msg("Connection with Telegram established")
|
||||
|
Reference in New Issue
Block a user