From 426acebb428ddfb1ea24c9fe3dd82ff6c2637808 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 1 Oct 2018 11:45:28 +0800 Subject: [PATCH] add youtube line command --- module/message-command/line-group.go | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/module/message-command/line-group.go b/module/message-command/line-group.go index 12e695d..777c240 100644 --- a/module/message-command/line-group.go +++ b/module/message-command/line-group.go @@ -26,6 +26,10 @@ 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 "addyoutube": + return addYoutubeChannel(sub, txt, s) + case "delyoutube": + return delYoutubeChannel(sub, txt, s) case "hello": return "World!!" } @@ -298,3 +302,31 @@ func addYoutubeChannel(sub, txt string, s *lineobj.SourceObject) (res string) { return "Success" } + +func delYoutubeChannel(sub, txt string, s *lineobj.SourceObject) (res string) { + // args = youtubeID + ok, err := checkGroupOwner(s) + if err != nil { + return "check group fail" + } + if !ok { + return "not owner" + } + txt = strings.Trim(txt, " ") + ytData, err := model.GetYoutubeChannelWithID(txt) + if err != nil { + return "check channel fail" + } + if ytData == nil { + return "channel not exists" + } + rt := &model.LineYoutubeRT{ + Line: s.GroupID, + Youtube: ytData.ID, + } + err = rt.DelRT() + if err != nil { + return "delete channel fail" + } + return "Success" +}