mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
Merge pull request #946 from c9s/fix/telegram-error
bbgo: fix telegram message error, there must be one message to send
This commit is contained in:
commit
cfeb0ba97b
|
@ -145,16 +145,14 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
}
|
||||
|
||||
position := reader.CurrentPosition()
|
||||
if position != nil {
|
||||
reply.Send("Your current position:")
|
||||
reply.Send(position.PlainText())
|
||||
|
||||
if position.Base.IsZero() {
|
||||
reply.Message(fmt.Sprintf("Strategy %q has no opened position", signature))
|
||||
return fmt.Errorf("strategy %T has no opened position", strategy)
|
||||
}
|
||||
if position == nil || position.Base.IsZero() {
|
||||
reply.Message(fmt.Sprintf("Strategy %q has no opened position", signature))
|
||||
return fmt.Errorf("strategy %T has no opened position", strategy)
|
||||
}
|
||||
|
||||
reply.Send("Your current position:")
|
||||
reply.Message(position.PlainText())
|
||||
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
|
@ -285,6 +283,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
}
|
||||
return nil
|
||||
}).Next(func(signature string, reply interact.Reply) error {
|
||||
defer func() {
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
}()
|
||||
|
||||
strategy, ok := it.exchangeStrategies[signature]
|
||||
if !ok {
|
||||
reply.Message("Strategy not found")
|
||||
|
@ -299,10 +303,6 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
|
||||
status := controller.GetStatus()
|
||||
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
|
||||
if status == types.StrategyStatusRunning {
|
||||
reply.Message(fmt.Sprintf("Strategy %s is running.", signature))
|
||||
} else if status == types.StrategyStatusStopped {
|
||||
|
@ -323,6 +323,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
}
|
||||
return nil
|
||||
}).Next(func(signature string, reply interact.Reply) error {
|
||||
defer func() {
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
}()
|
||||
|
||||
strategy, ok := it.exchangeStrategies[signature]
|
||||
if !ok {
|
||||
reply.Message("Strategy not found")
|
||||
|
@ -341,16 +347,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
return nil
|
||||
}
|
||||
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
|
||||
if err := controller.Suspend(); err != nil {
|
||||
reply.Message(fmt.Sprintf("Failed to suspend the strategy, %s", err.Error()))
|
||||
return err
|
||||
}
|
||||
|
||||
reply.Message(fmt.Sprintf("Strategy %s suspended.", signature))
|
||||
reply.Message(fmt.Sprintf("Strategy %s is now suspended.", signature))
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -365,6 +367,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
}
|
||||
return nil
|
||||
}).Next(func(signature string, reply interact.Reply) error {
|
||||
defer func() {
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
}()
|
||||
|
||||
strategy, ok := it.exchangeStrategies[signature]
|
||||
if !ok {
|
||||
reply.Message("Strategy not found")
|
||||
|
@ -383,16 +391,12 @@ func (it *CoreInteraction) Commands(i *interact.Interact) {
|
|||
return nil
|
||||
}
|
||||
|
||||
if kc, ok := reply.(interact.KeyboardController); ok {
|
||||
kc.RemoveKeyboard()
|
||||
}
|
||||
|
||||
if err := controller.Resume(); err != nil {
|
||||
reply.Message(fmt.Sprintf("Failed to resume the strategy, %s", err.Error()))
|
||||
return err
|
||||
}
|
||||
|
||||
reply.Message(fmt.Sprintf("Strategy %s resumed.", signature))
|
||||
reply.Message(fmt.Sprintf("Strategy %s is now resumed.", signature))
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
|
@ -157,7 +157,9 @@ func (tm *Telegram) Start(context.Context) {
|
|||
|
||||
if reply.set {
|
||||
reply.build()
|
||||
checkSendErr(tm.Bot.Send(m.Chat, reply.message, reply.menu))
|
||||
if len(reply.message) > 0 || reply.menu != nil {
|
||||
checkSendErr(tm.Bot.Send(m.Chat, reply.message, reply.menu))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user