diff --git a/.gitignore b/.gitignore index 6308429..07ab8fc 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ config.json dist node_modules yarn-error* +vendor diff --git a/ffmpeg b/ffmpeg_linux similarity index 100% rename from ffmpeg rename to ffmpeg_linux diff --git a/ffmpeg_mac b/ffmpeg_mac new file mode 100755 index 0000000..16e6629 Binary files /dev/null and b/ffmpeg_mac differ diff --git a/ffmpeg_windows.exe b/ffmpeg_windows.exe new file mode 100755 index 0000000..0e2cd9e Binary files /dev/null and b/ffmpeg_windows.exe differ diff --git a/glide.lock b/glide.lock new file mode 100644 index 0000000..ad4122e --- /dev/null +++ b/glide.lock @@ -0,0 +1,36 @@ +hash: aa2cc77713b57b79c4fc5bd35494fc4077e122137fdd68fa77aab8fdbc4215c8 +updated: 2017-06-28T22:24:45.223511-05:00 +imports: +- name: github.com/buaazp/fasthttprouter + version: ade4e2031af3aed7fffd241084aad80a58faf421 +- name: github.com/bwmarrin/discordgo + version: 0993a94b4e1c3291bed2047f583f34792269355c +- name: github.com/gorilla/websocket + version: ea4d1f681babbce9545c9c5f3d5194a789c89f5b +- name: github.com/karalabe/xgo + version: 34c7afab9a8eb8bff579e20bdbce9a764ce2a9ab +- name: github.com/klauspost/compress + version: f3dce52e0576655d55fd69e74b63da96ad1108f3 + subpackages: + - flate + - gzip + - zlib +- name: github.com/klauspost/cpuid + version: 09cded8978dc9e80714c4d85b0322337b0a1e5e0 +- name: github.com/tidwall/gjson + version: c784c417818f59d6597274642d8ac1d09efc9b01 +- name: github.com/tidwall/match + version: 173748da739a410c5b0b813b956f89ff94730b4c +- name: github.com/valyala/fasthttp + version: d42167fd04f636e20b005e9934159e95454233c7 + subpackages: + - fasthttputil +- name: golang.org/x/crypto + version: 84f24dfdf3c414ed893ca1b318d0045ef5a1f607 + subpackages: + - nacl/secretbox + - poly1305 + - salsa20/salsa +- name: layeh.com/gopus + version: 0ebf989153aa016ef5e77141b08c48e48a79312e +testImports: [] diff --git a/glide.yaml b/glide.yaml new file mode 100644 index 0000000..2ce2a0a --- /dev/null +++ b/glide.yaml @@ -0,0 +1,11 @@ +package: . +import: +- package: github.com/buaazp/fasthttprouter + version: ^0.1.1 +- package: github.com/bwmarrin/discordgo + version: ^0.16.0 +- package: github.com/tidwall/gjson +- package: github.com/valyala/fasthttp + version: ^20160617.0.0 +- package: layeh.com/gopus +- package: github.com/karalabe/xgo diff --git a/makefile b/makefile index 3387e09..330154b 100644 --- a/makefile +++ b/makefile @@ -2,17 +2,19 @@ run: go run ./server/main.go install: - go get ./server && yarn install + glide install && yarn install build: - go build -o ./dist/bot ./server/main.go + go build -o ./dist/linux ./server/main.go clean: rm -rf ./dist copyfiles: cp config.template.json ./dist/config.template.json - cp ffmpeg ./dist/ffmpeg + cp ffmpeg_linux ./dist/ + cp ffmpeg_mac ./dist/ + cp ffmpeg_windows.exe ./dist/ all: install build copyfiles yarn run build diff --git a/readme.md b/readme.md index 10e0176..665174c 100644 --- a/readme.md +++ b/readme.md @@ -24,12 +24,14 @@ Sounds are stored in the `dist/sounds` directory. You may copy files directly to ### Dependencies - Go +- Glide - [GoLang package manager](https://glide.sh/) - 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 @@ -38,7 +40,4 @@ Sounds are stored in the `dist/sounds` directory. You may copy files directly to - success! ### Windows -I've only compiled and run this on linux, but it should work on windows with little changes. -An ffmpeg executable is required. The linux executable is included. -If running on windows ffmpeg.exe must be downloaded. -Check line 116 in server/bothandlers/sounds.go +I've only compiled and run this on linux so far, but I've recently added cross platform support. diff --git a/server/bot/bot.go b/server/bot/bot.go index 216be19..6c85709 100644 --- a/server/bot/bot.go +++ b/server/bot/bot.go @@ -2,6 +2,8 @@ package bot import ( "fmt" + "log" + "github.com/bwmarrin/discordgo" ) @@ -17,14 +19,16 @@ func Connect(token string) { Session, err = discordgo.New("Bot " + token) if err != nil { - fmt.Println("error creating Discord session,", err) - return + log.Println(err) + log.Fatal("Error creating Discord session.", err) } // Get the account information. u, err := Session.User("@me") + if err != nil { - fmt.Println("error obtaining account details,", err) + log.Println("Error obtaining account details. Make sure you have the correct bot token.") + log.Fatal(err) } // Store the account ID for later use. diff --git a/server/bothandlers/sounds.go b/server/bothandlers/sounds.go index 90a1fc5..9dda99a 100644 --- a/server/bothandlers/sounds.go +++ b/server/bothandlers/sounds.go @@ -1,19 +1,21 @@ package bothandlers import ( - "../config" "bufio" "encoding/binary" "errors" "fmt" - "github.com/bwmarrin/discordgo" "io" "io/ioutil" - "layeh.com/gopus" "os/exec" + "runtime" "strconv" "strings" "time" + + "../config" + "github.com/bwmarrin/discordgo" + "layeh.com/gopus" ) const ( @@ -113,14 +115,24 @@ func loadFile(fileName string) error { fmt.Println("Loading file: " + fname + fextension) - // TODO - check if windows and use "./ffmpeg.exe" - change this if you wish to run on windows + var ffmpegExecutable string + + switch runtime.GOOS { + case "darwin": + ffmpegExecutable = "./ffmpeg_mac" + case "linux": + ffmpegExecutable = "./ffmpeg_linux" + case "windows": + ffmpegExecutable = "ffmpeg_windows.exe" + } + // use ffmpeg to convert file into a format we can use - cmd := exec.Command("./ffmpeg", "-i", config.Config.SoundsPath+fname+fextension, "-f", "s16le", "-ar", strconv.Itoa(frameRate), "-ac", strconv.Itoa(channels), "pipe:1") + cmd := exec.Command(ffmpegExecutable, "-i", config.Config.SoundsPath+fname+fextension, "-f", "s16le", "-ar", strconv.Itoa(frameRate), "-ac", strconv.Itoa(channels), "pipe:1") ffmpegout, err := cmd.StdoutPipe() if err != nil { - return errors.New("Stdout error.") + return errors.New("Unable to execute ffmpeg. To set permissions on this file run chmod +x ffmpeg_linux (or ffmpeg_mac depending which operating system you are on)") } ffmpegbuf := bufio.NewReaderSize(ffmpegout, 16348) @@ -128,7 +140,7 @@ func loadFile(fileName string) error { err = cmd.Start() if err != nil { - return errors.New("CMD Start error.") + return errors.New("Unable to execute ffmpeg. To set permissions on this file run chmod +x ffmpeg_linux (or ffmpeg_mac depending which operating system you are on)") } // crate encoder to convert audio to opus codec