Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
twbworld committed Jan 12, 2024
1 parent a1aa828 commit 7fbe089
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 0 additions & 3 deletions dao/dbHandle.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ func UpdateUsersExpiry(ids []uint, tx *sqlx.Tx) (err error) {
func InsertEmptyUsers(tx *sqlx.Tx, userName string) (err error) {
sql := "INSERT INTO `users`(`username`, `password`, `passwordShow`, `quota`, `download`, `upload`, `useDays`, `expiryDate`) VALUES(:username, :password, :passwordShow, :quota, :download, :upload, :useDays, :expiryDate)"

if err != nil {
return err
}
t := time.Now().AddDate(0, 1, 0)

_, err = tx.NamedExec(sql, map[string]interface{}{
Expand Down
14 changes: 14 additions & 0 deletions service/tg.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func TgWebhookHandle(ctx *gin.Context) error {
// fmt.Println(string(st))

if update.Message != nil {
global.Log.Info("进入3")
// (对话第一步) 和 (对话第五步)
return firstStep(&update)
} else if update.CallbackQuery != nil {
global.Log.Info("进入2")
if update.CallbackQuery.Data == "" {
return errors.New("参数错误[gdoigjiod]")
}
Expand Down Expand Up @@ -94,6 +96,7 @@ func firstStep(update *tg.Update) error {
errSys := dao.GetSysValByKey(&info, strconv.FormatInt(update.Message.Chat.ID, 10)+"_step")

if update.Message.IsCommand() {
global.Log.Info("进入4")
switch update.Message.Command() {
case "start", "help":
msg.Text = "\nHello " + update.Message.From.FirstName + update.Message.From.LastName
Expand Down Expand Up @@ -136,6 +139,7 @@ func firstStep(update *tg.Update) error {
msg.ReplyToMessageID = update.Message.MessageID //引用对话
}
} else {
global.Log.Info("进入5")
msg.ReplyToMessageID = update.Message.MessageID //引用对话
if errSys != nil {
goto SEND
Expand All @@ -145,6 +149,8 @@ func firstStep(update *tg.Update) error {
return nil
}

global.Log.Info("进入1", info.Value, update.Message.Text)

if info.Value == "user_insert" {
return userInsert(update, &info)
}
Expand Down Expand Up @@ -390,6 +396,7 @@ func userInsert(update *tg.Update, info *model.SystemInfo) (err error) {
if err != nil {
return errors.New("开启事务失败[glyasd]: " + err.Error())
}
global.Log.Info("进入6")
defer func() {
if p := recover(); p != nil {
tx.Rollback()
Expand All @@ -409,6 +416,8 @@ func userInsert(update *tg.Update, info *model.SystemInfo) (err error) {
goto SEND2
}

global.Log.Info("进入7")

err = dao.GetUsersByUserName(&user, update.Message.Text)
if err == nil {
msg.Text = strings.Replace(fmt.Sprintf("*用户`%s`已存在\\!\\!\\!*\n", update.Message.Text), `-`, `\-`, -1) + getUserMarkdownV2Text(&user)
Expand All @@ -417,6 +426,8 @@ func userInsert(update *tg.Update, info *model.SystemInfo) (err error) {
goto SEND2
}

global.Log.Info("进入8")

err = dao.InsertEmptyUsers(tx, update.Message.Text)
if err != nil {
msg.Text = `系统错误, 请按"/start"重新设置4`
Expand All @@ -431,6 +442,8 @@ func userInsert(update *tg.Update, info *model.SystemInfo) (err error) {
goto SEND2
}

global.Log.Info("进入9")

msg.Text = "*新增成功\\!\\!\\!*\n" + getUserMarkdownV2Text(&user)
msg.ParseMode = "MarkdownV2"
msg.ReplyMarkup = tg.NewInlineKeyboardMarkup(
Expand All @@ -440,6 +453,7 @@ func userInsert(update *tg.Update, info *model.SystemInfo) (err error) {
)

SEND2:
global.Log.Info("进入10")
_, err = global.Bot.Send(msg)
return
}
Expand Down

0 comments on commit 7fbe089

Please sign in to comment.