Fixing build issues

This commit is contained in:
MichaelOultram 2015-07-28 16:31:37 +01:00
parent 232ea53ece
commit 9e7975be7d
3 changed files with 32 additions and 9 deletions

View file

@ -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) {

View file

@ -170,3 +170,8 @@ const CURRENT_SONG_HTML = `
const CURRENT_SONG_PLAYLIST_HTML = `
The song currently playing is "%s", added <b>%s</b> from the playlist "%s".
`
// URL of the server for connecting via a web address
const WEB_ADDRESS = `
Control mumbledj from a web browser: <a href="http://%s/%s">http://%s/%s</a>.
`

28
web.go
View file

@ -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
}
}