game_timer.go 918 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package tg
  2. import (
  3. "time"
  4. tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
  5. "github.com/sirupsen/logrus"
  6. "github.com/spf13/viper"
  7. )
  8. func StartGameTimer() {
  9. waitSecond := viper.GetInt("wait_second")
  10. for {
  11. logrus.Info("run...")
  12. sendGameInfo()
  13. <-time.After(time.Duration(waitSecond) * time.Second)
  14. }
  15. }
  16. func sendGameInfo() {
  17. chatID := viper.GetInt64("chat_id")
  18. gifMsg := tgbotapi.GameConfig{
  19. BaseChat: tgbotapi.BaseChat{
  20. ChatID: chatID,
  21. ReplyMarkup: GetGameReplyMarkup(),
  22. },
  23. GameShortName: "qznn",
  24. }
  25. event2.MustFire(EventSendMsg, event2.M{
  26. "msg": gifMsg,
  27. })
  28. }
  29. func GetGameReplyMarkup() tgbotapi.InlineKeyboardMarkup {
  30. gameBtn := tgbotapi.NewInlineKeyboardButtonData("🎮进入游戏", "")
  31. gameBtn.CallbackGame = &tgbotapi.CallbackGame{}
  32. gameBtn.CallbackData = nil
  33. return tgbotapi.NewInlineKeyboardMarkup(
  34. tgbotapi.NewInlineKeyboardRow(
  35. gameBtn,
  36. ),
  37. )
  38. }