update code

This commit is contained in:
Jay 2019-07-21 09:41:06 +08:00
parent fd3bd2679e
commit 4f0b650ac2
5 changed files with 40 additions and 8 deletions

View File

@ -111,8 +111,11 @@ func (p *ChannelModel) SetNotifyState(state bool) (err error) {
}
// GetFacebookPageList -
func (p *ChannelModel) GetFacebookPageList() (pages *pubmodel.FacebookPageModel, err error) {
db := models.GetConn()
_ = db
return
func (p *ChannelModel) GetFacebookPageList() (pages []*pubmodel.FacebookPageModel, err error) {
return pubmodel.GetFacebookPageListByChannel(p.ID)
}
// GetFacebookPageByID -
func (p *ChannelModel) GetFacebookPageByID(id string) (page *pubmodel.FacebookPageModel, err error) {
return pubmodel.GetFacebookPageByChannelAndID(id, p.ID)
}

View File

@ -41,6 +41,35 @@ func GetFacebookPageByID(id string) (page *FacebookPageModel, err error) {
return
}
// GetFacebookPageListByChannel -
func GetFacebookPageListByChannel(channel string) (pages []*FacebookPageModel, err error) {
if len(channel) == 0 {
return nil, errors.New("channel is empty")
}
db := models.GetConn()
query := `select id, lastpost, ctime, mtime from public.facebook_page where channel = $1`
err = db.Select(&pages, query, channel)
if err != nil {
return nil, err
}
return
}
// GetFacebookPageByChannelAndID -
func GetFacebookPageByChannelAndID(id, channel string) (page *FacebookPageModel, err error) {
if len(channel) == 0 || len(id) == 0 {
return nil, errors.New("channel or id is empty")
}
db := models.GetConn()
page = &FacebookPageModel{}
query := `select id, lastpost, ctime, mtime from public.facebook_page where id = $1 and channel = $2`
err = db.Get(page, query, channel)
if err != nil {
return nil, err
}
return
}
// GetAllFacebookPage -
func GetAllFacebookPage() (pages []*FacebookPageModel, err error) {
db := models.GetConn()

View File

@ -6,7 +6,7 @@ import (
)
func addServer(info EvtInfo, name string) string {
exists, err := dsmodel.GetDiscordServerByID(info.Server)
exists, err := dsmodel.GetServerByID(info.Server)
if err != nil {
log.Println("check server exists fail :: ", err)
return "check server info fail"
@ -15,7 +15,7 @@ func addServer(info EvtInfo, name string) string {
return "server already setup"
}
ds, err := dsmodel.NewDiscordServer(info.Server, name, 0)
ds, err := dsmodel.NewServer(info.Server, name, 0)
if err != nil {
log.Println("create dsmodel fail :: ", err)
return "create server data fail"

View File

@ -32,7 +32,7 @@ func messageCreateEvt(s *discordgo.Session, evt *discordgo.MessageCreate) {
_ = channelID
_ = uid
server, err := dsmodel.GetDiscordServerByID(guildID)
server, err := dsmodel.GetServerByID(guildID)
if err != nil {
log.Println("get server err :: ", err)
return

View File

@ -49,7 +49,7 @@ func getCMD(str string) (cmd string, keyword bool) {
return
}
func getRegServerCommandAction(s *discordgo.Session, msgEvt *discordgo.MessageCreate, server *dsmodel.DiscordServerModel, cmd string) (c *pubmodel.CommandModel, acts []*cmdparser.CmdAction, err error) {
func getRegServerCommandAction(s *discordgo.Session, msgEvt *discordgo.MessageCreate, server *dsmodel.ServerModel, cmd string) (c *pubmodel.CommandModel, acts []*cmdparser.CmdAction, err error) {
cmds, err := pubmodel.GetCommandByPlatformBinding(cmd, server.ID, "discord")
if err != nil {
log.Println("get command err :: ", err)