1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-11 17:42:48 +00:00

added ffmpeg binaries for mac/windows

This commit is contained in:
2017-06-28 22:57:09 -05:00
parent f9247c5417
commit eacdc51874
10 changed files with 82 additions and 17 deletions

View File

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

View File

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