diff --git a/BUILDS/net5.0/CMD_Utils.dll b/BUILDS/net5.0/CMD_Utils.dll index 6811276..2da5423 100644 Binary files a/BUILDS/net5.0/CMD_Utils.dll and b/BUILDS/net5.0/CMD_Utils.dll differ diff --git a/BUILDS/net5.0/ref/CMD_Utils.dll b/BUILDS/net5.0/ref/CMD_Utils.dll index 5a716e7..663a24d 100644 Binary files a/BUILDS/net5.0/ref/CMD_Utils.dll and b/BUILDS/net5.0/ref/CMD_Utils.dll differ diff --git a/CMD_Utils/Music/Data.cs b/CMD_Utils/Music/Data.cs new file mode 100644 index 0000000..68b2f2b --- /dev/null +++ b/CMD_Utils/Music/Data.cs @@ -0,0 +1,17 @@ +using Discord; +using Discord.Audio; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CMD_Utils.Music +{ + internal static class Data + { + internal static IAudioClient audioClient; + internal static IVoiceChannel voiceChannel; + } +} diff --git a/CMD_Utils/Music/Leave.cs b/CMD_Utils/Music/Leave.cs new file mode 100644 index 0000000..492214e --- /dev/null +++ b/CMD_Utils/Music/Leave.cs @@ -0,0 +1,34 @@ +using Discord.Commands; +using Discord.WebSocket; + +using PluginManager.Interfaces; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CMD_Utils.Music +{ + class Leave : DBCommand + { + public string Command => "leave"; + + public string Description => "Leave the voice channel"; + + public string Usage => "leave"; + + public bool canUseDM => false; + + public bool canUseServer => true; + + public bool requireAdmin => false; + + public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) + { + await Data.audioClient.StopAsync(); + await Data.voiceChannel.DisconnectAsync(); + } + } +} diff --git a/CMD_Utils/Music/Pause.cs b/CMD_Utils/Music/Pause.cs new file mode 100644 index 0000000..16d9872 --- /dev/null +++ b/CMD_Utils/Music/Pause.cs @@ -0,0 +1,33 @@ +using Discord.Commands; +using Discord.WebSocket; + +using PluginManager.Interfaces; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CMD_Utils.Music +{ + class Pause : DBCommand + { + public string Command => "pause"; + + public string Description => "Pause the music"; + + public string Usage => "pause"; + + public bool canUseDM => false; + + public bool canUseServer => true; + + public bool requireAdmin => false; + + public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) + { + // to be implemented + } + } +} diff --git a/CMD_Utils/Music/Play.cs b/CMD_Utils/Music/Play.cs new file mode 100644 index 0000000..f2cbac2 --- /dev/null +++ b/CMD_Utils/Music/Play.cs @@ -0,0 +1,77 @@ +using Discord; +using Discord.Audio; +using Discord.Commands; +using Discord.WebSocket; + +using Microsoft.VisualBasic; + +using PluginManager.Interfaces; +using PluginManager.Others; + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Channels; +using System.Threading.Tasks; + +namespace CMD_Utils.Music +{ + class Play : DBCommand + { + public string Command => "fplay"; + + public string Description => "Play music from a file"; + + public string Usage => "fplay [name]"; + + public bool canUseDM => false; + + public bool canUseServer => true; + + public bool requireAdmin => false; + + public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM) + { + string path = "./Music"; + string FileName = Functions.GetArguments(message).ToArray().MergeStrings(0); + path += "/" + FileName + ".mp3"; + if (!File.Exists(path)) + { + Console.WriteLine("Unknown path " + path); + return; + } + + // Get the audio channel + + Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel; + if (Data.voiceChannel == null) { await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; } + + // For the next step with transmitting audio, you would want to pass this Audio Client in to a service. + Data.audioClient = await Data.voiceChannel.ConnectAsync(); + + + // Create FFmpeg using the previous example + using (var ffmpeg = CreateStream(path)) + using (var output = ffmpeg.StandardOutput.BaseStream) + using (var discord = Data.audioClient.CreatePCMStream(AudioApplication.Mixed)) + { + try { await output.CopyToAsync(discord); } + finally { await discord.FlushAsync(); } + } + } + + private Process CreateStream(string path) + { + return Process.Start(new ProcessStartInfo + { + FileName = "ffmpeg", + Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1", + UseShellExecute = false, + RedirectStandardOutput = true, + }); + } + } +}