diff --git a/.gitignore b/.gitignore index 07ab8fc..59bb9b6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ dist node_modules yarn-error* vendor +bot +sounds diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..34051bd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "go", + "request": "launch", + "mode": "debug", + "remotePath": "", + "port": 2345, + "host": "127.0.0.1", + "program": "${workspaceRoot}", + "env": {}, + "args": [], + "showLog": true + } + ] +} diff --git a/.babelrc b/client/.babelrc similarity index 100% rename from .babelrc rename to client/.babelrc diff --git a/.eslintrc.js b/client/.eslintrc.js similarity index 100% rename from .eslintrc.js rename to client/.eslintrc.js diff --git a/.jsbeautifyrc b/client/.jsbeautifyrc similarity index 100% rename from .jsbeautifyrc rename to client/.jsbeautifyrc diff --git a/app/Wrapper.js b/client/app/Wrapper.js similarity index 100% rename from app/Wrapper.js rename to client/app/Wrapper.js diff --git a/app/app.js b/client/app/app.js similarity index 100% rename from app/app.js rename to client/app/app.js diff --git a/app/assets/font-awesome/css/font-awesome.css b/client/app/assets/font-awesome/css/font-awesome.css similarity index 100% rename from app/assets/font-awesome/css/font-awesome.css rename to client/app/assets/font-awesome/css/font-awesome.css diff --git a/app/assets/font-awesome/fonts/FontAwesome.otf b/client/app/assets/font-awesome/fonts/FontAwesome.otf similarity index 100% rename from app/assets/font-awesome/fonts/FontAwesome.otf rename to client/app/assets/font-awesome/fonts/FontAwesome.otf diff --git a/app/assets/font-awesome/fonts/fontawesome-webfont.eot b/client/app/assets/font-awesome/fonts/fontawesome-webfont.eot similarity index 100% rename from app/assets/font-awesome/fonts/fontawesome-webfont.eot rename to client/app/assets/font-awesome/fonts/fontawesome-webfont.eot diff --git a/app/assets/font-awesome/fonts/fontawesome-webfont.svg b/client/app/assets/font-awesome/fonts/fontawesome-webfont.svg similarity index 100% rename from app/assets/font-awesome/fonts/fontawesome-webfont.svg rename to client/app/assets/font-awesome/fonts/fontawesome-webfont.svg diff --git a/app/assets/font-awesome/fonts/fontawesome-webfont.ttf b/client/app/assets/font-awesome/fonts/fontawesome-webfont.ttf similarity index 100% rename from app/assets/font-awesome/fonts/fontawesome-webfont.ttf rename to client/app/assets/font-awesome/fonts/fontawesome-webfont.ttf diff --git a/app/assets/font-awesome/fonts/fontawesome-webfont.woff b/client/app/assets/font-awesome/fonts/fontawesome-webfont.woff similarity index 100% rename from app/assets/font-awesome/fonts/fontawesome-webfont.woff rename to client/app/assets/font-awesome/fonts/fontawesome-webfont.woff diff --git a/app/assets/font-awesome/fonts/fontawesome-webfont.woff2 b/client/app/assets/font-awesome/fonts/fontawesome-webfont.woff2 similarity index 100% rename from app/assets/font-awesome/fonts/fontawesome-webfont.woff2 rename to client/app/assets/font-awesome/fonts/fontawesome-webfont.woff2 diff --git a/app/assets/normalize.css b/client/app/assets/normalize.css similarity index 100% rename from app/assets/normalize.css rename to client/app/assets/normalize.css diff --git a/app/components/Navbar/Navbar.component.js b/client/app/components/Navbar/Navbar.component.js similarity index 100% rename from app/components/Navbar/Navbar.component.js rename to client/app/components/Navbar/Navbar.component.js diff --git a/app/components/Navbar/Navbar.scss b/client/app/components/Navbar/Navbar.scss similarity index 100% rename from app/components/Navbar/Navbar.scss rename to client/app/components/Navbar/Navbar.scss diff --git a/app/pages/Home/Home.js b/client/app/pages/Home/Home.js similarity index 100% rename from app/pages/Home/Home.js rename to client/app/pages/Home/Home.js diff --git a/app/pages/Home/Home.scss b/client/app/pages/Home/Home.scss similarity index 100% rename from app/pages/Home/Home.scss rename to client/app/pages/Home/Home.scss diff --git a/app/pages/NotFound/NotFound.js b/client/app/pages/NotFound/NotFound.js similarity index 99% rename from app/pages/NotFound/NotFound.js rename to client/app/pages/NotFound/NotFound.js index 1adc60f..701cce2 100644 --- a/app/pages/NotFound/NotFound.js +++ b/client/app/pages/NotFound/NotFound.js @@ -9,4 +9,4 @@ export default class Default extends React.Component { ); } -} \ No newline at end of file +} diff --git a/app/pages/NotFound/NotFound.scss b/client/app/pages/NotFound/NotFound.scss similarity index 100% rename from app/pages/NotFound/NotFound.scss rename to client/app/pages/NotFound/NotFound.scss diff --git a/app/pages/Soundboard/SoundList.component.js b/client/app/pages/Soundboard/SoundList.component.js similarity index 100% rename from app/pages/Soundboard/SoundList.component.js rename to client/app/pages/Soundboard/SoundList.component.js diff --git a/app/pages/Soundboard/SoundList.scss b/client/app/pages/Soundboard/SoundList.scss similarity index 100% rename from app/pages/Soundboard/SoundList.scss rename to client/app/pages/Soundboard/SoundList.scss diff --git a/app/pages/Soundboard/Soundboard.js b/client/app/pages/Soundboard/Soundboard.js similarity index 100% rename from app/pages/Soundboard/Soundboard.js rename to client/app/pages/Soundboard/Soundboard.js diff --git a/app/pages/Soundboard/Soundboard.scss b/client/app/pages/Soundboard/Soundboard.scss similarity index 100% rename from app/pages/Soundboard/Soundboard.scss rename to client/app/pages/Soundboard/Soundboard.scss diff --git a/app/scss/index.scss b/client/app/scss/index.scss similarity index 100% rename from app/scss/index.scss rename to client/app/scss/index.scss diff --git a/app/scss/style.scss b/client/app/scss/style.scss similarity index 100% rename from app/scss/style.scss rename to client/app/scss/style.scss diff --git a/app/scss/variables.scss b/client/app/scss/variables.scss similarity index 100% rename from app/scss/variables.scss rename to client/app/scss/variables.scss diff --git a/index.html b/client/index.html similarity index 100% rename from index.html rename to client/index.html diff --git a/package.json b/client/package.json similarity index 100% rename from package.json rename to client/package.json diff --git a/postcss.config.js b/client/postcss.config.js similarity index 100% rename from postcss.config.js rename to client/postcss.config.js diff --git a/webpack.config.js b/client/webpack.config.js similarity index 97% rename from webpack.config.js rename to client/webpack.config.js index f8df6ea..8fb53b9 100644 --- a/webpack.config.js +++ b/client/webpack.config.js @@ -9,7 +9,7 @@ module.exports = { vendor: ['react', 'react-dom'] }, output: { - path: path.resolve(__dirname, 'dist'), + path: path.resolve(__dirname, '../dist'), filename: '/static/[name].[hash].js' }, module: { diff --git a/yarn.lock b/client/yarn.lock similarity index 100% rename from yarn.lock rename to client/yarn.lock diff --git a/ffmpeg_linux b/ffmpeg_linux old mode 100644 new mode 100755 diff --git a/server/main.go b/main.go similarity index 100% rename from server/main.go rename to main.go diff --git a/makefile b/makefile index 29ec847..4f3ffa4 100644 --- a/makefile +++ b/makefile @@ -1,20 +1,16 @@ run: - go run ./server/main.go + go run ./main.go install: - go get ./server && yarn install + go get && cd client && yarn install -build: - go build -o ./dist/bot ./server/main.go +build-server: + go build -o bot ./main.go + +build-client: + cd client && yarn run build clean: - rm -rf ./dist + rm -rf bot ./dist -copyfiles: - cp config.template.json ./dist/config.template.json - cp ffmpeg_linux ./dist/ - cp ffmpeg_mac ./dist/ - cp ffmpeg_windows.exe ./dist/ - -all: install build copyfiles - yarn run build +all: install build-server build-client diff --git a/readme.md b/readme.md index 62bee67..1e57826 100644 --- a/readme.md +++ b/readme.md @@ -15,23 +15,21 @@ NOTE: Currently the binaries in the release package only run on linux. Check the ### NOTE -If you get a permissions error with ffmpeg: -`sudo chmod +x dist/ffmpeg` +If you get a permissions error with ffmpeg on mac or linux: +`sudo chmod +x dist/ffmpeg_linux` -Sounds are stored in the `dist/sounds` directory. You may copy files directly to this folder rather than uploading through the site. +Sounds are stored in the `sounds` directory. You may copy files directly to this folder rather than uploading through the site. ## Building from Source ### Dependencies - Go -- Godep - [Godep package manager](https://github.com/tools/godep) - Yarn (or npm - makefile will need to be adjusted) - make ### Compiling - Make sure dependencies are installed - `make all` -- cd into ./dist - Rename the `config.template.json` to `config.json` - add configurations to `config.json` - run the executable diff --git a/server/bothandlers/sounds.go b/server/bothandlers/sounds.go index a1698d9..b83b0f6 100644 --- a/server/bothandlers/sounds.go +++ b/server/bothandlers/sounds.go @@ -26,23 +26,50 @@ const ( maxBytes int = (frameSize * 2) * 2 // max size of opus data ) +// store our connection objects in a map tied to a guild id +var activeConnections = make(map[string]*audioConnection) + +type audioConnection struct { + guild *discordgo.Guild + sounds map[string]*audioClip + soundQueue chan string + voiceConnection *discordgo.VoiceConnection +} + var ( - sounds = make(map[string]*AudioClip, 0) + sounds = make(map[string]*audioClip, 0) soundQueue = []string{} soundPlayingLock = false voiceConnection *discordgo.VoiceConnection ) -type AudioClip struct { +type audioClip struct { Name string Extension string Content [][]byte } -const SOUNDS_DIR string = "./sounds/" - +// SoundsHandler - func SoundsHandler(s *discordgo.Session, m *discordgo.MessageCreate) { + // get guild ID and check for connection instance + c, err := s.State.Channel(m.ChannelID) + if err != nil { + // Could not find channel. + fmt.Println("Unable to find channel.") + return + } + + if _, ok := activeConnections[c.GuildID]; !ok { + newConnectionInstance, err := getNewConnectionInstance(s, m) + if err != nil { + log.Println(err) + return + } + + activeConnections[c.GuildID] = newConnectionInstance + } + // check if valid command if strings.HasPrefix(m.Content, config.Config.BotPrefix) { @@ -62,6 +89,10 @@ func SoundsHandler(s *discordgo.Session, m *discordgo.MessageCreate) { } } +func getNewConnectionInstance(s *discordgo.Session, m *discordgo.MessageCreate) (*audioConnection, error) { + return &audioConnection{}, nil +} + func dismiss() { if voiceConnection != nil { voiceConnection.Disconnect() @@ -213,7 +244,7 @@ func loadFile(fileName string) error { return errors.New("NewEncoder error.") } - sounds[fileName] = &AudioClip{ + sounds[fileName] = &audioClip{ Content: make([][]byte, 0), Name: fileName, Extension: fextension, @@ -249,7 +280,7 @@ func playSounds(s *discordgo.Session, guildID, channelID string) (err error) { soundPlayingLock = true // Join the channel the user issued the command from if not in it - if voiceConnection == nil || voiceConnection.ChannelID != channelID { + if voiceConnection == nil || !voiceConnection.Ready { var err error voiceConnection, err = s.ChannelVoiceJoin(guildID, channelID, false, false) if err != nil { diff --git a/server/webserver/server.go b/server/webserver/server.go index c72a3af..d6d88e7 100644 --- a/server/webserver/server.go +++ b/server/webserver/server.go @@ -28,11 +28,11 @@ func registerRoutes(router *fasthttprouter.Router) { router.GET("/soundlist", handlers.SoundList) router.PUT("/upload", handlers.FileUpload) - router.ServeFiles("/static/*filepath", "./static") + router.ServeFiles("/static/*filepath", "./dist/static") router.ServeFiles("/sounds/*filepath", config.Config.SoundsPath) router.NotFound = func(ctx *fasthttp.RequestCtx) { - fasthttp.ServeFile(ctx, "./index.html") + fasthttp.ServeFile(ctx, "./dist/index.html") } }