From 1c35860c177c4ad606989ab2f74f9bfed39191c7 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 18 Dec 2018 16:50:38 +0800 Subject: [PATCH] add video command body --- model/lottery.go | 4 +--- module/message-command/line-group.go | 2 ++ module/message-command/message-command.go | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/model/lottery.go b/model/lottery.go index 89b4fc9..52da806 100644 --- a/model/lottery.go +++ b/model/lottery.go @@ -2,7 +2,6 @@ package model import ( "database/sql" - "math/rand" "time" ) @@ -29,8 +28,7 @@ func GetRandomLotteryByType(t string) (p *Lottery, err error) { // GetRandomLotteryByTypeAndLimit - func GetRandomLotteryByTypeAndLimit(t string, limit int) (p []*Lottery, err error) { - offset := rand.Intn(10) - err = x.Select(&p, `select * from "public"."lottery" where "type" = $1 order by random() offset $2 limit $3`, t, offset, limit) + err = x.Select(&p, `select * from "public"."lottery" where "type" = $1 offset floor(random() * (select count(*) as c from "public"."lottery" where "type" = $2)) limit $3`, t, t, limit) if err == sql.ErrNoRows { return nil, nil } diff --git a/module/message-command/line-group.go b/module/message-command/line-group.go index 6ce0095..e90e556 100644 --- a/module/message-command/line-group.go +++ b/module/message-command/line-group.go @@ -28,6 +28,8 @@ func selectAct(cmd, sub, txt string, s *lineobj.SourceObject) (res string) { return delTwitchChannel(sub, txt, s) case "image": return fmt.Sprintf("$image$%s", sub) + case "video": + return fmt.Sprintf("$video$%s", sub) case "addyoutube": return addYoutubeChannel(sub, txt, s) case "delyoutube": diff --git a/module/message-command/message-command.go b/module/message-command/message-command.go index 90f70be..d6440c1 100644 --- a/module/message-command/message-command.go +++ b/module/message-command/message-command.go @@ -79,6 +79,13 @@ func parseResult(str string) interface{} { OriginalContentURL: strs[0], PreviewImageURL: strs[1], } + } else if strings.HasPrefix(str, "$video$") { + str = strings.Replace(str, "$video$", "", 1) + strs := strings.Split(str, ";") + m = &line.VideoMessage{ + OriginalContentURL: strs[0], + PreviewImageURL: strs[1], + } } else { m = &line.TextMessage{ Text: str,