From a1f2066532d6c8013a25d1054fd43bdc1431fcf8 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:38:35 +0100 Subject: [PATCH 01/67] Improving web authentication --- commands.go | 37 ++++-------------------- service.go | 36 +++++++++++++++++++++-- service_youtube.go | 16 +++++------ web.go | 72 +++++++++++++++++++++------------------------- 4 files changed, 81 insertions(+), 80 deletions(-) diff --git a/commands.go b/commands.go index 61c83fb..99db8fd 100644 --- a/commands.go +++ b/commands.go @@ -36,7 +36,7 @@ func parseCommand(user *gumble.User, username, command string) { // Add command case dj.conf.Aliases.AddAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminAdd) { - add(user, username, argument) + add(user, argument) } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } @@ -166,40 +166,15 @@ func parseCommand(user *gumble.User, username, command string) { // add performs !add functionality. Checks input URL for service, and adds // the URL to the queue if the format matches. -func add(user *gumble.User, username, url string) { +func add(user *gumble.User, url string) { if url == "" { dj.SendPrivateMessage(user, NO_ARGUMENT_MSG) } else { - var urlService Service - - // Checks all services to see if any can take the URL - for _, service := range services { - if service.URLRegex(url) { - urlService = service - } - } - - if urlService == nil { - dj.SendPrivateMessage(user, INVALID_URL_MSG) + title, err := findServiceAndAdd(user, url) + if err == nil { + dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, user.Name, title), false) } else { - oldLength := dj.queue.Len() - - if err := urlService.NewRequest(user, url); err == nil { - dj.client.Self.Channel.Send(SONG_ADDED_HTML, false) - - // Starts playing the new song if nothing else is playing - if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() { - if err := dj.queue.CurrentSong().Download(); err == nil { - dj.queue.CurrentSong().Play() - } else { - dj.SendPrivateMessage(user, AUDIO_FAIL_MSG) - dj.queue.CurrentSong().Delete() - dj.queue.OnSongFinished() - } - } - } else { - dj.SendPrivateMessage(user, err.Error()) - } + dj.SendPrivateMessage(user, err.Error()) } } } diff --git a/service.go b/service.go index 541605b..7c67733 100644 --- a/service.go +++ b/service.go @@ -8,14 +8,15 @@ package main import ( + "fmt" "github.com/layeh/gumble/gumble" ) // Service interface. Each service should implement these functions type Service interface { ServiceName() string - URLRegex(string) bool // Can service deal with URL - NewRequest(*gumble.User, string) error // Create song/playlist and add to the queue + URLRegex(string) bool // Can service deal with URL + NewRequest(*gumble.User, string) (string, error) // Create song/playlist and add to the queue } // Song interface. Each service will implement these @@ -50,3 +51,34 @@ type Playlist interface { } var services = []Service{YouTube{}} + +func findServiceAndAdd(user *gumble.User, url string) (string, error) { + var urlService Service + + // Checks all services to see if any can take the URL + for _, service := range services { + if service.URLRegex(url) { + urlService = service + } + } + + if urlService == nil { + return nil, errors.New("INVALID_URL") + } else { + oldLength := dj.queue.Len() + if title, err := urlService.NewRequest(user, url); err == nil { + + // Starts playing the new song if nothing else is playing + if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() { + if err := dj.queue.CurrentSong().Download(); err == nil { + dj.queue.CurrentSong().Play() + } else { + dj.queue.CurrentSong().Delete() + dj.queue.OnSongFinished() + return nil, errors.New("FAILED_TO_DOWNLOAD") + } + } + } + return title, err + } +} diff --git a/service_youtube.go b/service_youtube.go index 4c60cd0..a831f09 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -39,7 +39,7 @@ var youtubeVideoPatterns = []string{ // YOUTUBE SERVICE // --------------- -type YouTube struct {} +type YouTube struct{} // Name of the service func (y YouTube) ServiceName() string { @@ -63,16 +63,16 @@ func RegexpFromURL(url string, patterns []string) *regexp.Regexp { } // Creates the requested song/playlist and adds to the queue -func (y YouTube) NewRequest(user *gumble.User, url string) error { +func (y YouTube) NewRequest(user *gumble.User, url string) (string, error) { var shortURL, startOffset = "", "" if re, err := regexp.Compile(youtubePlaylistPattern); err == nil { if re.MatchString(url) { if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) { shortURL = re.FindStringSubmatch(url)[1] - _, err := NewYouTubePlaylist(user.Name, shortURL) - return err + playlist, err := NewYouTubePlaylist(user.Name, shortURL) + return playlist.Title(), err } else { - return errors.New("NO_PLAYLIST_PERMISSION") + return nil, errors.New("NO_PLAYLIST_PERMISSION") } } else { re = RegexpFromURL(url, youtubeVideoPatterns) @@ -81,11 +81,11 @@ func (y YouTube) NewRequest(user *gumble.User, url string) error { if len(matches[0]) == 3 { startOffset = matches[0][2] } - _, err := NewYouTubeSong(user.Name, shortURL, startOffset, nil) - return err + song, err := NewYouTubeSong(user.Name, shortURL, startOffset, nil) + return song.Title(), err } } else { - return err + return nil, err } } diff --git a/web.go b/web.go index 76f826b..b513255 100644 --- a/web.go +++ b/web.go @@ -5,64 +5,58 @@ import ( "io/ioutil" "math/rand" "net/http" + "html" "strings" "time" "github.com/layeh/gumble/gumble" ) -var client_token = make(map[string]string) -var token_client = make(map[string]string) +var client_token = make(map[*gumble.User]string) +var token_client = make(map[string]*gumble.User) var external_ip = "" -type Page struct { - Title string - Body []byte -} - -func (p *Page) save() error { - filename := p.Title + ".txt" - return ioutil.WriteFile(filename, p.Body, 0600) -} - -func loadPage(title string) (*Page, error) { - filename := title + ".txt" - body, err := ioutil.ReadFile(filename) - if err != nil { - return nil, err - } - return &Page{Title: title, Body: body}, nil -} - -func handler(w http.ResponseWriter, r *http.Request) { - var uname = token_client[r.URL.Path[1:]] - if uname == "" { - fmt.Fprintf(w, "I don't know you") - } else { - fmt.Fprintf(w, "Hi there, I love %s!", uname) - } -} - func Webserver() { - http.HandleFunc("/", handler) + http.HandleFunc("/", homepage) + http.HandleFunc("/add", addSong) http.ListenAndServe(":9563", nil) rand.Seed(time.Now().UnixNano()) } +func homepage(w http.ResponseWriter, r *http.Request) { + var uname = token_client[r.FormValue("token")] + if uname == "" { + fmt.Fprintf(w, "Invalid Token") + } else { + fmt.Fprintf(w, "Hang in there %s, I haven't made the website yet!", uname.Name) + } +} + +func addSong(w http.ResponseWriter, r *http.Request) { + var uname = token_client[r.FormValue("token")] + if uname == "" { + fmt.Fprintf(w, "Invalid Token") + } else { + var url = UnescapeString(r.FormValue("url")) + + } +} + func GetWebAddress(user *gumble.User) { - if client_token[user.Name] != "" { - token_client[client_token[user.Name]] = "" + if client_token[user] != "" { + token_client[client_token[user]] = "" } // dealing with collisions var firstLoop = true - for firstLoop || token_client[client_token[user.Name]] != "" { - client_token[user.Name] = randSeq(10) + for firstLoop || token_client[client_token[user]] != "" { + client_token[user] = randSeq(10) firstLoop = false } - token_client[client_token[user.Name]] = user.Name - dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), client_token[user.Name], getIP(), client_token[user.Name])) + token_client[client_token[user]] = user + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), client_token[user], getIP(), client_token[user])) } +// Gets the external ip address for the server func getIP() string { if external_ip != "" { return external_ip @@ -79,9 +73,9 @@ func getIP() string { } } -var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") - +// Generates a pseudorandom string of characters func randSeq(n int) string { + var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") b := make([]rune, n) for i := range b { b[i] = letters[rand.Intn(len(letters))] From fb9f9cc418787b1f9acf8d745b6635e30c3a0311 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:40:44 +0100 Subject: [PATCH 02/67] Fixing build issues --- service.go | 9 ++++++--- web.go | 3 +-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/service.go b/service.go index 7c67733..551fc28 100644 --- a/service.go +++ b/service.go @@ -8,7 +8,8 @@ package main import ( - "fmt" + "errors" + "github.com/layeh/gumble/gumble" ) @@ -63,9 +64,11 @@ func findServiceAndAdd(user *gumble.User, url string) (string, error) { } if urlService == nil { - return nil, errors.New("INVALID_URL") + return "", errors.New("INVALID_URL") } else { oldLength := dj.queue.Len() + var title string + var err error if title, err := urlService.NewRequest(user, url); err == nil { // Starts playing the new song if nothing else is playing @@ -75,7 +78,7 @@ func findServiceAndAdd(user *gumble.User, url string) (string, error) { } else { dj.queue.CurrentSong().Delete() dj.queue.OnSongFinished() - return nil, errors.New("FAILED_TO_DOWNLOAD") + return "", errors.New("FAILED_TO_DOWNLOAD") } } } diff --git a/web.go b/web.go index b513255..cc392b2 100644 --- a/web.go +++ b/web.go @@ -5,7 +5,6 @@ import ( "io/ioutil" "math/rand" "net/http" - "html" "strings" "time" @@ -38,7 +37,7 @@ func addSong(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { var url = UnescapeString(r.FormValue("url")) - + } } From ad25f4bcc3b3fa3adbf1f115c5cd3ce58eb1df9d Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:43:02 +0100 Subject: [PATCH 03/67] Fixing build issues --- service_youtube.go | 4 ++-- web.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/service_youtube.go b/service_youtube.go index a831f09..9a94723 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -72,7 +72,7 @@ func (y YouTube) NewRequest(user *gumble.User, url string) (string, error) { playlist, err := NewYouTubePlaylist(user.Name, shortURL) return playlist.Title(), err } else { - return nil, errors.New("NO_PLAYLIST_PERMISSION") + return "", errors.New("NO_PLAYLIST_PERMISSION") } } else { re = RegexpFromURL(url, youtubeVideoPatterns) @@ -85,7 +85,7 @@ func (y YouTube) NewRequest(user *gumble.User, url string) (string, error) { return song.Title(), err } } else { - return nil, err + return "", err } } diff --git a/web.go b/web.go index cc392b2..28ae8cd 100644 --- a/web.go +++ b/web.go @@ -24,7 +24,7 @@ func Webserver() { func homepage(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.FormValue("token")] - if uname == "" { + if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { fmt.Fprintf(w, "Hang in there %s, I haven't made the website yet!", uname.Name) @@ -33,7 +33,7 @@ func homepage(w http.ResponseWriter, r *http.Request) { func addSong(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.FormValue("token")] - if uname == "" { + if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { var url = UnescapeString(r.FormValue("url")) @@ -43,11 +43,11 @@ func addSong(w http.ResponseWriter, r *http.Request) { func GetWebAddress(user *gumble.User) { if client_token[user] != "" { - token_client[client_token[user]] = "" + token_client[client_token[user]] = nil } // dealing with collisions var firstLoop = true - for firstLoop || token_client[client_token[user]] != "" { + for firstLoop || token_client[client_token[user]] != nil { client_token[user] = randSeq(10) firstLoop = false } From 5f73536b666c5333522e2a00c088c6f0f1df5259 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:43:46 +0100 Subject: [PATCH 04/67] Fixing build issues --- web.go | 1 + 1 file changed, 1 insertion(+) diff --git a/web.go b/web.go index 28ae8cd..8d5b379 100644 --- a/web.go +++ b/web.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "html" "io/ioutil" "math/rand" "net/http" From a7e6b74b9d3b9191541620c5922c56105384491a Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:47:05 +0100 Subject: [PATCH 05/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 8d5b379..b44c601 100644 --- a/web.go +++ b/web.go @@ -37,7 +37,7 @@ func addSong(w http.ResponseWriter, r *http.Request) { if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - var url = UnescapeString(r.FormValue("url")) + var url = html.UnescapeString(r.FormValue("url")) } } From a0f8ee59a1a738ad6a3787b4ad7904540fa38010 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:48:20 +0100 Subject: [PATCH 06/67] Fixing build issues --- service.go | 2 +- web.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service.go b/service.go index 551fc28..bc0db34 100644 --- a/service.go +++ b/service.go @@ -69,7 +69,7 @@ func findServiceAndAdd(user *gumble.User, url string) (string, error) { oldLength := dj.queue.Len() var title string var err error - if title, err := urlService.NewRequest(user, url); err == nil { + if title, err = urlService.NewRequest(user, url); err == nil { // Starts playing the new song if nothing else is playing if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() { diff --git a/web.go b/web.go index b44c601..afc760f 100644 --- a/web.go +++ b/web.go @@ -38,7 +38,7 @@ func addSong(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { var url = html.UnescapeString(r.FormValue("url")) - + fmt.Fprintf(w, url) } } From 5d68fc57b76bfe96faa427da2e5d88d635b23a0a Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 21:56:07 +0100 Subject: [PATCH 07/67] Fixing build issues --- strings.go | 4 ++-- web.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/strings.go b/strings.go index e8cf2b5..0ea151b 100644 --- a/strings.go +++ b/strings.go @@ -173,5 +173,5 @@ const CURRENT_SONG_PLAYLIST_HTML = ` // URL of the server for connecting via a web address const WEB_ADDRESS = ` - Control mumbledj from a web browser: http://%s:9563/%s -` \ No newline at end of file + Control mumbledj from a web browser: http://%s/%s +` diff --git a/web.go b/web.go index afc760f..3cb5e55 100644 --- a/web.go +++ b/web.go @@ -19,12 +19,12 @@ var external_ip = "" func Webserver() { http.HandleFunc("/", homepage) http.HandleFunc("/add", addSong) - http.ListenAndServe(":9563", nil) + http.ListenAndServe(":80", nil) rand.Seed(time.Now().UnixNano()) } func homepage(w http.ResponseWriter, r *http.Request) { - var uname = token_client[r.FormValue("token")] + var uname = token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { From 7375b4174ae6a7810bc557109a4068ad09f4266c Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 22:05:49 +0100 Subject: [PATCH 08/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 3cb5e55..a7b43e0 100644 --- a/web.go +++ b/web.go @@ -19,7 +19,7 @@ var external_ip = "" func Webserver() { http.HandleFunc("/", homepage) http.HandleFunc("/add", addSong) - http.ListenAndServe(":80", nil) + http.ListenAndServe(":9563", nil) rand.Seed(time.Now().UnixNano()) } From cccb76d553cdbc0f95c6c99a74c951441c192302 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 22:06:09 +0100 Subject: [PATCH 09/67] Fixing build issues --- strings.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings.go b/strings.go index 0ea151b..9d5524f 100644 --- a/strings.go +++ b/strings.go @@ -173,5 +173,5 @@ const CURRENT_SONG_PLAYLIST_HTML = ` // URL of the server for connecting via a web address const WEB_ADDRESS = ` - Control mumbledj from a web browser: http://%s/%s + Control mumbledj from a web browser: http://%s:9563/%s ` From 90671fd1a504a736a7de8cb576863c98f53da088 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Wed, 29 Jul 2015 02:04:32 +0100 Subject: [PATCH 10/67] Fixing build issues --- Makefile | 1 + commands.go | 4 +++- index.html | 18 ++++++++++++++++++ main.go | 6 +++--- web.go | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 index.html diff --git a/Makefile b/Makefile index 5de2412..36b484b 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ clean: install: mkdir -p ~/.mumbledj/config mkdir -p ~/.mumbledj/songs + mkdir -p ~/.mumbledj/web if [ -a ~/.mumbledj/config/mumbledj.gcfg ]; then mv ~/.mumbledj/config/mumbledj.gcfg ~/.mumbledj/config/mumbledj_backup.gcfg; fi; cp -u config.gcfg ~/.mumbledj/config/mumbledj.gcfg if [ -d ~/bin ]; then cp -f mumbledj* ~/bin/mumbledj; else sudo cp -f mumbledj* /usr/local/bin/mumbledj; fi; diff --git a/commands.go b/commands.go index 99db8fd..59d66ea 100644 --- a/commands.go +++ b/commands.go @@ -166,9 +166,10 @@ func parseCommand(user *gumble.User, username, command string) { // add performs !add functionality. Checks input URL for service, and adds // the URL to the queue if the format matches. -func add(user *gumble.User, url string) { +func add(user *gumble.User, url string) error { if url == "" { dj.SendPrivateMessage(user, NO_ARGUMENT_MSG) + return errors.New("NO_ARGUMENT") } else { title, err := findServiceAndAdd(user, url) if err == nil { @@ -176,6 +177,7 @@ func add(user *gumble.User, url string) { } else { dj.SendPrivateMessage(user, err.Error()) } + return err } } diff --git a/index.html b/index.html new file mode 100644 index 0000000..e4c1635 --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + + + + %s - mumbledj + + + +

Add Song Form

+ + + + \ No newline at end of file diff --git a/main.go b/main.go index bc8d710..b841957 100644 --- a/main.go +++ b/main.go @@ -102,7 +102,7 @@ func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) { func (dj *mumbledj) OnUserChange(e *gumble.UserChangeEvent) { if e.Type.Has(gumble.UserChangeDisconnected) { if dj.audioStream.IsPlaying() { - if dj.queue.CurrentSong().Playlist() != nil { + if !isNull(dj.queue.CurrentSong().Playlist()) { dj.queue.CurrentSong().Playlist().RemoveSkip(e.User.Name) } dj.queue.CurrentSong().RemoveSkip(e.User.Name) @@ -228,8 +228,8 @@ func main() { if err := dj.client.Connect(); err != nil { fmt.Printf("Could not connect to Mumble server at %s:%s.\n", address, port) os.Exit(1) - } - + } + Webserver() <-dj.keepAlive diff --git a/web.go b/web.go index a7b43e0..c26bcf6 100644 --- a/web.go +++ b/web.go @@ -38,7 +38,7 @@ func addSong(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { var url = html.UnescapeString(r.FormValue("url")) - fmt.Fprintf(w, url) + add(uname, url) } } From ef0d9691b8823ccc8cb30c061a16757af20aa4d8 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Wed, 29 Jul 2015 02:05:21 +0100 Subject: [PATCH 11/67] Fixing build issues --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index b841957..dd7bec3 100644 --- a/main.go +++ b/main.go @@ -102,7 +102,7 @@ func (dj *mumbledj) OnTextMessage(e *gumble.TextMessageEvent) { func (dj *mumbledj) OnUserChange(e *gumble.UserChangeEvent) { if e.Type.Has(gumble.UserChangeDisconnected) { if dj.audioStream.IsPlaying() { - if !isNull(dj.queue.CurrentSong().Playlist()) { + if !isNil(dj.queue.CurrentSong().Playlist()) { dj.queue.CurrentSong().Playlist().RemoveSkip(e.User.Name) } dj.queue.CurrentSong().RemoveSkip(e.User.Name) From 32006b3e50990148ed13fa54a22ad422976de71b Mon Sep 17 00:00:00 2001 From: Michael Oultram Date: Wed, 29 Jul 2015 23:34:51 +0100 Subject: [PATCH 12/67] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index f58a1bd..71a878f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ All commandline parameters are optional. Below are descriptions of all the avail * `-key`: Path to user PEM key. Defaults to no key. * `-insecure`: If included, the bot will not check the certs for the server. Try using this commandline flag if you are having connection issues. * `-accesstokens`: List of access tokens for the bot separated by spaces. Defaults to no access tokens. +* `-verbose`: Prints out song status into the console. ## FEATURES * Plays audio from both YouTube videos and YouTube playlists! @@ -50,6 +51,7 @@ Command | Description | Arguments | Admin | Example **help** | Displays this list of commands in Mumble chat. | None | No | `!help` **volume** | Either outputs the current volume or changes the current volume. If desired volume is not provided, the current volume will be displayed in chat. Otherwise, the volume for the bot will be changed to desired volume if it is within the allowed volume range. | None OR desired volume | No | `!volume 0.5`, `!volume` **move** | Moves MumbleDJ into channel if it exists. | Channel | Yes | `!move Music` +**web** | Displays a unique url for the user to control mumbledj from a web browser | None | No | `!web` **reload** | Reloads `mumbledj.gcfg` to retrieve updated configuration settings. | None | Yes | `!reload` **reset** | Stops all audio and resets the song queue. | None | Yes | `!reset` **numsongs** | Outputs the number of songs in the queue in chat. Individual songs and songs within playlists are both counted. | None | No | `!numsongs` From dbc58bd95b18c47042dfb249bea2e36e6d239d73 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 13:48:53 +0100 Subject: [PATCH 13/67] Using a web template --- commands.go | 8 +- index.html | 28 ++++++- main.go | 13 ++- service.go | 8 +- service_youtube.go | 196 ++++++++++++++++++++++----------------------- web.go | 61 ++++++++++---- 6 files changed, 185 insertions(+), 129 deletions(-) diff --git a/commands.go b/commands.go index 59d66ea..d4dc02d 100644 --- a/commands.go +++ b/commands.go @@ -171,13 +171,7 @@ func add(user *gumble.User, url string) error { dj.SendPrivateMessage(user, NO_ARGUMENT_MSG) return errors.New("NO_ARGUMENT") } else { - title, err := findServiceAndAdd(user, url) - if err == nil { - dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, user.Name, title), false) - } else { - dj.SendPrivateMessage(user, err.Error()) - } - return err + return findServiceAndAdd(user, url) } } diff --git a/index.html b/index.html index e4c1635..5659235 100644 --- a/index.html +++ b/index.html @@ -2,17 +2,37 @@ - %s - mumbledj + {{user}} - mumbledj +

Add Song Form

- - + + + + + \ No newline at end of file diff --git a/main.go b/main.go index dd7bec3..91c00bb 100644 --- a/main.go +++ b/main.go @@ -152,6 +152,17 @@ func isNil(a interface{}) bool { return a == nil || reflect.ValueOf(a).IsNil() } +func RegexpFromURL(url string, patterns []string) *regexp.Regexp { + for _, pattern := range patterns { + if re, err := regexp.Compile(pattern); err == nil { + if re.MatchString(url) { + return re + } + } + } + return nil +} + // dj variable declaration. This is done outside of main() to allow global use. var dj = mumbledj{ keepAlive: make(chan bool), @@ -230,7 +241,7 @@ func main() { os.Exit(1) } - Webserver() + Webserver(9563) <-dj.keepAlive } diff --git a/service.go b/service.go index bc0db34..36c77ab 100644 --- a/service.go +++ b/service.go @@ -53,7 +53,7 @@ type Playlist interface { var services = []Service{YouTube{}} -func findServiceAndAdd(user *gumble.User, url string) (string, error) { +func findServiceAndAdd(user *gumble.User, url string) error { var urlService Service // Checks all services to see if any can take the URL @@ -69,7 +69,9 @@ func findServiceAndAdd(user *gumble.User, url string) (string, error) { oldLength := dj.queue.Len() var title string var err error + if title, err = urlService.NewRequest(user, url); err == nil { + dj.client.Self.Channel.Send(fmt.Sprintf(SONG_ADDED_HTML, user.Name, title), false) // Starts playing the new song if nothing else is playing if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() { @@ -81,7 +83,9 @@ func findServiceAndAdd(user *gumble.User, url string) (string, error) { return "", errors.New("FAILED_TO_DOWNLOAD") } } + } else { + dj.SendPrivateMessage(user, err.Error()) } - return title, err + return err } } diff --git a/service_youtube.go b/service_youtube.go index 9a94723..63a343d 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -35,64 +35,13 @@ var youtubeVideoPatterns = []string{ `https?:\/\/www.youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`, } -// --------------- -// YOUTUBE SERVICE -// --------------- +// ------ +// TYPES +// ------ +// YouTube implements the Service interface type YouTube struct{} -// Name of the service -func (y YouTube) ServiceName() string { - return "Youtube" -} - -// Checks to see if service will accept URL -func (y YouTube) URLRegex(url string) bool { - return RegexpFromURL(url, append(youtubeVideoPatterns, []string{youtubePlaylistPattern}...)) != nil -} - -func RegexpFromURL(url string, patterns []string) *regexp.Regexp { - for _, pattern := range patterns { - if re, err := regexp.Compile(pattern); err == nil { - if re.MatchString(url) { - return re - } - } - } - return nil -} - -// Creates the requested song/playlist and adds to the queue -func (y YouTube) NewRequest(user *gumble.User, url string) (string, error) { - var shortURL, startOffset = "", "" - if re, err := regexp.Compile(youtubePlaylistPattern); err == nil { - if re.MatchString(url) { - if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) { - shortURL = re.FindStringSubmatch(url)[1] - playlist, err := NewYouTubePlaylist(user.Name, shortURL) - return playlist.Title(), err - } else { - return "", errors.New("NO_PLAYLIST_PERMISSION") - } - } else { - re = RegexpFromURL(url, youtubeVideoPatterns) - matches := re.FindAllStringSubmatch(url, -1) - shortURL = matches[0][1] - if len(matches[0]) == 3 { - startOffset = matches[0][2] - } - song, err := NewYouTubeSong(user.Name, shortURL, startOffset, nil) - return song.Title(), err - } - } else { - return "", err - } -} - -// ------------ -// YOUTUBE SONG -// ------------ - // YouTubeSong holds the metadata for a song extracted from a YouTube video. type YouTubeSong struct { submitter string @@ -107,14 +56,61 @@ type YouTubeSong struct { dontSkip bool } -// NewYouTubeSong gathers the metadata for a song extracted from a YouTube video, and returns +// YouTubePlaylist holds the metadata for a YouTube playlist. +type YouTubePlaylist struct { + id string + title string +} + +// --------------- +// YOUTUBE SERVICE +// --------------- + +// Name of the service +func (yt YouTube) ServiceName() string { + return "Youtube" +} + +// Checks to see if service will accept URL +func (yt YouTube) URLRegex(url string) bool { + return RegexpFromURL(url, append(youtubeVideoPatterns, []string{youtubePlaylistPattern}...)) != nil +} + +// Creates the requested song/playlist and adds to the queue +func (yt YouTube) NewRequest(user *gumble.User, url string) (string, error) { + var shortURL, startOffset = "", "" + if re, err := regexp.Compile(youtubePlaylistPattern); err == nil { + if re.MatchString(url) { + if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) { + shortURL = re.FindStringSubmatch(url)[1] + playlist, err := yt.NewPlaylist(user.Name, shortURL) + return playlist.Title(), err + } else { + return "", errors.New("NO_PLAYLIST_PERMISSION") + } + } else { + re = RegexpFromURL(url, youtubeVideoPatterns) + matches := re.FindAllStringSubmatch(url, -1) + shortURL = matches[0][1] + if len(matches[0]) == 3 { + startOffset = matches[0][2] + } + song, err := yt.NewSong(user.Name, shortURL, startOffset, nil) + return song.Title(), err + } + } else { + return "", err + } +} + +// NewSong gathers the metadata for a song extracted from a YouTube video, and returns // the song. -func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTubeSong, error) { +func (yt YouTube) NewSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTubeSong, error) { var apiResponse *jsonq.JsonQuery var err error url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=%s&key=%s", id, os.Getenv("YOUTUBE_API_KEY")) - if apiResponse, err = PerformGetRequest(url); err != nil { + if apiResponse, err = yt.PerformGetRequest(url); err != nil { return nil, errors.New(INVALID_API_KEY) } @@ -203,6 +199,46 @@ func NewYouTubeSong(user, id, offset string, playlist *YouTubePlaylist) (*YouTub return nil, errors.New(VIDEO_TOO_LONG_MSG) } +// NewPlaylist gathers the metadata for a YouTube playlist and returns it. +func (yt YouTube) NewPlaylist(user, id string) (*YouTubePlaylist, error) { + var apiResponse *jsonq.JsonQuery + var err error + // Retrieve title of playlist + url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=%s&key=%s", + id, os.Getenv("YOUTUBE_API_KEY")) + if apiResponse, err = yt.PerformGetRequest(url); err != nil { + return nil, err + } + title, _ := apiResponse.String("items", "0", "snippet", "title") + + playlist := &YouTubePlaylist{ + id: id, + title: title, + } + + // Retrieve items in playlist + url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s", + id, os.Getenv("YOUTUBE_API_KEY")) + if apiResponse, err = yt.PerformGetRequest(url); err != nil { + return nil, err + } + numVideos, _ := apiResponse.Int("pageInfo", "totalResults") + if numVideos > 50 { + numVideos = 50 + } + + for i := 0; i < numVideos; i++ { + index := strconv.Itoa(i) + videoID, _ := apiResponse.String("items", index, "snippet", "resourceId", "videoId") + yt.NewSong(user, videoID, "", playlist) + } + return playlist, nil +} + +// ------------ +// YOUTUBE SONG +// ------------ + // Download downloads the song via youtube-dl if it does not already exist on disk. // All downloaded songs are stored in ~/.mumbledj/songs and should be automatically cleaned. func (s *YouTubeSong) Download() error { @@ -380,48 +416,6 @@ func (s *YouTubeSong) SetDontSkip(value bool) { // YOUTUBE PLAYLIST // ---------------- -// YouTubePlaylist holds the metadata for a YouTube playlist. -type YouTubePlaylist struct { - id string - title string -} - -// NewYouTubePlaylist gathers the metadata for a YouTube playlist and returns it. -func NewYouTubePlaylist(user, id string) (*YouTubePlaylist, error) { - var apiResponse *jsonq.JsonQuery - var err error - // Retrieve title of playlist - url := fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlists?part=snippet&id=%s&key=%s", - id, os.Getenv("YOUTUBE_API_KEY")) - if apiResponse, err = PerformGetRequest(url); err != nil { - return nil, err - } - title, _ := apiResponse.String("items", "0", "snippet", "title") - - playlist := &YouTubePlaylist{ - id: id, - title: title, - } - - // Retrieve items in playlist - url = fmt.Sprintf("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s", - id, os.Getenv("YOUTUBE_API_KEY")) - if apiResponse, err = PerformGetRequest(url); err != nil { - return nil, err - } - numVideos, _ := apiResponse.Int("pageInfo", "totalResults") - if numVideos > 50 { - numVideos = 50 - } - - for i := 0; i < numVideos; i++ { - index := strconv.Itoa(i) - videoID, _ := apiResponse.String("items", index, "snippet", "resourceId", "videoId") - NewYouTubeSong(user, videoID, "", playlist) - } - return playlist, nil -} - // AddSkip adds a skip to the playlist's skippers slice. func (p *YouTubePlaylist) AddSkip(username string) error { for _, user := range dj.playlistSkips[p.ID()] { @@ -475,7 +469,7 @@ func (p *YouTubePlaylist) Title() string { // ----------- // PerformGetRequest does all the grunt work for a YouTube HTTPS GET request. -func PerformGetRequest(url string) (*jsonq.JsonQuery, error) { +func (yt YouTube) PerformGetRequest(url string) (*jsonq.JsonQuery, error) { jsonString := "" if response, err := http.Get(url); err == nil { diff --git a/web.go b/web.go index c26bcf6..25ce20f 100644 --- a/web.go +++ b/web.go @@ -12,37 +12,70 @@ import ( "github.com/layeh/gumble/gumble" ) -var client_token = make(map[*gumble.User]string) -var token_client = make(map[string]*gumble.User) -var external_ip = "" - -func Webserver() { - http.HandleFunc("/", homepage) - http.HandleFunc("/add", addSong) - http.ListenAndServe(":9563", nil) - rand.Seed(time.Now().UnixNano()) +type WebServer struct { + port int + client_token map[*gumble.User]string + token_client map[string]*gumble.User } -func homepage(w http.ResponseWriter, r *http.Request) { +type Page struct { + siteUrl string + token string +} + +var external_ip = "" + +func Webserver(port int) *WebServer { + var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} + http.HandleFunc("/", webServer.homepage) + http.HandleFunc("/add", webserver.add) + http.HandleFunc("/volume", webserver.volume) + http.HandleFunc("/skip", webserver.skip) + http.ListenAndServe(":"+port, nil) + rand.Seed(time.Now().UnixNano()) + return &webserver +} + +func (w WebServer) homepage(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - fmt.Fprintf(w, "Hang in there %s, I haven't made the website yet!", uname.Name) + t, _ := template.ParseFiles("index.html") + t.Execute(w, Page{"http://" + getIp() + ":" + w.port + "/", r.URL.Path[1:]}) } } -func addSong(w http.ResponseWriter, r *http.Request) { +func (w WebServer) add(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - var url = html.UnescapeString(r.FormValue("url")) + add(uname, html.UnescapeString(r.FormValue("value"))) + } +} + +func (w WebServer) volume(w http.ResponseWriter, r *http.Request) { + var uname = token_client[r.FormValue("token")] + if uname == nil { + fmt.Fprintf(w, "Invalid Token") + } else { + var url = html.UnescapeString(r.FormValue("value")) add(uname, url) } } -func GetWebAddress(user *gumble.User) { +func (w WebServer) skip(w http.ResponseWriter, r *http.Request) { + var uname = token_client[r.FormValue("token")] + if uname == nil { + fmt.Fprintf(w, "Invalid Token") + } else { + var url = html.UnescapeString(r.FormValue("value")) + add(uname, url) + } +} + +func (w WebServer) GetWebAddress(user *gumble.User) { if client_token[user] != "" { token_client[client_token[user]] = nil } From eb8afc4404d9eeca874e015f13fa75e56abe2b80 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 13:54:13 +0100 Subject: [PATCH 14/67] Fixing build issues --- main.go | 1 + service.go | 5 +++-- web.go | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 91c00bb..8a9d12a 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ import ( "os" "os/user" "reflect" + "regexp" "strings" "time" diff --git a/service.go b/service.go index 36c77ab..13a1d08 100644 --- a/service.go +++ b/service.go @@ -9,6 +9,7 @@ package main import ( "errors" + "fmt" "github.com/layeh/gumble/gumble" ) @@ -64,7 +65,7 @@ func findServiceAndAdd(user *gumble.User, url string) error { } if urlService == nil { - return "", errors.New("INVALID_URL") + return errors.New("INVALID_URL") } else { oldLength := dj.queue.Len() var title string @@ -80,7 +81,7 @@ func findServiceAndAdd(user *gumble.User, url string) error { } else { dj.queue.CurrentSong().Delete() dj.queue.OnSongFinished() - return "", errors.New("FAILED_TO_DOWNLOAD") + return errors.New("FAILED_TO_DOWNLOAD") } } } else { diff --git a/web.go b/web.go index 25ce20f..398cc02 100644 --- a/web.go +++ b/web.go @@ -36,7 +36,7 @@ func Webserver(port int) *WebServer { return &webserver } -func (w WebServer) homepage(w http.ResponseWriter, r *http.Request) { +func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -46,7 +46,7 @@ func (w WebServer) homepage(w http.ResponseWriter, r *http.Request) { } } -func (w WebServer) add(w http.ResponseWriter, r *http.Request) { +func (web WebServer) add(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -55,7 +55,7 @@ func (w WebServer) add(w http.ResponseWriter, r *http.Request) { } } -func (w WebServer) volume(w http.ResponseWriter, r *http.Request) { +func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -65,7 +65,7 @@ func (w WebServer) volume(w http.ResponseWriter, r *http.Request) { } } -func (w WebServer) skip(w http.ResponseWriter, r *http.Request) { +func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { var uname = token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -75,7 +75,7 @@ func (w WebServer) skip(w http.ResponseWriter, r *http.Request) { } } -func (w WebServer) GetWebAddress(user *gumble.User) { +func (web WebServer) GetWebAddress(user *gumble.User) { if client_token[user] != "" { token_client[client_token[user]] = nil } From 921af2f1b05a1f9466e09db329cd9f5b024b719d Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 13:58:31 +0100 Subject: [PATCH 15/67] Fixing build issues --- web.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/web.go b/web.go index 398cc02..c0619c8 100644 --- a/web.go +++ b/web.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "math/rand" "net/http" + "strconv" "strings" "time" @@ -27,27 +28,27 @@ var external_ip = "" func Webserver(port int) *WebServer { var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} - http.HandleFunc("/", webServer.homepage) + http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) http.HandleFunc("/volume", webserver.volume) http.HandleFunc("/skip", webserver.skip) - http.ListenAndServe(":"+port, nil) + http.ListenAndServe(":"+strconv.Itoa(port), nil) rand.Seed(time.Now().UnixNano()) return &webserver } func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { - var uname = token_client[r.URL.Path[1:]] + var uname = web.token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { t, _ := template.ParseFiles("index.html") - t.Execute(w, Page{"http://" + getIp() + ":" + w.port + "/", r.URL.Path[1:]}) + t.Execute(w, Page{"http://" + getIp() + ":" + web.port + "/", r.URL.Path[1:]}) } } func (web WebServer) add(w http.ResponseWriter, r *http.Request) { - var uname = token_client[r.FormValue("token")] + var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { @@ -56,7 +57,7 @@ func (web WebServer) add(w http.ResponseWriter, r *http.Request) { } func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { - var uname = token_client[r.FormValue("token")] + var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { @@ -66,7 +67,7 @@ func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { } func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { - var uname = token_client[r.FormValue("token")] + var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { @@ -76,17 +77,17 @@ func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { } func (web WebServer) GetWebAddress(user *gumble.User) { - if client_token[user] != "" { - token_client[client_token[user]] = nil + if web.client_token[user] != "" { + web.token_client[web.client_token[user]] = nil } // dealing with collisions var firstLoop = true - for firstLoop || token_client[client_token[user]] != nil { - client_token[user] = randSeq(10) + for firstLoop || web.token_client[web.client_token[user]] != nil { + web.client_token[user] = randSeq(10) firstLoop = false } - token_client[client_token[user]] = user - dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), client_token[user], getIP(), client_token[user])) + web.token_client[web.client_token[user]] = user + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), web.client_token[user], getIP(), web.client_token[user])) } // Gets the external ip address for the server From a4dd48007d0de9705c42ca3733f550c17c168cf1 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:01:55 +0100 Subject: [PATCH 16/67] Fixing build issues --- commands.go | 2 +- main.go | 4 +++- web.go | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/commands.go b/commands.go index d4dc02d..4be4eeb 100644 --- a/commands.go +++ b/commands.go @@ -85,7 +85,7 @@ func parseCommand(user *gumble.User, username, command string) { // Web command case dj.conf.Aliases.WebAlias: if dj.HasPermission(username, dj.conf.Permissions.AdminWeb) { - GetWebAddress(user) + web.GetWebAddress(user) } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } diff --git a/main.go b/main.go index 8a9d12a..abc1ca0 100644 --- a/main.go +++ b/main.go @@ -172,6 +172,8 @@ var dj = mumbledj{ cache: NewSongCache(), } +var web *Webserver + // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. func main() { @@ -242,7 +244,7 @@ func main() { os.Exit(1) } - Webserver(9563) + web = Webserver(9563) <-dj.keepAlive } diff --git a/web.go b/web.go index c0619c8..8b9fc23 100644 --- a/web.go +++ b/web.go @@ -3,6 +3,7 @@ package main import ( "fmt" "html" + "html/template" "io/ioutil" "math/rand" "net/http" @@ -43,7 +44,7 @@ func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { t, _ := template.ParseFiles("index.html") - t.Execute(w, Page{"http://" + getIp() + ":" + web.port + "/", r.URL.Path[1:]}) + t.Execute(w, Page{"http://" + getIP() + ":" + web.port + "/", r.URL.Path[1:]}) } } From 2550e43710ae1f3a8a0191881c53a98e98eb1ff7 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:03:22 +0100 Subject: [PATCH 17/67] Fixing build issues --- main.go | 2 +- web.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index abc1ca0..77d4251 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web *Webserver +var web *WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. diff --git a/web.go b/web.go index 8b9fc23..21a8377 100644 --- a/web.go +++ b/web.go @@ -44,7 +44,7 @@ func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { t, _ := template.ParseFiles("index.html") - t.Execute(w, Page{"http://" + getIP() + ":" + web.port + "/", r.URL.Path[1:]}) + t.Execute(w, Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) } } From 9ad1eda59f2d536ad08d0971a672a1b1e1cf3e48 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:05:52 +0100 Subject: [PATCH 18/67] Fixing build issues --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 77d4251..1a280a4 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web *WebServer +var web WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. From c4242a9efd84b5599dea412a19352c3be63c96e5 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:06:17 +0100 Subject: [PATCH 19/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 21a8377..6f8a3a7 100644 --- a/web.go +++ b/web.go @@ -27,7 +27,7 @@ type Page struct { var external_ip = "" -func Webserver(port int) *WebServer { +func Webserver(port int) WebServer { var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) From 03505fd44d1f201ea577e7b8a9dbd89c672f66b7 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:06:33 +0100 Subject: [PATCH 20/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 6f8a3a7..13883f9 100644 --- a/web.go +++ b/web.go @@ -35,7 +35,7 @@ func Webserver(port int) WebServer { http.HandleFunc("/skip", webserver.skip) http.ListenAndServe(":"+strconv.Itoa(port), nil) rand.Seed(time.Now().UnixNano()) - return &webserver + return webserver } func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { From 02f6cc49d7ecdee5353adc20f055e3f6122263a8 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:07:46 +0100 Subject: [PATCH 21/67] Fixing build issues --- web.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web.go b/web.go index 13883f9..95f9ba5 100644 --- a/web.go +++ b/web.go @@ -27,7 +27,7 @@ type Page struct { var external_ip = "" -func Webserver(port int) WebServer { +func Webserver(port int) *WebServer { var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) @@ -35,10 +35,10 @@ func Webserver(port int) WebServer { http.HandleFunc("/skip", webserver.skip) http.ListenAndServe(":"+strconv.Itoa(port), nil) rand.Seed(time.Now().UnixNano()) - return webserver + return &webserver } -func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -48,7 +48,7 @@ func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) add(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) add(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -57,7 +57,7 @@ func (web WebServer) add(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) volume(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -67,7 +67,7 @@ func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -77,7 +77,7 @@ func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) GetWebAddress(user *gumble.User) { +func (web *WebServer) GetWebAddress(user *gumble.User) { if web.client_token[user] != "" { web.token_client[web.client_token[user]] = nil } From 05eaf4dd3632d44b3759bc96dc2678b671bfc9aa Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:08:21 +0100 Subject: [PATCH 22/67] Fixing build issues --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1a280a4..77d4251 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web WebServer +var web *WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. From 2be5407aa479a537426b4ce706a4095a55ae160f Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:10:40 +0100 Subject: [PATCH 23/67] Fixing build issues --- main.go | 2 +- web.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 77d4251..0f87a45 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,7 @@ func main() { os.Exit(1) } - web = Webserver(9563) + web = &Webserver(9563) <-dj.keepAlive } diff --git a/web.go b/web.go index 95f9ba5..be4ce6e 100644 --- a/web.go +++ b/web.go @@ -27,7 +27,7 @@ type Page struct { var external_ip = "" -func Webserver(port int) *WebServer { +func Webserver(port int) WebServer { var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) @@ -35,7 +35,7 @@ func Webserver(port int) *WebServer { http.HandleFunc("/skip", webserver.skip) http.ListenAndServe(":"+strconv.Itoa(port), nil) rand.Seed(time.Now().UnixNano()) - return &webserver + return webserver } func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { From aee8e95ae1a9dcda5007172aed4bd08931c7a391 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:12:13 +0100 Subject: [PATCH 24/67] Fixing build issues --- main.go | 2 +- web.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 0f87a45..77d4251 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,7 @@ func main() { os.Exit(1) } - web = &Webserver(9563) + web = Webserver(9563) <-dj.keepAlive } diff --git a/web.go b/web.go index be4ce6e..1370628 100644 --- a/web.go +++ b/web.go @@ -27,15 +27,14 @@ type Page struct { var external_ip = "" -func Webserver(port int) WebServer { - var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} +func Webserver(port int) *WebServer { http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) http.HandleFunc("/volume", webserver.volume) http.HandleFunc("/skip", webserver.skip) http.ListenAndServe(":"+strconv.Itoa(port), nil) rand.Seed(time.Now().UnixNano()) - return webserver + return &WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} } func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { From 4678298ae9bdb5e5d891794610cb12580659232d Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:12:43 +0100 Subject: [PATCH 25/67] Fixing build issues --- web.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index 1370628..026ae17 100644 --- a/web.go +++ b/web.go @@ -28,13 +28,14 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { + var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) http.HandleFunc("/volume", webserver.volume) http.HandleFunc("/skip", webserver.skip) http.ListenAndServe(":"+strconv.Itoa(port), nil) rand.Seed(time.Now().UnixNano()) - return &WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} + return webserver } func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { From a246196786d2042d66380011530abb382aa24744 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:17:01 +0100 Subject: [PATCH 26/67] Fixing build issues --- web.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/web.go b/web.go index 026ae17..56a302e 100644 --- a/web.go +++ b/web.go @@ -28,14 +28,17 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { - var webserver = WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} - http.HandleFunc("/", webserver.homepage) - http.HandleFunc("/add", webserver.add) - http.HandleFunc("/volume", webserver.volume) - http.HandleFunc("/skip", webserver.skip) - http.ListenAndServe(":"+strconv.Itoa(port), nil) + return WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)}.construct() +} + +func (web *WebServer) construct() *WebServer { + http.HandleFunc("/", web.homepage) + http.HandleFunc("/add", web.add) + http.HandleFunc("/volume", web.volume) + http.HandleFunc("/skip", web.skip) + http.ListenAndServe(":"+strconv.Itoa(web.port), nil) rand.Seed(time.Now().UnixNano()) - return webserver + return web } func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { From 2fcdb0fc97e2981ca81279598b0a50c9d1df419c Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:17:37 +0100 Subject: [PATCH 27/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 56a302e..9766c3c 100644 --- a/web.go +++ b/web.go @@ -28,7 +28,7 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { - return WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)}.construct() + return &WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)}.construct() } func (web *WebServer) construct() *WebServer { From 5e1bae3c4cac8aeac8c0b8b4311b760031fe4f00 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:21:13 +0100 Subject: [PATCH 28/67] Fixing build issues --- web.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/web.go b/web.go index 9766c3c..48e3e53 100644 --- a/web.go +++ b/web.go @@ -28,17 +28,20 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { - return &WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)}.construct() -} + webserver := new(WebServer) + + webserver.port = port + webserver.client_token = make(map[*gumble.User]string) + webserver.token_client = make(map[string]*gumble.User) + + http.HandleFunc("/", webserver.homepage) + http.HandleFunc("/add", webserver.add) + http.HandleFunc("/volume", webserver.volume) + http.HandleFunc("/skip", webserver.skip) + http.ListenAndServe(":"+strconv.Itoa(port), nil) -func (web *WebServer) construct() *WebServer { - http.HandleFunc("/", web.homepage) - http.HandleFunc("/add", web.add) - http.HandleFunc("/volume", web.volume) - http.HandleFunc("/skip", web.skip) - http.ListenAndServe(":"+strconv.Itoa(web.port), nil) rand.Seed(time.Now().UnixNano()) - return web + return webserver } func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { From 78cb63106cc8da0ad75c873e00e865d7a490d932 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:27:55 +0100 Subject: [PATCH 29/67] Fixing build issues --- web.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/web.go b/web.go index 48e3e53..2ef2930 100644 --- a/web.go +++ b/web.go @@ -83,18 +83,18 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } } -func (web *WebServer) GetWebAddress(user *gumble.User) { - if web.client_token[user] != "" { - web.token_client[web.client_token[user]] = nil +func (website *websiteServer) GetwebsiteAddress(user *gumble.User) { + if website.client_token[user] != "" { + website.token_client[website.client_token[user]] = nil } // dealing with collisions var firstLoop = true - for firstLoop || web.token_client[web.client_token[user]] != nil { - web.client_token[user] = randSeq(10) + for firstLoop || website.token_client[website.client_token[user]] != nil { + website.client_token[user] = randSeq(10) firstLoop = false } - web.token_client[web.client_token[user]] = user - dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), web.client_token[user], getIP(), web.client_token[user])) + website.token_client[website.client_token[user]] = user + dj.SendPrivateMessage(user, fmt.Sprintf(website_ADDRESS, getIP(), website.client_token[user], getIP(), website.client_token[user])) } // Gets the external ip address for the server From a37dbe128325b7e6b0faf64046963d98caeb6eb2 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:28:39 +0100 Subject: [PATCH 30/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 2ef2930..4e7ce2d 100644 --- a/web.go +++ b/web.go @@ -83,7 +83,7 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } } -func (website *websiteServer) GetwebsiteAddress(user *gumble.User) { +func (website *WebServer) GetWebAddress(user *gumble.User) { if website.client_token[user] != "" { website.token_client[website.client_token[user]] = nil } From ac6979a9d895afce8b0880b2ad7aacad660e977b Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:29:06 +0100 Subject: [PATCH 31/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 4e7ce2d..12f839e 100644 --- a/web.go +++ b/web.go @@ -94,7 +94,7 @@ func (website *WebServer) GetWebAddress(user *gumble.User) { firstLoop = false } website.token_client[website.client_token[user]] = user - dj.SendPrivateMessage(user, fmt.Sprintf(website_ADDRESS, getIP(), website.client_token[user], getIP(), website.client_token[user])) + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), website.client_token[user], getIP(), website.client_token[user])) } // Gets the external ip address for the server From d9617a86c77fe400fdadc08f504d2fede0ded1e6 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:31:10 +0100 Subject: [PATCH 32/67] Fixing build issues --- web.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web.go b/web.go index 12f839e..851c440 100644 --- a/web.go +++ b/web.go @@ -84,6 +84,12 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } func (website *WebServer) GetWebAddress(user *gumble.User) { + if website == nil { + Verbose("WEBSITE NOT INITIALISED") + } + if website.client_token == nil { + Verbose("CLIENT_TOKEN NOT INITIALISED") + } if website.client_token[user] != "" { website.token_client[website.client_token[user]] = nil } From ebf5fa0a014d057f0f0c9b543133e87b84f89fd0 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:32:43 +0100 Subject: [PATCH 33/67] Fixing build issues --- web.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web.go b/web.go index 851c440..3218c5e 100644 --- a/web.go +++ b/web.go @@ -84,6 +84,8 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } func (website *WebServer) GetWebAddress(user *gumble.User) { + // A random comment + Verbose("Not fun") if website == nil { Verbose("WEBSITE NOT INITIALISED") } From 1b7167335e4f106fbd82d1306d313c4f33e41183 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:40:39 +0100 Subject: [PATCH 34/67] Fixing build issues --- main.go | 2 +- web.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 77d4251..27a94d0 100644 --- a/main.go +++ b/main.go @@ -144,7 +144,7 @@ func PerformStartupChecks() { func Verbose(msg string) { if dj.verbose { - fmt.Printf(msg) + fmt.Printf(msg + "\n") } } diff --git a/web.go b/web.go index 3218c5e..e951c39 100644 --- a/web.go +++ b/web.go @@ -28,7 +28,7 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { - webserver := new(WebServer) + webserver := new(WebServer{}) webserver.port = port webserver.client_token = make(map[*gumble.User]string) From e2541f119256e5594f66d3711f7246a54b86a7ae Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:42:28 +0100 Subject: [PATCH 35/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index e951c39..f0d39e6 100644 --- a/web.go +++ b/web.go @@ -28,7 +28,7 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { - webserver := new(WebServer{}) + webserver := WebServer{} webserver.port = port webserver.client_token = make(map[*gumble.User]string) From 759ea0f3b9473ccdc567eefdc4879d3a305854f1 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:47:34 +0100 Subject: [PATCH 36/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index f0d39e6..37a897c 100644 --- a/web.go +++ b/web.go @@ -28,7 +28,7 @@ type Page struct { var external_ip = "" func Webserver(port int) *WebServer { - webserver := WebServer{} + webserver := &WebServer{} webserver.port = port webserver.client_token = make(map[*gumble.User]string) From 7da0a68f5103845f8e58e18db58c6f73c2e8ea1a Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:52:33 +0100 Subject: [PATCH 37/67] Fixing build issues --- main.go | 2 +- web.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 27a94d0..629fd3c 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web *WebServer +var web WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. diff --git a/web.go b/web.go index 37a897c..cbcc8fb 100644 --- a/web.go +++ b/web.go @@ -27,8 +27,8 @@ type Page struct { var external_ip = "" -func Webserver(port int) *WebServer { - webserver := &WebServer{} +func makeWebserver(port int) WebServer { + webserver := WebServer{} webserver.port = port webserver.client_token = make(map[*gumble.User]string) From 7f913c06e49341cb033e3130cfea12cf60f70014 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:53:37 +0100 Subject: [PATCH 38/67] Fixing build issues --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 629fd3c..66cd711 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,7 @@ func main() { os.Exit(1) } - web = Webserver(9563) + web = WebServer(9563) <-dj.keepAlive } From f26f8e9ec59e74153bf996d1b37878dbc0f8250f Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:54:34 +0100 Subject: [PATCH 39/67] Fixing build issues --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 66cd711..4849776 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,7 @@ func main() { os.Exit(1) } - web = WebServer(9563) + web = makeWebserver(9563) <-dj.keepAlive } From 2e09ec1b91105e547b94cf6ebab60fe771ebe594 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 14:56:47 +0100 Subject: [PATCH 40/67] Fixing build issues --- web.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/web.go b/web.go index cbcc8fb..a8e1dac 100644 --- a/web.go +++ b/web.go @@ -28,11 +28,7 @@ type Page struct { var external_ip = "" func makeWebserver(port int) WebServer { - webserver := WebServer{} - - webserver.port = port - webserver.client_token = make(map[*gumble.User]string) - webserver.token_client = make(map[string]*gumble.User) + webserver := WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) From 3732c0e9dd6c053f33532bdaacd4c79a4db576db Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:04:58 +0100 Subject: [PATCH 41/67] Fixing build issues --- web.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/web.go b/web.go index a8e1dac..6f88810 100644 --- a/web.go +++ b/web.go @@ -80,14 +80,6 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } func (website *WebServer) GetWebAddress(user *gumble.User) { - // A random comment - Verbose("Not fun") - if website == nil { - Verbose("WEBSITE NOT INITIALISED") - } - if website.client_token == nil { - Verbose("CLIENT_TOKEN NOT INITIALISED") - } if website.client_token[user] != "" { website.token_client[website.client_token[user]] = nil } From 6d040db236b243bda1b502bdf146bb7bf7360bdf Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:07:40 +0100 Subject: [PATCH 42/67] Fixing build issues --- web.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web.go b/web.go index 6f88810..cd192db 100644 --- a/web.go +++ b/web.go @@ -80,17 +80,17 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } func (website *WebServer) GetWebAddress(user *gumble.User) { - if website.client_token[user] != "" { - website.token_client[website.client_token[user]] = nil + if web.client_token[user] != "" { + web.token_client[web.client_token[user]] = nil } // dealing with collisions var firstLoop = true - for firstLoop || website.token_client[website.client_token[user]] != nil { - website.client_token[user] = randSeq(10) + for firstLoop || web.token_client[web.client_token[user]] != nil { + web.client_token[user] = randSeq(10) firstLoop = false } - website.token_client[website.client_token[user]] = user - dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), website.client_token[user], getIP(), website.client_token[user])) + web.token_client[web.client_token[user]] = user + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), web.client_token[user], getIP(), web.client_token[user])) } // Gets the external ip address for the server From 31644719feb1ea0aee5b68f8c13df75b4014b4c0 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:10:43 +0100 Subject: [PATCH 43/67] Fixing build issues --- main.go | 2 +- web.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4849776..16cdbc7 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web WebServer +var web *WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. diff --git a/web.go b/web.go index cd192db..ba151eb 100644 --- a/web.go +++ b/web.go @@ -27,8 +27,8 @@ type Page struct { var external_ip = "" -func makeWebserver(port int) WebServer { - webserver := WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} +func makeWebserver(port int) *WebServer { + webserver := &WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) From cf0a8b28f94a24b20977aa5f6df80b94d1f307a9 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:12:00 +0100 Subject: [PATCH 44/67] Fixing build issues --- web.go | 1 + 1 file changed, 1 insertion(+) diff --git a/web.go b/web.go index ba151eb..4da4906 100644 --- a/web.go +++ b/web.go @@ -80,6 +80,7 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } func (website *WebServer) GetWebAddress(user *gumble.User) { + Verbose("Port number: " + strconv.Itoa(web.port)) if web.client_token[user] != "" { web.token_client[web.client_token[user]] = nil } From 4350d54c3b89d5608b23aa8c0d0a9f78b321f19f Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:13:17 +0100 Subject: [PATCH 45/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 4da4906..c0cc4c1 100644 --- a/web.go +++ b/web.go @@ -79,7 +79,7 @@ func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { } } -func (website *WebServer) GetWebAddress(user *gumble.User) { +func (website WebServer) GetWebAddress(user *gumble.User) { Verbose("Port number: " + strconv.Itoa(web.port)) if web.client_token[user] != "" { web.token_client[web.client_token[user]] = nil From d1105b75569ccfa4f321f445a9d25a0b47e6a5a0 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:14:30 +0100 Subject: [PATCH 46/67] Fixing build issues --- main.go | 2 +- web.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 16cdbc7..4849776 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web *WebServer +var web WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. diff --git a/web.go b/web.go index c0cc4c1..4bb9c19 100644 --- a/web.go +++ b/web.go @@ -27,8 +27,8 @@ type Page struct { var external_ip = "" -func makeWebserver(port int) *WebServer { - webserver := &WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} +func makeWebserver(port int) WebServer { + webserver := WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) @@ -40,7 +40,7 @@ func makeWebserver(port int) *WebServer { return webserver } -func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { +func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -50,7 +50,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { } } -func (web *WebServer) add(w http.ResponseWriter, r *http.Request) { +func (web WebServer) add(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -59,7 +59,7 @@ func (web *WebServer) add(w http.ResponseWriter, r *http.Request) { } } -func (web *WebServer) volume(w http.ResponseWriter, r *http.Request) { +func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -69,7 +69,7 @@ func (web *WebServer) volume(w http.ResponseWriter, r *http.Request) { } } -func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { +func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") From 8013ffea116faf452ac4ae71595da53369220a0c Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:17:04 +0100 Subject: [PATCH 47/67] Fixing build issues --- web.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index 4bb9c19..b13bcf4 100644 --- a/web.go +++ b/web.go @@ -28,7 +28,11 @@ type Page struct { var external_ip = "" func makeWebserver(port int) WebServer { - webserver := WebServer{port, make(map[*gumble.User]string), make(map[string]*gumble.User)} + webserver := WebServer{} + + webserver.port = port + webserver.client_token = make(map[*gumble.User]string) + webserver.token_client = make(map[string]*gumble.User) http.HandleFunc("/", webserver.homepage) http.HandleFunc("/add", webserver.add) From dcb85e1892dc6704480d6b0e746463e12bff4bc3 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:23:05 +0100 Subject: [PATCH 48/67] Fixing build issues --- main.go | 2 +- web.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 4849776..16cdbc7 100644 --- a/main.go +++ b/main.go @@ -172,7 +172,7 @@ var dj = mumbledj{ cache: NewSongCache(), } -var web WebServer +var web *WebServer // main primarily performs startup tasks. Grabs and parses commandline // args, sets up the gumble client and its listeners, and then connects to the server. diff --git a/web.go b/web.go index b13bcf4..25a7a9a 100644 --- a/web.go +++ b/web.go @@ -27,8 +27,8 @@ type Page struct { var external_ip = "" -func makeWebserver(port int) WebServer { - webserver := WebServer{} +func makeWebserver(port int) *WebServer { + webserver := &WebServer{} webserver.port = port webserver.client_token = make(map[*gumble.User]string) From 9d6ff1ad784bec0cdab45de16ee1e4e4fdd26c2b Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:24:30 +0100 Subject: [PATCH 49/67] Fixing build issues --- main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.go b/main.go index 16cdbc7..56f1066 100644 --- a/main.go +++ b/main.go @@ -246,5 +246,9 @@ func main() { web = makeWebserver(9563) + if isNil(web) { + Verbose("WEB IS NIL") + } + <-dj.keepAlive } From a55ce8a3e0d8e16c74807e89e128dd64dcc52700 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:28:41 +0100 Subject: [PATCH 50/67] Fixing build issues --- web.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/web.go b/web.go index 25a7a9a..e521602 100644 --- a/web.go +++ b/web.go @@ -44,7 +44,7 @@ func makeWebserver(port int) *WebServer { return webserver } -func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.URL.Path[1:]] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -54,7 +54,7 @@ func (web WebServer) homepage(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) add(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) add(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -63,7 +63,7 @@ func (web WebServer) add(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) volume(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -73,7 +73,7 @@ func (web WebServer) volume(w http.ResponseWriter, r *http.Request) { } } -func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { +func (web *WebServer) skip(w http.ResponseWriter, r *http.Request) { var uname = web.token_client[r.FormValue("token")] if uname == nil { fmt.Fprintf(w, "Invalid Token") @@ -83,7 +83,7 @@ func (web WebServer) skip(w http.ResponseWriter, r *http.Request) { } } -func (website WebServer) GetWebAddress(user *gumble.User) { +func (website *WebServer) GetWebAddress(user *gumble.User) { Verbose("Port number: " + strconv.Itoa(web.port)) if web.client_token[user] != "" { web.token_client[web.client_token[user]] = nil From f15ff8755a917848d8c2dcb3125c92b4ecc929ef Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:34:40 +0100 Subject: [PATCH 51/67] Fixing build issues --- main.go | 3 ++- web.go | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 56f1066..ba85c0c 100644 --- a/main.go +++ b/main.go @@ -244,7 +244,8 @@ func main() { os.Exit(1) } - web = makeWebserver(9563) + web = NewWebServer(9563) + web.makeWeb() if isNil(web) { Verbose("WEB IS NIL") diff --git a/web.go b/web.go index e521602..7fd4bc1 100644 --- a/web.go +++ b/web.go @@ -27,21 +27,21 @@ type Page struct { var external_ip = "" -func makeWebserver(port int) *WebServer { - webserver := &WebServer{} - - webserver.port = port - webserver.client_token = make(map[*gumble.User]string) - webserver.token_client = make(map[string]*gumble.User) - - http.HandleFunc("/", webserver.homepage) - http.HandleFunc("/add", webserver.add) - http.HandleFunc("/volume", webserver.volume) - http.HandleFunc("/skip", webserver.skip) - http.ListenAndServe(":"+strconv.Itoa(port), nil) +func NewWebServer(port int) *WebServer { + return &WebServer{ + port: port, + client_token: make(map[*gumble.User]string), + token_client: make(map[string]*gumble.User), + } +} +func (web *WebServer) makeWeb() { + http.HandleFunc("/", web.homepage) + http.HandleFunc("/add", web.add) + http.HandleFunc("/volume", web.volume) + http.HandleFunc("/skip", web.skip) + http.ListenAndServe(":"+strconv.Itoa(web.port), nil) rand.Seed(time.Now().UnixNano()) - return webserver } func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { From 15ce071ef6b96b87871a475c90ba67fdef27a6b5 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:47:05 +0100 Subject: [PATCH 52/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 7fd4bc1..2e630fd 100644 --- a/web.go +++ b/web.go @@ -50,7 +50,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { t, _ := template.ParseFiles("index.html") - t.Execute(w, Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) + t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) } } From bc3193009feb75cb1cd773821ed77b4025ef446d Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:52:10 +0100 Subject: [PATCH 53/67] Fixing build issues --- web.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web.go b/web.go index 2e630fd..805b71e 100644 --- a/web.go +++ b/web.go @@ -49,8 +49,16 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - t, _ := template.ParseFiles("index.html") - t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) + t, err := template.ParseFiles("index.html") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } } } From fcee078c0b2c38a52957b707a75a1d081fb81d36 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 15:54:46 +0100 Subject: [PATCH 54/67] Fixing build issues --- Makefile | 1 + web.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 36b484b..565b52e 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ install: mkdir -p ~/.mumbledj/web if [ -a ~/.mumbledj/config/mumbledj.gcfg ]; then mv ~/.mumbledj/config/mumbledj.gcfg ~/.mumbledj/config/mumbledj_backup.gcfg; fi; cp -u config.gcfg ~/.mumbledj/config/mumbledj.gcfg + cp -u index.html ~/.mumbledj/web/index.html if [ -d ~/bin ]; then cp -f mumbledj* ~/bin/mumbledj; else sudo cp -f mumbledj* /usr/local/bin/mumbledj; fi; build: diff --git a/web.go b/web.go index 805b71e..8dd02f2 100644 --- a/web.go +++ b/web.go @@ -49,12 +49,12 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - t, err := template.ParseFiles("index.html") + t, err := template.ParseFiles("~/.mumbledj/web/index.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - + err = t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) From 619d9100c394f235550fc6bfad78a982fc5062a3 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:07:59 +0100 Subject: [PATCH 55/67] Fixing build issues --- cache.go | 2 +- commands.go | 2 +- main.go | 2 +- parseconfig.go | 2 +- service.go | 2 +- service_youtube.go | 2 +- songqueue.go | 2 +- strings.go | 2 +- web.go | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cache.go b/cache.go index 0adda0e..9f56af3 100644 --- a/cache.go +++ b/cache.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "errors" diff --git a/commands.go b/commands.go index 4be4eeb..5f0e02c 100644 --- a/commands.go +++ b/commands.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "errors" diff --git a/main.go b/main.go index ba85c0c..840aba9 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "crypto/tls" diff --git a/parseconfig.go b/parseconfig.go index 4b4a16a..f567c4c 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "errors" diff --git a/service.go b/service.go index 13a1d08..39f7b0c 100644 --- a/service.go +++ b/service.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "errors" diff --git a/service_youtube.go b/service_youtube.go index 63a343d..aa7ec1f 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "encoding/json" diff --git a/songqueue.go b/songqueue.go index f1bdc1c..0a6bb31 100644 --- a/songqueue.go +++ b/songqueue.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj import ( "errors" diff --git a/strings.go b/strings.go index 9d5524f..03a7e3c 100644 --- a/strings.go +++ b/strings.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package main +package mumbledj // Message shown to users when the bot has an invalid YouTube API key. const INVALID_API_KEY = "MumbleDJ does not have a valid YouTube API key." diff --git a/web.go b/web.go index 8dd02f2..bdbf3bd 100644 --- a/web.go +++ b/web.go @@ -1,4 +1,4 @@ -package main +package mumbledj import ( "fmt" @@ -49,7 +49,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - t, err := template.ParseFiles("~/.mumbledj/web/index.html") + t, err := template.ParseFiles("mumbledj/index.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return From 6f9e4a9c76da26454ce90e9f00e61fd97d76316a Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:12:16 +0100 Subject: [PATCH 56/67] Fixing build issues --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 565b52e..2f0b5c3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: mumbledj -mumbledj: main.go commands.go parseconfig.go strings.go service.go service_youtube.go songqueue.go cache.go +mumbledj: main.go commands.go parseconfig.go strings.go service.go service_youtube.go songqueue.go cache.go web.go go get github.com/nitrous-io/goop rm -rf Goopfile.lock goop install From 14c38799e304cfa05233467b32f8c904c9fb455c Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:28:01 +0100 Subject: [PATCH 57/67] Fixing build issues --- cache.go | 2 +- commands.go | 2 +- main.go | 2 +- parseconfig.go | 2 +- service.go | 2 +- service_youtube.go | 2 +- songqueue.go | 2 +- strings.go | 2 +- web.go | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cache.go b/cache.go index 9f56af3..0adda0e 100644 --- a/cache.go +++ b/cache.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "errors" diff --git a/commands.go b/commands.go index 5f0e02c..4be4eeb 100644 --- a/commands.go +++ b/commands.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "errors" diff --git a/main.go b/main.go index 840aba9..ba85c0c 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "crypto/tls" diff --git a/parseconfig.go b/parseconfig.go index f567c4c..4b4a16a 100644 --- a/parseconfig.go +++ b/parseconfig.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "errors" diff --git a/service.go b/service.go index 39f7b0c..13a1d08 100644 --- a/service.go +++ b/service.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "errors" diff --git a/service_youtube.go b/service_youtube.go index aa7ec1f..63a343d 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "encoding/json" diff --git a/songqueue.go b/songqueue.go index 0a6bb31..f1bdc1c 100644 --- a/songqueue.go +++ b/songqueue.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main import ( "errors" diff --git a/strings.go b/strings.go index 03a7e3c..9d5524f 100644 --- a/strings.go +++ b/strings.go @@ -5,7 +5,7 @@ * Copyright (c) 2014, 2015 Matthieu Grieger (MIT License) */ -package mumbledj +package main // Message shown to users when the bot has an invalid YouTube API key. const INVALID_API_KEY = "MumbleDJ does not have a valid YouTube API key." diff --git a/web.go b/web.go index bdbf3bd..bebb94b 100644 --- a/web.go +++ b/web.go @@ -1,4 +1,4 @@ -package mumbledj +package main import ( "fmt" From 5d18bd68d8e20ae9e57ffd2013de12966af8ef72 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:30:32 +0100 Subject: [PATCH 58/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index bebb94b..90104c2 100644 --- a/web.go +++ b/web.go @@ -49,7 +49,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - t, err := template.ParseFiles("mumbledj/index.html") + t, err := template.ParseFiles("./index.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return From 2606fc4cb904db0c24260b7a8b470d90fe56170d Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:32:56 +0100 Subject: [PATCH 59/67] Fixing build issues --- web.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index 90104c2..95334fc 100644 --- a/web.go +++ b/web.go @@ -7,6 +7,8 @@ import ( "io/ioutil" "math/rand" "net/http" + "os" + "path/filepath" "strconv" "strings" "time" @@ -49,7 +51,8 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { if uname == nil { fmt.Fprintf(w, "Invalid Token") } else { - t, err := template.ParseFiles("./index.html") + cwd, _ := os.Getwd() + t, err := template.ParseFiles(filepath.Join(cwd, "./index.html")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return From e1ccad13581e708a666cadb714198da4fdbd8e96 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:35:03 +0100 Subject: [PATCH 60/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index 95334fc..a7f8a36 100644 --- a/web.go +++ b/web.go @@ -52,7 +52,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Invalid Token") } else { cwd, _ := os.Getwd() - t, err := template.ParseFiles(filepath.Join(cwd, "./index.html")) + t, err := template.ParseFiles(filepath.Join(cwd, "./.mumbledj/web/index.html")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return From 2107462d5bdc6ea23fee8e8122994c545b823e98 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:36:37 +0100 Subject: [PATCH 61/67] Fixing build issues --- web.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web.go b/web.go index a7f8a36..c3c67db 100644 --- a/web.go +++ b/web.go @@ -25,6 +25,7 @@ type WebServer struct { type Page struct { siteUrl string token string + user string } var external_ip = "" @@ -58,7 +59,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { return } - err = t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:]}) + err = t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:], uname}) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } From b7aa5dafbed0d03e7822a8811aaf491fd7a3491e Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:37:19 +0100 Subject: [PATCH 62/67] Fixing build issues --- web.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web.go b/web.go index c3c67db..35a8bb7 100644 --- a/web.go +++ b/web.go @@ -59,7 +59,7 @@ func (web *WebServer) homepage(w http.ResponseWriter, r *http.Request) { return } - err = t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:], uname}) + err = t.Execute(w, &Page{"http://" + getIP() + ":" + strconv.Itoa(web.port) + "/", r.URL.Path[1:], uname.Name}) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } From 9cd9c0ad605eb9173278ab20ad6659bdb8dd3bfd Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Thu, 30 Jul 2015 17:39:04 +0100 Subject: [PATCH 63/67] Fixing build issues --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 5659235..ea3806a 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - {{user}} - mumbledj + {{.user}} - mumbledj