mtfosbot/model/twitch_channel.go

52 lines
1.3 KiB
Go
Raw Normal View History

2018-09-07 08:33:37 +00:00
package model
import "time"
2018-09-12 04:03:44 +00:00
// TwitchGroup -
type TwitchGroup struct {
*LineGroup
Tmpl string `db:"tmpl"`
}
2018-09-07 08:33:37 +00:00
// TwitchChannel - struct
type TwitchChannel struct {
2018-09-12 04:03:44 +00:00
ID string `db:"id" cc:"id"`
Name string `db:"name" cc:"name"`
LastStream string `db:"laststream" cc:"laststream"`
Join bool `db:"join" cc:"join"`
OpayID string `db:"opayid" cc:"opayid"`
Ctime time.Time `db:"ctime" cc:"ctime"`
Mtime time.Time `db:"mtime" cc:"ctime"`
Groups []*TwitchGroup `db:"-"`
2018-09-07 08:33:37 +00:00
}
2018-09-11 16:29:38 +00:00
2018-09-12 04:03:44 +00:00
// GetAllTwitchChannel -
func GetAllTwitchChannel() (channels []*TwitchChannel, err error) {
2018-09-11 16:29:38 +00:00
err = x.Select(&channels, `select * from "public"."twitch_channel"`)
return
}
2018-09-12 04:03:44 +00:00
// UpdateStream -
func (p *TwitchChannel) UpdateStream(streamID string) (err error) {
query := `update "public"."twitch_channel" set "laststream" = $1 where "id" = $2`
_, err = x.Exec(query, streamID, p.ID)
if err != nil {
return
}
p.LastStream = streamID
return
}
// GetGroups -
func (p *TwitchChannel) GetGroups() (err error) {
query := `select g.*, rt.tmpl as tmpl from "public"."twitch_channel" tw
left join "public"."line_twitch_rt" rt
on rt.twitch = tw.id
left join "public"."line_group" g
on g.id = rt.line
where
tw.id = $1`
err = x.Select(&p.Groups, query, p.ID)
return
}