game.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package tg
  2. import (
  3. "fmt"
  4. "sync/atomic"
  5. tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
  6. "github.com/sirupsen/logrus"
  7. )
  8. var index = int32(30)
  9. var idMap = map[int64]int32{}
  10. func GameStart() {
  11. event2.On(EventUpdateMsg, event2.ListenerFunc(onUpdate))
  12. }
  13. func onUpdate(e event2.Event) error {
  14. var err error
  15. update := e.Get("update").(tgbotapi.Update)
  16. // if update.Message != nil {
  17. // if update.Message.Text == "yx" {
  18. // sendGameInfo()
  19. // }
  20. // return nil
  21. // }
  22. if update.CallbackQuery == nil {
  23. logrus.Info("CallbackQuery is null")
  24. return nil
  25. }
  26. //shortName := viper.GetString("short_name")
  27. currIndex := int32(0)
  28. indexVal, exists := idMap[update.CallbackQuery.From.ID]
  29. if !exists {
  30. index = atomic.AddInt32(&index, 1)
  31. currIndex = index
  32. } else {
  33. currIndex = indexVal
  34. }
  35. idMap[update.CallbackQuery.From.ID] = currIndex
  36. logrus.Info("shortname: ", update.CallbackQuery.GameShortName)
  37. if update.CallbackQuery.GameShortName == "qznn" {
  38. gameConfig := tgbotapi.CallbackConfig{
  39. CallbackQueryID: update.CallbackQuery.ID,
  40. URL: fmt.Sprintf("https://211.99.98.167:3306/web-desktopQZNN/index.html?tk=8bc766ae05120ad091e8e52c29e23c%d&app=1", currIndex),
  41. CacheTime: 0,
  42. }
  43. logrus.Info("gameconfig:", gameConfig)
  44. go event2.MustFire(EventSendMsg, event2.M{
  45. "msg": gameConfig,
  46. })
  47. return nil
  48. }
  49. logrus.Error("not found game")
  50. return err
  51. }