diff --git a/site/youtube.go b/site/youtube.go index c872b471ee28cf4a60dfe1436ed7439786b997bd..4f96853b451c596b703f574ece20badaa9cd2053 100644 --- a/site/youtube.go +++ b/site/youtube.go @@ -46,7 +46,8 @@ func (yt Youtube) Read(url string) (*Content, error) { return &Content{ Author: video.Snippet.ChannelTitle, - Duration: duration + 1, + Duration: duration, + Title: video.Snippet.Title, Source: "youtube", SourceId: video.Id, Url: "https://www.youtube.com/watch?v=" + video.Id, diff --git a/transport/irc/.events.go.swp b/transport/irc/.events.go.swp deleted file mode 100644 index 92779672c8ec1df79889d67ee8382586b7a777ee..0000000000000000000000000000000000000000 Binary files a/transport/irc/.events.go.swp and /dev/null differ diff --git a/transport/irc/.print.go.swp b/transport/irc/.print.go.swp deleted file mode 100644 index 853d46928d8b839cbf92af3320f486514dd72286..0000000000000000000000000000000000000000 Binary files a/transport/irc/.print.go.swp and /dev/null differ diff --git a/transport/irc/events.go b/transport/irc/events.go index 64571102f9508cfa9ea72c574ebd49eb9da1e5cb..86c186735a98758eb9af6b5ab03325f471c5076a 100644 --- a/transport/irc/events.go +++ b/transport/irc/events.go @@ -29,6 +29,6 @@ func (t *IrcTransport) privmsg(conn *irc.Conn, line *irc.Line) { go b.ParseLine(line.Nick, msg, contents) for content := range contents { - t.printContent(content) + t.printContent(conn, content, channel) } } diff --git a/transport/irc/print.go b/transport/irc/print.go index e7cc912d916a16916b54160c36ccd727712e8cad..ec899b067ef94a60a98173891cd63b3eb4ab8aab 100644 --- a/transport/irc/print.go +++ b/transport/irc/print.go @@ -1,13 +1,69 @@ package irc import ( + "fmt" "log" + irc "github.com/fluffle/goirc/client" + "git.iiens.net/morignot2011/playbot/site" ) -func (t *IrcTransport) printContent(content *site.Content) { - log.Printf("Print lol: %q", content) +const ( + NORMAL string = "\x0f" + BOLD string = "\x02" + UNDERLINE string = "\x1f" + REVERSE string = "\x16" + ITALIC string = "\x1d" + FIXED string = "\x11" + BLINK string = "\x06" + + WHITE string = "\x0300" + BLACK string = "\x0301" + BLUE string = "\x0302" + GREEN string = "\x0303" + RED string = "\x0304" + BROWN string = "\x0305" + PURPLE string = "\x0306" + ORANGE string = "\x0307" + YELLOW string = "\x0308" + LIGHT_GREEN string = "\x0309" + TEAL string = "\x0310" + LIGHT_CYAN string = "\x0311" + LIGHT_BLUE string = "\x0312" + PINK string = "\x0313" + GREY string = "\x0314" + LIGHT_GREY string = "\x0315" +) + +func (t *IrcTransport) printContent(conn *irc.Conn, content *site.Content, channel string) { + msg := fmt.Sprintf("%s[%d] %s%s", YELLOW, content.Id, GREEN, content.Title) + + if content.Author != "" { + msg += " | " + content.Author + } + + if content.Duration > 0 { + h := content.Duration / 3600 + m := (content.Duration % 3600) / 60 + s := (content.Duration % 3600) % 60 + + msg += LIGHT_BLUE + " (" + + if h > 0 { + msg += fmt.Sprintf("%02d:", h) + } + + if m > 0 { + msg += fmt.Sprintf("%02d:", m) + } + + msg += fmt.Sprintf("%02d)%s", s, NORMAL) + } + + msg += " => " + content.Url + ORANGE + + conn.Privmsg(channel, msg) } func (t *IrcTransport) printError(err error) {