Fix typos, remove unwanted goroutines
This commit is contained in:
parent
66638518ea
commit
a98179a6ed
@ -16,58 +16,57 @@ func fwMessagesFilter(msg *tdlib.TdMessage) bool {
|
|||||||
|
|
||||||
// ZookeeperReceiver adds announcement functionality to bot
|
// ZookeeperReceiver adds announcement functionality to bot
|
||||||
func ZookeeperReceiver(client *tdlib.Client) {
|
func ZookeeperReceiver(client *tdlib.Client) {
|
||||||
log.Debug().Msg("Adding receiver for @FWorld_bot messages...")
|
log.Debug().Msg("Adding receiver for @FWorldBot messages...")
|
||||||
// Here we can add a receiver to retreive any message type we want
|
// Here we can add a receiver to retreive any message type we want
|
||||||
// We like to get UpdateNewMessage events and with a specific FilterFunc
|
// We like to get UpdateNewMessage events and with a specific FilterFunc
|
||||||
receiver := client.AddEventReceiver(&tdlib.UpdateNewMessage{}, fwMessagesFilter, 5)
|
receiver := client.AddEventReceiver(&tdlib.UpdateNewMessage{}, fwMessagesFilter, 5)
|
||||||
log.Debug().Msg("Receiver added")
|
log.Debug().Msg("Receiver added")
|
||||||
go func() {
|
|
||||||
for newMsg := range receiver.Chan {
|
for newMsg := range receiver.Chan {
|
||||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
||||||
// Check if message text contains needed battle data
|
// Check if message text contains needed battle data
|
||||||
msgText := updateMsg.Message.Content.(*tdlib.MessageText)
|
msgText := updateMsg.Message.Content.(*tdlib.MessageText)
|
||||||
if strings.HasPrefix(msgText.Text.Text, "Я встретил") {
|
if strings.HasPrefix(msgText.Text.Text, "Я встретил") {
|
||||||
log.Debug().Msgf("%s", msgText.Text.Text)
|
log.Debug().Msgf("%s", msgText.Text.Text)
|
||||||
battleType := ""
|
battleType := ""
|
||||||
battleTag := ""
|
battleTag := ""
|
||||||
if strings.Contains(msgText.Text.Text, "Огров") {
|
if strings.Contains(msgText.Text.Text, "Огров") {
|
||||||
battleType = "Огры!"
|
battleType = "Огры!"
|
||||||
}
|
}
|
||||||
if strings.Contains(msgText.Text.Text, "Буйволов") {
|
if strings.Contains(msgText.Text.Text, "Буйволов") {
|
||||||
battleType = "Буйволы!"
|
battleType = "Буйволы!"
|
||||||
}
|
}
|
||||||
if strings.Contains(msgText.Text.Text, "Кабанов") {
|
if strings.Contains(msgText.Text.Text, "Кабанов") {
|
||||||
battleType = "Кабаны!"
|
battleType = "Кабаны!"
|
||||||
}
|
}
|
||||||
switch updateMsg.Message.ReplyMarkup.(type) {
|
switch updateMsg.Message.ReplyMarkup.(type) {
|
||||||
case *tdlib.ReplyMarkupInlineKeyboard:
|
case *tdlib.ReplyMarkupInlineKeyboard:
|
||||||
keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard)
|
keyboard := updateMsg.Message.ReplyMarkup.(*tdlib.ReplyMarkupInlineKeyboard)
|
||||||
if len(keyboard.Rows) > 0 {
|
if len(keyboard.Rows) > 0 {
|
||||||
if len(keyboard.Rows[0]) > 0 {
|
if len(keyboard.Rows[0]) > 0 {
|
||||||
button := keyboard.Rows[0][0]
|
button := keyboard.Rows[0][0]
|
||||||
switch button.Type.(type) {
|
switch button.Type.(type) {
|
||||||
case *tdlib.InlineKeyboardButtonTypeSwitchInline:
|
case *tdlib.InlineKeyboardButtonTypeSwitchInline:
|
||||||
buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline)
|
buttonQuery := button.Type.(*tdlib.InlineKeyboardButtonTypeSwitchInline)
|
||||||
battleTag = string(buttonQuery.Query)
|
battleTag = string(buttonQuery.Query)
|
||||||
default:
|
default:
|
||||||
log.Error().Msg("Invalid button type")
|
log.Error().Msg("Invalid button type")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
log.Error().Msg("Invalid keyboard type")
|
|
||||||
}
|
}
|
||||||
log.Debug().Msgf("Battle type: %s", battleType)
|
default:
|
||||||
log.Debug().Msgf("Battle tag: %s", battleTag)
|
log.Error().Msg("Invalid keyboard type")
|
||||||
|
}
|
||||||
|
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(updateMsg.Message.ChatID, 0, false, true, nil, reply)
|
_, err := client.SendMessage(updateMsg.Message.ChatID, 0, false, true, nil, reply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err)
|
log.Error().Err(err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user