From 9e7975be7db1bf2061e880baa29cafcc79adff44 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 16:31:37 +0100 Subject: [PATCH] Fixing build issues --- commands.go | 8 +------- strings.go | 5 +++++ web.go | 28 ++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/commands.go b/commands.go index 0feed01..61c83fb 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) { - web(user) + GetWebAddress(user) } else { dj.SendPrivateMessage(user, NO_PERMISSION_MSG) } @@ -298,12 +298,6 @@ func volume(user *gumble.User, username, value string) { } } -// web performs !web functionality. Gives user URL to web interface -func web(user *gumble.User) { - Verbose("Sending user web address") - dj.SendPrivateMessage(user, "http://178.62.73.59:9563/"+user.Name) -} - // move performs !move functionality. Determines if the supplied channel is valid and moves the bot // to the channel if it is. func move(user *gumble.User, channel string) { diff --git a/strings.go b/strings.go index d48e7a7..92f577b 100644 --- a/strings.go +++ b/strings.go @@ -170,3 +170,8 @@ const CURRENT_SONG_HTML = ` const CURRENT_SONG_PLAYLIST_HTML = ` The song currently playing is "%s", added %s from the playlist "%s". ` + +// URL of the server for connecting via a web address +const WEB_ADDRESS = ` + Control mumbledj from a web browser: http://%s/%s. +` \ No newline at end of file diff --git a/web.go b/web.go index 9a61cf5..0986856 100644 --- a/web.go +++ b/web.go @@ -6,6 +6,9 @@ import ( "net/http" ) +var client_token = new(map[string]string) +var external_ip = "" + type Page struct { Title string Body []byte @@ -26,10 +29,31 @@ func loadPage(title string) (*Page, error) { } func handler(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) + fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) } -func Webserver(){ +func Webserver() { http.HandleFunc("/", handler) http.ListenAndServe(":9563", nil) } + +func GetWebAddress(user *gumble.User) { + dj.SendPrivateMessage(user, fmt.Sprintf(WEB_ADDRESS, getIP(), user.Name, getIP(), user.Name)) +} + +func getIP() string { + if external_ip != "" { + return external_ip + } else { + if response, err := http.Get("http://myexternalip.com/raw"); err == nil { + defer response.Body.Close() + if response.StatusCode == 200 { + if body, err := ioutil.ReadAll(response.Body); err == nil { + external_ip = string(body) + } + } + } + + return external_ip + } +}