update
This commit is contained in:
+38
-1
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user