This commit is contained in:
Jay
2018-09-13 18:18:59 +08:00
parent 7823fb86ab
commit a83ff3a0df
10 changed files with 290 additions and 9 deletions
+38 -1
View File
@@ -1,6 +1,10 @@
package model
import "time"
import (
"database/sql"
"errors"
"time"
)
// Commands - struct
type Commands struct {
@@ -10,3 +14,36 @@ type Commands struct {
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
}
// GetAllCommands -
func GetAllCommands() (cmds []*Commands, err error) {
err = x.Select(&cmds, `select * from "public"."commands"`)
return
}
// GetGroupCommand -
func GetGroupCommand(c, g string) (cmd *Commands, err error) {
if len(c) == 0 {
return nil, errors.New("command is empty")
}
tmpCmd := struct {
Commands
Message2 sql.NullString `db:"message2"`
}{}
query := `select c.*, c2.message as message2 from "public"."commands" c
left join "public"."commands" c2
on c2.cmd = c.cmd and c2."group" = $2
where c."cmd" = $1
and c."group" = ''`
err = x.Get(&tmpCmd, query, c, g)
if err != nil {
return nil, err
}
cmd = &tmpCmd.Commands
if tmpCmd.Message2.Valid {
cmd.Message = tmpCmd.Message2.String
}
return
}
+32 -1
View File
@@ -1,6 +1,10 @@
package model
import "time"
import (
"database/sql"
"errors"
"time"
)
// KeyCommands - struct
type KeyCommands struct {
@@ -10,3 +14,30 @@ type KeyCommands struct {
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
}
// GetKeyCommand -
func GetKeyCommand(c, g string) (cmd *KeyCommands, err error) {
if len(c) == 0 {
return nil, errors.New("command is empty")
}
tmpCmd := struct {
KeyCommands
Message2 sql.NullString `db:"message2"`
}{}
query := `select c.*, c2.message as message2 from "public"."key_commands" c
left join "public"."key_commands" c2
on c2.key = c.key and c2."group" = $2
where c."key" = $1
and c."group" = ''`
err = x.Get(&tmpCmd, query, c, g)
if err != nil {
return nil, err
}
cmd = &tmpCmd.KeyCommands
if tmpCmd.Message2.Valid {
cmd.Message = tmpCmd.Message2.String
}
return
}
+13
View File
@@ -11,3 +11,16 @@ type LineGroup struct {
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
}
// CheckGroup -
func CheckGroup(g string) (exists bool, err error) {
ss := struct {
C int `db:"c"`
}{}
err = x.Get(&ss, `select count(*) as c from "public"."line_group" where "id" = $1`, g)
if err != nil {
return false, err
}
return ss.C > 0, nil
}
+6
View File
@@ -26,6 +26,12 @@ func GetAllTwitchChannel() (channels []*TwitchChannel, err error) {
return
}
// GetJoinChatChannel -
func GetJoinChatChannel() (channels []*TwitchChannel, err error) {
err = x.Select(&channels, `select * from "public"."twitch_channel" where "join" = true`)
return
}
// UpdateStream -
func (p *TwitchChannel) UpdateStream(streamID string) (err error) {
query := `update "public"."twitch_channel" set "laststream" = $1 where "id" = $2`