talent/api_join.go

41 lines
860 B
Go
Raw Normal View History

2022-01-02 16:47:25 +00:00
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("你好!")
2022-01-03 05:06:26 +00:00
if _, err := SendMessage(event.ReplyToken, uid, msg); err != nil {
panic(err)
2022-01-02 16:47:25 +00:00
}
} else {
// 舊用戶
log.Debug().Str("user", uid).Msg("user unblocked.")
msg := linebot.NewTextMessage("歡迎回來!")
2022-01-03 05:06:26 +00:00
if _, err := SendMessage(event.ReplyToken, uid, msg); err != nil {
panic(err)
2022-01-02 16:47:25 +00:00
}
}
// Welcome and ask for
}