40 lines
859 B
Go
40 lines
859 B
Go
package discord
|
|
|
|
import (
|
|
dsmodel "dorisbot/models/discord"
|
|
"log"
|
|
)
|
|
|
|
func addServer(info EvtInfo, name string) string {
|
|
exists, err := dsmodel.GetDiscordServerByID(info.Server)
|
|
if err != nil {
|
|
log.Println("check server exists fail :: ", err)
|
|
return "check server info fail"
|
|
}
|
|
if exists != nil {
|
|
return "server already setup"
|
|
}
|
|
|
|
ds, err := dsmodel.NewDiscordServer(info.Server, name, 0)
|
|
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"
|
|
}
|