del button from accepted
This commit is contained in:
@@ -27,11 +27,12 @@ type DuelController struct {
|
||||
FName string
|
||||
}
|
||||
|
||||
Summ int
|
||||
Inited bool
|
||||
MatchAccepted bool
|
||||
Bot *tele.Bot
|
||||
DC *DataController
|
||||
Summ int
|
||||
Inited bool
|
||||
MatchAccepted bool
|
||||
InitialMessage *tele.Message
|
||||
Bot *tele.Bot
|
||||
DC *DataController
|
||||
}
|
||||
|
||||
// Controller Init
|
||||
@@ -90,7 +91,13 @@ func (s *DuelController) StartMatch(c tele.Context) error {
|
||||
btnAccept := markup.Data("Принять", AcceptDuelButtonUnique)
|
||||
markup.Inline(markup.Row(btnAccept))
|
||||
|
||||
return c.Send(fmt.Sprintf("%s начал дуель, ставка: %d", s.PlayerOne.FName, summ), markup)
|
||||
msg, err := s.Bot.Send(c.Chat(), fmt.Sprintf("%s начал дуель, ставка: %d", s.PlayerOne.FName, summ), markup)
|
||||
if err != nil {
|
||||
s.resetDuelState()
|
||||
return err
|
||||
}
|
||||
s.InitialMessage = msg
|
||||
return nil
|
||||
}
|
||||
|
||||
// Accept Match
|
||||
@@ -124,9 +131,17 @@ func (s *DuelController) AcceptMatch(c tele.Context) error {
|
||||
s.MatchAccepted = true
|
||||
s.Summ *= 2
|
||||
|
||||
go s.gameProccess(c.Chat())
|
||||
if s.InitialMessage == nil {
|
||||
log.Println("Error: InitialMessage is nil in AcceptMatch")
|
||||
s.resetDuelState()
|
||||
return c.Send("Произошла ошибка, дуэль отменена. Попробуйте начать заново.")
|
||||
}
|
||||
|
||||
return c.Send(fmt.Sprintf("%s принимает участие в дуэли.", s.PlayerTwo.FName))
|
||||
// Edit the original message to remove the button and show the second player.
|
||||
s.Bot.Edit(s.InitialMessage, fmt.Sprintf("%s начал дуель, ставка: %d\n\n%s принимает участие в дуэли.", s.PlayerOne.FName, s.Summ/2, s.PlayerTwo.FName))
|
||||
|
||||
go s.gameProccess(s.InitialMessage)
|
||||
return c.Respond()
|
||||
}
|
||||
|
||||
// Clear match
|
||||
@@ -150,18 +165,19 @@ func (s *DuelController) resetDuelState() {
|
||||
s.Summ = 0
|
||||
s.Inited = false
|
||||
s.MatchAccepted = false
|
||||
s.InitialMessage = nil
|
||||
}
|
||||
|
||||
// Start Game
|
||||
func (s *DuelController) gameProccess(r tele.Recipient) {
|
||||
func (s *DuelController) gameProccess(msg *tele.Message) {
|
||||
time.Sleep(time.Second * 3)
|
||||
msg, err := s.Bot.Send(r, fmt.Sprintf("Дуэль началась!\nНа кону: %d", s.Summ))
|
||||
editedMsg, err := s.Bot.Edit(msg, fmt.Sprintf("Дуэль началась!\nНа кону: %d", s.Summ))
|
||||
if err != nil {
|
||||
log.Printf("Error sending duel start message: %v", err)
|
||||
s.resetDuelState() // Reset state if we can't even send the message
|
||||
return
|
||||
}
|
||||
s.RoundOne(msg)
|
||||
s.RoundOne(editedMsg)
|
||||
}
|
||||
|
||||
// Round One
|
||||
|
||||
Reference in New Issue
Block a user