core package, embryonic espeak function and tests
This commit is contained in:
51
core/messages.go
Normal file
51
core/messages.go
Normal file
@ -0,0 +1,51 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
func MessagePing(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
// Ignore all messages created by the bot itself
|
||||
// This isn't required in this specific example but it's a good practice.
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
|
||||
if m.Content == "ping" {
|
||||
s.ChannelMessageSend(m.ChannelID, "Pong!")
|
||||
}
|
||||
|
||||
if m.Content == "pong" {
|
||||
s.ChannelMessageSend(m.ChannelID, "Ping!")
|
||||
}
|
||||
}
|
||||
|
||||
func MessageAudio(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
if m.Author.ID == s.State.User.ID {
|
||||
return
|
||||
}
|
||||
|
||||
var prefix string = "/gogodisco audio"
|
||||
if strings.HasPrefix(m.Content, prefix) {
|
||||
var message string = strings.TrimLeft(m.Content, prefix)
|
||||
createAudio(message)
|
||||
}
|
||||
}
|
||||
|
||||
func createAudio(msg string) ([]byte, error){
|
||||
curr_time := time.Now().Unix()
|
||||
var filename string = fmt.Sprintf("/tmp/%d.mp3", curr_time)
|
||||
fmt.Println(filename)
|
||||
var cmd_args string = fmt.Sprintf("-s 120 -v mb-fr2 -p 30 '%s'", msg)
|
||||
cmd := exec.Command("espeak-ng", cmd_args)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Sprint(err) + ": " + string(out))
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
Reference in New Issue
Block a user