Commit 7bed51d2 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

update premium check

parent 6978ce5a
......@@ -23,9 +23,6 @@ func New(_c *config.Config) (dao *Dao, err error) {
c: _c,
}
// dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True",
// _c.MySQL.User, _c.MySQL.Password, _c.MySQL.Host, _c.MySQL.Port, _c.MySQL.Database)
// dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=verify-ca sslrootcert=ca.crt",
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d",
_c.PGSQL.Host, _c.PGSQL.User, _c.PGSQL.Password, _c.PGSQL.Database, _c.PGSQL.Port,
......
......@@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/gin-contrib/cors v1.7.2
github.com/gin-gonic/gin v1.10.0
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.2-0.20221020003057-99503a71186f
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/sirupsen/logrus v1.9.0
github.com/tidwall/gjson v1.17.1
......
......@@ -28,8 +28,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8=
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 h1:wG8n/XJQ07TmjbITcGiUaOtXxdrINDz1b0J1w0SzqDc=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.2-0.20221020003057-99503a71186f h1:s4aF4gKdCrJGRBWW8mUHIzjQ3PClFfZYA7gfH++aJ+E=
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.2-0.20221020003057-99503a71186f/go.mod h1:A2S0CWkNylc2phvKXWBBdD3K0iGnDBGbzRpISP2zBl8=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
......
......@@ -57,7 +57,7 @@ func (m *Messenger) Start() {
}
}
func (m *Messenger) ExistGroupChat(userId, chatId int64) (exist bool, err error) {
func (m *Messenger) ExistGroupChat(userId, chatId int64) (exist, premium bool, err error) {
mem, err := m.bot.GetChatMember(tgbotapi.GetChatMemberConfig{
ChatConfigWithUser: tgbotapi.ChatConfigWithUser{
ChatID: chatId,
......@@ -71,9 +71,9 @@ func (m *Messenger) ExistGroupChat(userId, chatId int64) (exist bool, err error)
switch {
case mem.HasLeft(), mem.WasKicked():
return false, nil
return false, false, nil
default:
return true, nil
return true, mem.User.IsPremium, nil
}
}
......
......@@ -19,12 +19,12 @@ func isJoined(c *gin.Context) {
return
}
joined, err := srv.IsJoined(userId, chatId)
joined, premium, err := srv.IsJoined(userId, chatId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
}
c.JSON(200, withSuccess(gin.H{"joined": joined}))
c.JSON(200, withSuccess(gin.H{"joined": joined, "isPremium": premium}))
return
}
......
......@@ -6,8 +6,8 @@ import (
log "github.com/sirupsen/logrus"
)
func (s *Service) IsJoined(userId, chatId int) (joined bool, err error) {
joined, err = s.msger.ExistGroupChat(int64(userId), int64(chatId))
func (s *Service) IsJoined(userId, chatId int) (joined, premium bool, err error) {
joined, premium, err = s.msger.ExistGroupChat(int64(userId), int64(chatId))
if err != nil {
log.WithError(err).Error("exist group chat error")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment