Browse Source

fix wuhua

Your Name 1 year ago
parent
commit
f109800c33
7 changed files with 141 additions and 39 deletions
  1. BIN
      dist/tg/dist/tg
  2. 1 1
      dist/tg/version.txt
  3. 1 1
      game/qznn/nn.go
  4. 3 2
      tg/const_data.go
  5. 30 0
      tg/game.go
  6. 78 23
      tg/game_timer.go
  7. 28 12
      tg/tg.go

BIN
dist/tg/dist/tg


+ 1 - 1
dist/tg/version.txt

@@ -1 +1 @@
-1.0.2211.bf395
+1.0.2211.007d2

+ 1 - 1
game/qznn/nn.go

@@ -21,7 +21,7 @@ func WinLevel(leftNum, rightNum []uint32) (bool, bool, int) {
 	logrus.Infof("%v:%d", rightNum, pointRight)
 
 	if isWuhuaLeft && !isWuhuaRight {
-		return true, false, 3
+		return true, false, 4
 	}
 
 	if !isWuhuaLeft && isWuhuaRight {

+ 3 - 2
tg/const_data.go

@@ -1,6 +1,7 @@
 package tg
 
 const (
-	EventUpdateMsg string = "event_update_msg"
-	EventSendMsg   string = "event_send_msg"
+	EventUpdateMsg  string = "event_update_msg"
+	EventSendMsg    string = "event_send_msg"
+	EventSendMsgFix string = "event_send_msg_fix"
 )

+ 30 - 0
tg/game.go

@@ -7,6 +7,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"net/http"
+	"runtime/debug"
 	"strings"
 	"time"
 
@@ -99,6 +100,22 @@ func onUpdate(e event2.Event[tgbotapi.Update]) error {
 func handlerMsg(update tgbotapi.Update) error {
 	var err error
 
+	defer func() {
+		if p := recover(); p != nil {
+			logrus.Error("panic recover! p:", p)
+			str, ok := p.(string)
+			if ok {
+				err = errors.New(str)
+			} else {
+				err = errors.New("panic")
+			}
+			logrus.Error(string(debug.Stack()))
+			debug.PrintStack()
+
+			logrus.Error(err)
+		}
+	}()
+
 	cmdMsg := update.Message.Text
 	tgID := update.Message.From.ID
 	tgUsername := update.Message.From.UserName
@@ -199,6 +216,19 @@ func handlerMsg(update tgbotapi.Update) error {
 		return nil
 	}
 
+	if cmdMsg == "gamesimple" {
+		gifMsg := &tgbotapi.GameConfig{
+			BaseChat: tgbotapi.BaseChat{
+				ChatID:      update.Message.Chat.ID,
+				ReplyMarkup: GetGameReplyMarkupSimple(),
+			},
+			GameShortName: "qznn",
+		}
+
+		go event2.MustFire(EventSendMsgFix, tgbotapi.Chattable(gifMsg))
+		return nil
+	}
+
 	if cmdMsg == "phb" || cmdMsg == "排行榜" || cmdMsg == "/phb@fllqznnbot" {
 		gameUserMapModel := model.GameUserMap{}
 		err = db.GetDB().Table("game_user_map").

+ 78 - 23
tg/game_timer.go

@@ -9,14 +9,25 @@ import (
 	"gogs.daxia.dev/huanan/pkg.daxia.dev/event2"
 )
 
+var deleteMsgList = make([]tgbotapi.DeleteMessageConfig, 0)
+
 func StartGameTimer() {
 	waitSecond := viper.GetInt("wait_second")
-	for {
-		logrus.Info("run...")
-		sendGameInfo()
-		sendGameInfo2()
-		<-time.After(time.Duration(waitSecond) * time.Second)
-	}
+	go func() {
+		for {
+			logrus.Info("run...")
+			sendGameInfo()
+			<-time.After(time.Duration(waitSecond) * time.Second)
+		}
+	}()
+
+	go func() {
+		for {
+			logrus.Info("run...")
+			sendGameInfo2()
+			<-time.After(60 * time.Second)
+		}
+	}()
 }
 
 func sendGameInfo() {
@@ -46,35 +57,79 @@ func sendGameInfo() {
 }
 
 func sendGameInfo2() {
+	chatID2 := int64(-1001632614756)
+
+	if len(deleteMsgList) == 2 {
+		MainBot.botApi.Send(deleteMsgList[0])
+
+		<-time.After(1 * time.Second)
+
+		MainBot.botApi.Send(deleteMsgList[1])
+	}
+
+	deleteMsgList = make([]tgbotapi.DeleteMessageConfig, 0)
+
 	caption := `东方汇看牌抢庄牛牛积分房,每天最高免费赠送2000U,详情请看牛牛群置顶规则。下载APP,大于100流水赠送5U。分享下级,下级注册赠送1U,上级推广奖励0.5U
  
 
 <a href='https://t.me/FLLDFH'>每天500流水免费领取60U</a>
 `
-	chatID2 := int64(-1001632614756)
 
-	textMsg := tgbotapi.MessageConfig{
-		BaseChat: tgbotapi.BaseChat{
-			ChatID: chatID2,
-		},
-		Text:                  caption,
-		ParseMode:             "HTML",
-		DisableWebPagePreview: true,
+	{
+		textMsg := tgbotapi.MessageConfig{
+			BaseChat: tgbotapi.BaseChat{
+				ChatID: chatID2,
+			},
+			Text:                  caption,
+			ParseMode:             "HTML",
+			DisableWebPagePreview: true,
+		}
+
+		resp, err := MainBot.botApi.Send(textMsg)
+		if err != nil {
+			logrus.Error(err)
+			return
+		}
+
+		deleteMsgList = append(deleteMsgList, tgbotapi.DeleteMessageConfig{
+			ChatID:    resp.Chat.ID,
+			MessageID: resp.MessageID,
+		})
 	}
 
-	event2.MustFire(EventSendMsg, tgbotapi.Chattable(textMsg))
-
 	<-time.After(2 * time.Second)
 
-	gifMsg := &tgbotapi.GameConfig{
-		BaseChat: tgbotapi.BaseChat{
-			ChatID:      chatID2,
-			ReplyMarkup: GetGameReplyMarkup2(),
-		},
-		GameShortName: "qznn",
+	{
+		gifMsg := &tgbotapi.GameConfig{
+			BaseChat: tgbotapi.BaseChat{
+				ChatID:      chatID2,
+				ReplyMarkup: GetGameReplyMarkup2(),
+			},
+			GameShortName: "qznn",
+		}
+
+		resp, err := MainBot.botApi.Send(gifMsg)
+		if err != nil {
+			logrus.Error(err)
+			return
+		}
+		deleteMsgList = append(deleteMsgList, tgbotapi.DeleteMessageConfig{
+			ChatID:    resp.Chat.ID,
+			MessageID: resp.MessageID,
+		})
 	}
+}
 
-	event2.MustFire(EventSendMsg, tgbotapi.Chattable(gifMsg))
+func GetGameReplyMarkupSimple() tgbotapi.InlineKeyboardMarkup {
+	gameBtn := tgbotapi.NewInlineKeyboardButtonData("🎮进入游戏", "")
+	gameBtn.CallbackGame = &tgbotapi.CallbackGame{}
+	gameBtn.CallbackData = nil
+
+	return tgbotapi.NewInlineKeyboardMarkup(
+		tgbotapi.NewInlineKeyboardRow(
+			gameBtn,
+		),
+	)
 }
 
 func GetGameReplyMarkup() tgbotapi.InlineKeyboardMarkup {

+ 28 - 12
tg/tg.go

@@ -1,6 +1,7 @@
 package tg
 
 import (
+	"encoding/json"
 	"time"
 
 	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
@@ -9,10 +10,14 @@ import (
 	"gogs.daxia.dev/huanan/pkg.daxia.dev/event2"
 )
 
+var MainBot *Bot
+
 func Start() {
-	MainBot := NewBot()
+	MainBot = NewBot()
 
 	event2.On[tgbotapi.Chattable](EventSendMsg, event2.ListenerFunc[tgbotapi.Chattable](MainBot.onSendMsg))
+	event2.On[tgbotapi.Chattable](EventSendMsgFix, event2.ListenerFunc[tgbotapi.Chattable](MainBot.onSendMsgFix))
+	event2.On[tgbotapi.Chattable](EventSendMsgFix, event2.ListenerFunc[tgbotapi.Chattable](MainBot.onSendMsgFix))
 
 	go func() {
 		<-time.After(3 * time.Second)
@@ -35,6 +40,14 @@ func NewBot() *Bot {
 }
 
 func (p *Bot) onSendMsg(e event2.Event[tgbotapi.Chattable]) error {
+	return p.onSendMsgInner(e, true)
+}
+
+func (p *Bot) onSendMsgFix(e event2.Event[tgbotapi.Chattable]) error {
+	return p.onSendMsgInner(e, false)
+}
+
+func (p *Bot) onSendMsgInner(e event2.Event[tgbotapi.Chattable], delete bool) error {
 	logrus.Info("onSendMsg:", e)
 	c := e.Data()
 
@@ -46,18 +59,20 @@ func (p *Bot) onSendMsg(e event2.Event[tgbotapi.Chattable]) error {
 
 	logrus.Info("send finish:", resp)
 
-	chatID2 := int64(-1001632614756)
-	if resp.Chat.ID == chatID2 {
-		go func() {
-			<-time.After(time.Duration(30) * time.Second)
+	if delete {
+		chatID2 := int64(-1001632614756)
+		if resp.Chat.ID == chatID2 {
+			go func() {
+				<-time.After(time.Duration(30) * time.Second)
 
-			deleteMsg := tgbotapi.DeleteMessageConfig{
-				ChatID:    resp.Chat.ID,
-				MessageID: resp.MessageID,
-			}
+				deleteMsg := tgbotapi.DeleteMessageConfig{
+					ChatID:    resp.Chat.ID,
+					MessageID: resp.MessageID,
+				}
 
-			p.botApi.Send(deleteMsg)
-		}()
+				p.botApi.Send(deleteMsg)
+			}()
+		}
 	}
 
 	return nil
@@ -151,7 +166,8 @@ func (p *Bot) ProcNewMessage() {
 	}
 
 	for update := range p.updateChannel {
-		logrus.Info("recv update msg:", update)
+		updateJson, _ := json.Marshal(update)
+		logrus.Info("recv update msg:", string(updateJson))
 		go event2.MustFire(EventUpdateMsg, update)
 	}
 }