diff --git a/main.go b/main.go
index 1623f22..ab48d39 100644
--- a/main.go
+++ b/main.go
@@ -530,6 +530,24 @@ func onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
// Find the collection for the command we got
+ findAndPlaySound(s, m, parts, guild)
+}
+
+func findSoundAndCollection(command string, soundname string) (*Sound, *SoundCollection) {
+ for _, c := range COLLECTIONS {
+ if scontains(command, c.Commands...) {
+ for _, s := range c.Sounds {
+ if soundname == s.Name {
+ return s, c
+ }
+ }
+ }
+ }
+ return nil, nil
+}
+
+// Find sound in collection and play it or do nothing if not found
+func findAndPlaySound(s *discordgo.Session, m *discordgo.MessageCreate, parts []string, g *discordgo.Guild) {
for _, coll := range COLLECTIONS {
if scontains(parts[0], coll.Commands...) {
go deleteCommandMessage(s, m.ChannelID, m.ID)
@@ -548,7 +566,7 @@ func onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
}
}
- go enqueuePlay(m.Author, guild, coll, sound)
+ go enqueuePlay(m.Author, g, coll, sound)
return
}
}
diff --git a/templates/internal.html b/templates/internal.html
index fff2431..9b31fa7 100644
--- a/templates/internal.html
+++ b/templates/internal.html
@@ -1,3 +1,12 @@
-{{ define "content" }}
-Logout
-{{ end }}
+{{ define "content" }}
+
+Logout
+Play sound {{ end }}
diff --git a/webserver.go b/webserver.go
index 746f55f..15236b7 100644
--- a/webserver.go
+++ b/webserver.go
@@ -51,12 +51,31 @@ func startWebServer(port string, ci string, cs string, redirectURL string) {
r.HandleFunc("/logout", handleLogout)
r.HandleFunc("/discordLogin", handlediscordLogin)
r.HandleFunc("/discordCallback", handlediscordCallback)
+ r.HandleFunc("/playsound", handlePlaySound)
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.Handle("/", r)
http.ListenAndServe(":"+port, nil)
}
+func handlePlaySound(w http.ResponseWriter, r *http.Request) {
+ r.ParseForm()
+ sound, soundCollection := findSoundAndCollection(r.FormValue("command"), r.FormValue("soundname"))
+ session, _ := store.Get(r, "session-name")
+ var guild *discordgo.Guild
+ user, _ := discord.User(session.Values["discordUserID"].(string))
+ for _, g := range discord.State.Guilds {
+ for _, vs := range g.VoiceStates {
+ if vs.UserID == session.Values["discordUserID"].(string) {
+ guild = g
+ }
+ }
+ }
+ if user != nil && guild != nil && sound != nil && soundCollection != nil {
+ enqueuePlay(user, guild, soundCollection, sound)
+ }
+}
+
func handleMain(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session-name")
if session.Values["discordUsername"] != nil {