Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
twbworld committed Jan 13, 2024
1 parent 4b22a84 commit 757e6c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion controller/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Tg(ctx *gin.Context) {
defer func() {
if p := recover(); p != nil || err != nil {
if p != nil {
global.Log.Errorln(p)
global.Log.Errorf("这里: %v", p)
} else {
global.Log.Errorln(err)
}
Expand Down
2 changes: 1 addition & 1 deletion initialize/tg.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TgInit() {
}

if info.LastErrorDate != 0 {
global.Log.Errorln("Telegram callback failed[fosdjfoisj]: ", info.LastErrorMessage)
global.Log.Errorln("获取tg信息错误[fosdjfoisj]: ", info.LastErrorMessage)
return
}
global.Log.Printf("成功配置tg[doiasjo]: %s", global.Bot.Self.UserName)
Expand Down
33 changes: 22 additions & 11 deletions service/tg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ type tgConfig struct {
update *tg.Update
}

func Webhook(ctx *gin.Context) (err error) {
c := &tgConfig{
update: &tg.Update{},
}
if err = json.NewDecoder(ctx.Request.Body).Decode(c.update); err != nil {
return
}

return c.handle()
}

func TgSend(text string) (err error) {
if global.Bot == nil || text == "" || IsTgSend {
return
Expand All @@ -45,6 +34,17 @@ func TgSend(text string) (err error) {
return
}

func Webhook(ctx *gin.Context) (err error) {
c := &tgConfig{
update: &tg.Update{},
}
if err = json.NewDecoder(ctx.Request.Body).Decode(c.update); err != nil {
return
}

return c.handle()
}

func (c tgConfig) handle() error {

// st, _ := json.Marshal(update)
Expand Down Expand Up @@ -93,8 +93,11 @@ func (c tgConfig) firstStep() error {
),
)

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

var info model.SystemInfo
errSys := dao.GetSysValByKey(&info, strconv.FormatInt(c.update.Message.Chat.ID, 10)+"_step")
global.Log.Info("进入2")

if c.update.Message.IsCommand() {
switch c.update.Message.Command() {
Expand Down Expand Up @@ -156,7 +159,12 @@ func (c tgConfig) firstStep() error {
return c.userInsert(&info)
}

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

// user_update@10@expiryDate

params := regexp.MustCompile(`(.+)@(\d+)@(.+)`).FindStringSubmatch(info.Value)
global.Log.Info("进入4", params)
if len(params) < 4 {
return errors.New("参数错误[fijsa]")
}
Expand Down Expand Up @@ -235,6 +243,9 @@ func (c tgConfig) firstStep() error {
}
SEND:
_, err := global.Bot.Send(msg)
if err != nil {
err = errors.New("[sidojfoijsakl]" + err.Error())
}
return err
}

Expand Down

0 comments on commit 757e6c7

Please sign in to comment.