Beispiel #1
0
func (k *Discord) Command_Audio_Play_File(text string) {
	if !k.discord.Voice.Ready {
		return
	}

	filepath := utils.GetAudioFilePath(text)
	if filepath != "" {
		dgvoice.PlayAudioFile(k.discord, filepath)
	}

}
Beispiel #2
0
func main() {

	// NOTE: All of the below fields are required for this example to work correctly.
	var (
		Email     = flag.String("e", "", "Discord account email.")
		Password  = flag.String("p", "", "Discord account password.")
		GuildID   = flag.String("g", "", "Guild ID")
		ChannelID = flag.String("c", "", "Channel ID")
		Folder    = flag.String("f", "", "Folder of files to play.")
		err       error
	)
	flag.Parse()

	// Connect to Discord
	discord, err := discordgo.New(*Email, *Password)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Open Websocket
	err = discord.Open()
	if err != nil {
		fmt.Println(err)
		return
	}

	// Connect to voice channel.
	// NOTE: Setting mute to false, deaf to true.
	dgv, err := discord.ChannelVoiceJoin(*GuildID, *ChannelID, false, true)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Start loop and attempt to play all files in the given folder
	fmt.Println("Reading Folder: ", *Folder)
	files, _ := ioutil.ReadDir(*Folder)
	for _, f := range files {
		fmt.Println("PlayAudioFile:", f.Name())
		discord.UpdateStatus(0, f.Name())
		dgvoice.PlayAudioFile(dgv, fmt.Sprintf("%s/%s", *Folder, f.Name()))
	}

	// Close connections
	dgv.Close()
	discord.Close()

	return
}
Beispiel #3
0
func main() {

	// NOTE: All of the below fields are required for this example to work correctly.
	var (
		Email     = flag.String("e", "", "Discord account email.")
		Password  = flag.String("p", "", "Discord account password.")
		GuildID   = flag.String("g", "", "Guild ID")
		ChannelID = flag.String("c", "", "Channel ID")
		Filename  = flag.String("f", "", "Filename of file to play.")
		err       error
	)
	flag.Parse()

	// Connect to Discord
	discord, err := discordgo.New(*Email, *Password)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Connect to voice channel.
	// NOTE: Setting mute to false, deaf to true.
	err = discord.ChannelVoiceJoin(*GuildID, *ChannelID, false, true)
	if err != nil {
		fmt.Println(err)
		return
	}

	// This will block until Voice is ready.  This is not the most ideal
	// way to check and shouldn't be used outside of this example.
	for {
		if discord.Voice.Ready {
			break
		}
		fmt.Print(".")
		time.Sleep(1 * time.Second)
	}

	// streams file from ffmpeg then encodes with opus and sends via UDP
	// to Discord.
	dgvoice.PlayAudioFile(discord, *Filename)

	// Close connections
	discord.Voice.Close()
	discord.Close()

	return
}
Beispiel #4
0
func (k *Discord) Command_Audio_Play_Ivona(text string, language string) {
	if !k.discord.Voice.Ready {
		return
	}

	var tt string
	if strings.HasPrefix(text, "$$$") {
		tt = strings.Split(text, "$$$")[1]
	} else {
		tt = strings.SplitN(text, " ", 2)[1]
	}

	if language == "" {
		language = k.services.YTranslate.Detect(tt)
	}

	filename := k.services.Ivona.GetAudio_File(tt, language)

	if filename != "" {
		dgvoice.PlayAudioFile(k.discord, filename)
	}
}