add youtube webhook
This commit is contained in:
@@ -34,11 +34,11 @@ func GetFacebookPage(id string) (page *FacebookPage, err error) {
|
||||
|
||||
// AddPage -
|
||||
func (p *FacebookPage) AddPage() (err error) {
|
||||
rows, err := x.NamedQuery(`insert into "public"."facebook_page" ("id", "lastpost") values (:id, :lastpost) returning *`, p)
|
||||
stmt, err := x.PrepareNamed(`insert into "public"."facebook_page" ("id", "lastpost") values (:id, :lastpost) returning *`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = rows.StructScan(&p)
|
||||
err = stmt.Get(p, p)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,42 @@ func (p *LineFacebookRT) AddRT() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// DelRT -
|
||||
func (p *LineFacebookRT) DelRT() (err error) {
|
||||
_, err = x.NamedExec(`delete from "public"."line_fb_rt" where "line" = :line and "facebook" = :facebook`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// GetRT -
|
||||
func (p *LineFacebookRT) GetRT() (err error) {
|
||||
stmt, err := x.PrepareNamed(`select * from "public"."line_fb_rt" where "line" = :line and "facebook" = :facebook`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = stmt.Get(p, p)
|
||||
return
|
||||
}
|
||||
|
||||
// AddRT - add twitch line rt
|
||||
func (p *LineTwitchRT) AddRT() (err error) {
|
||||
_, err = x.NamedExec(`insert into "public"."line_twitch_rt" ("line", "twitch", "type", "tmpl") values (:line, :twitch, :type, :tmpl)`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// DelRT -
|
||||
func (p *LineTwitchRT) DelRT() (err error) {
|
||||
_, err = x.NamedExec(`delete from "public"."line_twitch_rt" where "line" = :line and "twitch" = :twitch and "type" = :type`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// AddRT - add youtube line rt
|
||||
func (p *LineYoutubeRT) AddRT() (err error) {
|
||||
_, err = x.NamedExec(`insert into "public"."line_youtube_rt" ("line", "youtube", "tmpl") values (:line, :youtube, :tmpl)`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// DelRT -
|
||||
func (p *LineYoutubeRT) DelRT() (err error) {
|
||||
_, err = x.NamedExec(`delete from "public"."line_youtube_rt" where "line" = :line and "youtube" = :youtube`, p)
|
||||
return
|
||||
}
|
||||
|
||||
+15
-4
@@ -32,13 +32,24 @@ func GetJoinChatChannel() (channels []*TwitchChannel, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Add -
|
||||
func (p *TwitchChannel) Add() (err error) {
|
||||
rows, err := x.NamedQuery(`insert into "public"."twitch_channel" ("name", "laststream", "join", "opayid") values (:name, :laststream, :join, :opayid) returning *`, p)
|
||||
// GetWithName -
|
||||
func (p *TwitchChannel) GetWithName() (err error) {
|
||||
stmt, err := x.PrepareNamed(`select * from "public"."twitch_channel" where "name" = :name`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = rows.StructScan(p)
|
||||
|
||||
err = stmt.Get(p, p)
|
||||
return
|
||||
}
|
||||
|
||||
// Add -
|
||||
func (p *TwitchChannel) Add() (err error) {
|
||||
stmt, err := x.PrepareNamed(`insert into "public"."twitch_channel" ("name", "laststream", "join", "opayid") values (:name, :laststream, :join, :opayid) returning *`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = stmt.Get(p, p)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,55 @@ package model
|
||||
|
||||
import "time"
|
||||
|
||||
// YoutubeGroup -
|
||||
type YoutubeGroup struct {
|
||||
*LineGroup
|
||||
Tmpl string `db:"tmpl"`
|
||||
}
|
||||
|
||||
// YoutubeChannel -
|
||||
type YoutubeChannel struct {
|
||||
ID string `db:"id" cc:"id"`
|
||||
Name string `db:"name" cc:"name"`
|
||||
LastVideo string `db:"lastvideo" cc:"lastvideo"`
|
||||
Expire int32 `db:"expire" cc:"expire"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"mtime"`
|
||||
ID string `db:"id" cc:"id"`
|
||||
Name string `db:"name" cc:"name"`
|
||||
LastVideo string `db:"lastvideo" cc:"lastvideo"`
|
||||
Expire int64 `db:"expire" cc:"expire"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
Mtime time.Time `db:"mtime" cc:"mtime"`
|
||||
Groups []*YoutubeGroup `db:"-"`
|
||||
}
|
||||
|
||||
// GetYoutubeChannelWithID -
|
||||
func GetYoutubeChannelWithID(id string) (yt *YoutubeChannel, err error) {
|
||||
err = x.Get(&yt, `select * from "public"."youtube_channel" where "id" = $1`, id)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateLastVideo -
|
||||
func (p *YoutubeChannel) UpdateLastVideo(vid string) (err error) {
|
||||
p.LastVideo = vid
|
||||
_, err = x.NamedExec(`update "public"."youtube_channel" set "lastvideo" = :lastvideo where "id" = :id`, p)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateExpire -
|
||||
func (p *YoutubeChannel) UpdateExpire(t int64) (err error) {
|
||||
p.Expire = t
|
||||
_, err = x.NamedExec(`update "public"."youtube_channel" set "expire" = :expire where "id" = :id`, p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetGroups -
|
||||
func (p *YoutubeChannel) GetGroups() (err error) {
|
||||
query := `select g.*, rt.tmpl as tmpl from "public"."youtube_channel" yt
|
||||
left join "public"."line_youtube_rt" rt
|
||||
on rt.youtube = yt.id
|
||||
left join "public"."line_group" g
|
||||
on g.id = rt.line
|
||||
where
|
||||
yt.id = $1`
|
||||
err = x.Select(&p.Groups, query, p.ID)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user