update models

This commit is contained in:
Jay 2019-07-14 15:04:14 +08:00
parent c74b8f8e4d
commit fd3bd2679e
2 changed files with 81 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package discord
import (
"dorisbot/models"
pubmodel "dorisbot/models/public"
"errors"
"time"
)
@ -30,6 +31,35 @@ func NewChannel(id, server string, enableCMD, enableNotify bool) (ch *ChannelMod
return
}
// GetChannelByID -
func GetChannelByID(id string) (ch *ChannelModel, err error) {
if len(id) == 0 {
return nil, errors.New("id is empty")
}
ch = &ChannelModel{}
db := models.GetConn()
query := `select id, server, enable_cmd, enable_notify, ctime, mtime where id = $1`
err = db.Get(ch, query, id)
if err != nil {
return nil, err
}
return
}
// GetChannelListByServer -
func GetChannelListByServer(server string) (list []*ChannelModel, err error) {
if len(server) == 0 {
return nil, errors.New("server is empty")
}
db := models.GetConn()
query := `select id, server, enable_cmd, enable_notify, ctime, mtime where server = $1`
err = db.Select(&list, query, server)
if err != nil {
return nil, err
}
return
}
// Write -
func (p *ChannelModel) Write() (err error) {
db := models.GetConn()
@ -64,3 +94,25 @@ func (p *ChannelModel) SetCMDState(state bool) (err error) {
p.EnableCMD = state
return
}
// SetNotifyState -
func (p *ChannelModel) SetNotifyState(state bool) (err error) {
if state == p.EnableNotify {
return nil
}
db := models.GetConn()
query := `update "discord"."channel" set enable_notify = $1, mtime = now() where id = $2`
_, err = db.Exec(query, state, p.ID)
if err != nil {
return err
}
p.EnableNotify = state
return
}
// GetFacebookPageList -
func (p *ChannelModel) GetFacebookPageList() (pages *pubmodel.FacebookPageModel, err error) {
db := models.GetConn()
_ = db
return
}

View File

@ -1,6 +1,10 @@
package discord
import "time"
import (
"dorisbot/models"
"errors"
"time"
)
// ChannelFacebookRT -
type ChannelFacebookRT struct {
@ -39,6 +43,29 @@ type ChannelTwitchRT struct {
}
// CreateFacebookRT -
func CreateFacebookRT(channel, facebook string) (rt *ChannelFacebookRT, err error) {
func CreateFacebookRT(channel, facebook, tmpl string) (rt *ChannelFacebookRT, err error) {
if len(channel) == 0 || len(facebook) == 0 {
return nil, errors.New("channel or fbid is empty")
}
rt = &ChannelFacebookRT{
Channel: channel,
Facebook: facebook,
Tmpl: tmpl,
}
return
}
// GetFacebookRT -
func GetFacebookRT(channel, facebook string) (rt *ChannelFacebookRT, err error) {
if len(channel) == 0 || len(facebook) == 0 {
return nil, errors.New("channel or fbid is empty")
}
rt = &ChannelFacebookRT{}
db := models.GetConn()
query := `select channel, facebook, tmpl, ctime, mtime where channel = $1 and facebook = $2`
err = db.Get(rt, query, channel, facebook)
if err != nil {
return nil, err
}
return
}