package main import ( "github.com/line/line-bot-sdk-go/v7/linebot" "github.com/rs/zerolog/log" ) func Follow(event *linebot.Event) { // add user uid := event.Source.UserID usr := &User{ ID: uid, } Hit("加入", uid) row := DB.Exec("select id from users where id = ?", uid).RowsAffected if row == 0 { // 新用戶 if err := DB.Create(usr).Error; err != nil { log.Error().Err(err).Msg("Follow error.") return } log.Debug().Str("user", uid).Msg("New user.") msg := linebot.NewTextMessage("你好!") if _, err := SendMessage(event.ReplyToken, uid, msg); err != nil { panic(err) } } else { // 舊用戶 log.Debug().Str("user", uid).Msg("user unblocked.") msg := linebot.NewTextMessage("歡迎回來!") if _, err := SendMessage(event.ReplyToken, uid, msg); err != nil { panic(err) } } // Welcome and ask for }