fix query error
This commit is contained in:
parent
4acc78cd41
commit
703ffe34b2
@ -38,7 +38,7 @@ func GetChannelByID(id string) (ch *ChannelModel, err error) {
|
|||||||
}
|
}
|
||||||
ch = &ChannelModel{}
|
ch = &ChannelModel{}
|
||||||
db := models.GetConn()
|
db := models.GetConn()
|
||||||
query := `select id, server, enable_cmd, enable_notify, ctime, mtime where id = $1`
|
query := `select id, server, enable_cmd, enable_notify, ctime, mtime from "discord"."channel" where id = $1`
|
||||||
err = db.Get(ch, query, id)
|
err = db.Get(ch, query, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -52,7 +52,7 @@ func GetChannelListByServer(server string) (list []*ChannelModel, err error) {
|
|||||||
return nil, errors.New("server is empty")
|
return nil, errors.New("server is empty")
|
||||||
}
|
}
|
||||||
db := models.GetConn()
|
db := models.GetConn()
|
||||||
query := `select id, server, enable_cmd, enable_notify, ctime, mtime where server = $1`
|
query := `select id, server, enable_cmd, enable_notify, ctime, mtime from "discord"."channel" where server = $1`
|
||||||
err = db.Select(&list, query, server)
|
err = db.Select(&list, query, server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -61,12 +61,26 @@ func GetFacebookPageByChannelAndID(id, channel string) (page *FacebookPageModel,
|
|||||||
return nil, errors.New("channel or id is empty")
|
return nil, errors.New("channel or id is empty")
|
||||||
}
|
}
|
||||||
db := models.GetConn()
|
db := models.GetConn()
|
||||||
|
query := `
|
||||||
|
select
|
||||||
|
fb.id, fb.lastpost, fb.ctime, fb.mtime
|
||||||
|
from public.facebook_page fb
|
||||||
|
left join "discord"."channel_facebook_rt" rt
|
||||||
|
on rt.facebook = fb.id
|
||||||
|
where fb.id = $1 and rt.channel = $2`
|
||||||
|
result, err := db.Queryx(query, id, channel)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if result.Next() {
|
||||||
page = &FacebookPageModel{}
|
page = &FacebookPageModel{}
|
||||||
query := `select id, lastpost, ctime, mtime from public.facebook_page where id = $1 and channel = $2`
|
err = result.StructScan(page)
|
||||||
err = db.Get(page, query, channel)
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,10 +39,34 @@ func addServer(info EvtInfo, name string) string {
|
|||||||
return "add server success"
|
return "add server success"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addChannel(info EvtInfo, cmd, notify string) string {
|
||||||
|
server, err := dsmodel.GetServerByID(info.Server)
|
||||||
|
if err != nil {
|
||||||
|
return "Get server data fail"
|
||||||
|
}
|
||||||
|
_ = server
|
||||||
|
|
||||||
|
if server == nil {
|
||||||
|
return "Server not init"
|
||||||
|
}
|
||||||
|
|
||||||
|
ch, err := dsmodel.NewChannel(info.Channel, info.Server, cmd == "1", notify == "1")
|
||||||
|
if err != nil {
|
||||||
|
return "init channel data fail"
|
||||||
|
}
|
||||||
|
err = ch.Write()
|
||||||
|
if err != nil {
|
||||||
|
return "write channel data fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Success"
|
||||||
|
}
|
||||||
|
|
||||||
func addFacebookPage(info EvtInfo, fbid, tmpl string) string {
|
func addFacebookPage(info EvtInfo, fbid, tmpl string) string {
|
||||||
log.Printf("add facebook ::: id : %s ::: tmpl : %s \n", fbid, tmpl)
|
log.Printf("add facebook ::: id : %s ::: tmpl : %s \n", fbid, tmpl)
|
||||||
ch, err := dsmodel.GetChannelByID(info.Channel)
|
ch, err := dsmodel.GetChannelByID(info.Channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("get channel fail", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,14 +88,17 @@ func addFacebookPage(info EvtInfo, fbid, tmpl string) string {
|
|||||||
} else {
|
} else {
|
||||||
fbrt, err := ch.GetFacebookPageByID(fbid)
|
fbrt, err := ch.GetFacebookPageByID(fbid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("get fb rt fail :: ", err)
|
||||||
return "check data fail"
|
return "check data fail"
|
||||||
}
|
}
|
||||||
|
|
||||||
if fbrt != nil {
|
if fbrt != nil {
|
||||||
return "facebook page already linked"
|
return "facebook page already linked"
|
||||||
}
|
}
|
||||||
|
|
||||||
rt, err := dsmodel.CreateFacebookRT(info.Channel, page.ID, tmpl)
|
rt, err := dsmodel.CreateFacebookRT(info.Channel, page.ID, tmpl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("create fail :: ", err)
|
||||||
return "create data fail"
|
return "create data fail"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,8 +153,17 @@ func selectAction(info EvtInfo, cmdKey, cmdValue, payload string) string {
|
|||||||
switch cmdKey {
|
switch cmdKey {
|
||||||
case "ds_addserver":
|
case "ds_addserver":
|
||||||
return addServer(info, payload)
|
return addServer(info, payload)
|
||||||
|
case "ds_addchannel":
|
||||||
|
strs := strings.Split(payload, " ")
|
||||||
|
if len(strs) != 2 {
|
||||||
|
return "!ds_addchennel {enable_cmd} {enable_notify}"
|
||||||
|
}
|
||||||
|
return addChannel(info, strs[0], strs[1])
|
||||||
case "ds_addfacebook":
|
case "ds_addfacebook":
|
||||||
strs := strings.Split(payload, " ")
|
strs := strings.Split(payload, " ")
|
||||||
|
if len(strs) < 2 {
|
||||||
|
return "!ds_addfacebook {facebook_id} {template}"
|
||||||
|
}
|
||||||
return addFacebookPage(info, strs[0], strings.Join(strs[1:], " "))
|
return addFacebookPage(info, strs[0], strings.Join(strs[1:], " "))
|
||||||
case "ds_delfacebook":
|
case "ds_delfacebook":
|
||||||
return delFacebookPage(info, payload)
|
return delFacebookPage(info, payload)
|
||||||
|
Loading…
Reference in New Issue
Block a user