mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-09 16:42:48 +00:00
added ffmpeg binaries for mac/windows
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ config.json
|
||||
dist
|
||||
node_modules
|
||||
yarn-error*
|
||||
vendor
|
||||
|
||||
BIN
ffmpeg_mac
Executable file
BIN
ffmpeg_mac
Executable file
Binary file not shown.
BIN
ffmpeg_windows.exe
Executable file
BIN
ffmpeg_windows.exe
Executable file
Binary file not shown.
36
glide.lock
generated
Normal file
36
glide.lock
generated
Normal file
@@ -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: []
|
||||
11
glide.yaml
Normal file
11
glide.yaml
Normal file
@@ -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
|
||||
8
makefile
8
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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user