dorisbot/pkg/svc/discord/actions.go

75 lines
1.5 KiB
Go
Raw Normal View History

2019-07-04 09:00:16 +00:00
package discord
2019-07-09 15:05:36 +00:00
import (
dsmodel "dorisbot/models/discord"
2019-07-22 12:54:25 +00:00
pubmodel "dorisbot/models/public"
2019-07-09 15:05:36 +00:00
"log"
)
func addServer(info EvtInfo, name string) string {
2019-07-21 01:41:06 +00:00
exists, err := dsmodel.GetServerByID(info.Server)
2019-07-09 15:05:36 +00:00
if err != nil {
log.Println("check server exists fail :: ", err)
return "check server info fail"
}
if exists != nil {
return "server already setup"
}
2019-07-21 01:41:06 +00:00
ds, err := dsmodel.NewServer(info.Server, name, 0)
2019-07-09 15:05:36 +00:00
if err != nil {
log.Println("create dsmodel fail :: ", err)
return "create server data fail"
}
log.Println("show info :: ", info)
owner, err := client.GetGuildOwner(info.Server)
if err != nil {
log.Println("get server owner err :: ", err)
return "get server owner fail"
}
ds.Owner = owner
err = ds.Write()
if err != nil {
log.Println("write server data fail :: ", err)
return "write server data fail"
}
return "add server success"
2019-07-04 09:00:16 +00:00
}
2019-07-13 09:44:31 +00:00
func addFacebookPage(info EvtInfo, fbid, tmpl string) string {
2019-07-22 12:54:25 +00:00
ch, err := dsmodel.GetChannelByID(info.Channel)
if err != nil {
return ""
}
var page *pubmodel.FacebookPageModel
2019-07-13 09:44:31 +00:00
2019-07-22 12:54:25 +00:00
page, err = pubmodel.GetFacebookPageByID(fbid)
if err != nil {
return "check facebook fail"
}
if page == nil {
// TODO: write facebook page
page, err = pubmodel.NewFacebookPage(fbid)
if err != nil {
return "write data fail"
}
err = page.Write()
if err != nil {
return "write data fail"
}
} else {
fbrt, err := ch.GetFacebookPageByID(fbid)
if err != nil {
return "check data fail"
}
if fbrt != nil {
return "facebook page already linked"
}
}
2019-07-13 09:44:31 +00:00
return ""
}