From 35351e93bb0b3dcecef596c28b31c587a96562f1 Mon Sep 17 00:00:00 2001 From: Raymond Lu Date: Wed, 27 Oct 2010 21:02:28 -0400 Subject: [PATCH] Handle http://youtube.com without www and allow links that don't start lines --- handler.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/handler.go b/handler.go index 7bb2f18..6f85f69 100644 --- a/handler.go +++ b/handler.go @@ -50,13 +50,8 @@ func handlePrivmsg(conn *irc.Conn, line *irc.Line) { target := line.Args[0] if isChannel(target) { // message to a channel - var video string - if strings.HasPrefix(line.Text, "http://www.youtube.com/watch?v=") { - video = line.Text[31:] - } else if strings.HasPrefix(line.Text, "http://www.youtube.com/watch?v=") { - video = line.Text[27:] - } - if video != "" { + if start := strings.Index(line.Text, "youtube.com/watch?v="); start > -1 { + video := line.Text[start+20:] if end := strings.IndexAny(video, " &#"); end > -1 { video = video[0:end] }