Skip to content

Instantly share code, notes, and snippets.

@Joe4evr
Last active February 27, 2025 23:17
Show Gist options
  • Select an option

  • Save Joe4evr/773d3ce6cc10dbea6924d59bbfa3c62a to your computer and use it in GitHub Desktop.

Select an option

Save Joe4evr/773d3ce6cc10dbea6924d59bbfa3c62a to your computer and use it in GitHub Desktop.

Revisions

  1. Joe4evr revised this gist Jun 29, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,7 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    }
    }

    private Process CreateStream(string path)
    private Process CreateProcess(string path)
    {
    return Process.Start(new ProcessStartInfo
    {
  2. Joe4evr revised this gist Mar 22, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -53,10 +53,10 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    if (ConnectedChannels.TryGetValue(guild.Id, out client))
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
    using (var output = CreateStream(path).StandardOutput.BaseStream)
    using (var ffmpeg = CreateProcess(path))
    using (var stream = client.CreatePCMStream(AudioApplication.Music))
    {
    try { await output.CopyToAsync(stream); }
    try { await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream); }
    finally { await stream.FlushAsync(); }
    }
    }
  3. Joe4evr revised this gist Oct 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    using (var stream = client.CreatePCMStream(AudioApplication.Music))
    {
    try { await output.CopyToAsync(stream); }
    finally { await stream.FlushAsync().ConfigureAwait(false); }
    finally { await stream.FlushAsync(); }
    }
    }
    }
  4. Joe4evr revised this gist Oct 20, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -56,8 +56,8 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    using (var output = CreateStream(path).StandardOutput.BaseStream)
    using (var stream = client.CreatePCMStream(AudioApplication.Music))
    {
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    try { await output.CopyToAsync(stream); }
    finally { await stream.FlushAsync().ConfigureAwait(false); }
    }
    }
    }
  5. Joe4evr revised this gist Oct 20, 2017. 1 changed file with 7 additions and 8 deletions.
    15 changes: 7 additions & 8 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target)
    if (ConnectedChannels.TryAdd(guild.Id, audioClient))
    {
    // If you add a method to log happenings from this service,
    // you can uncomment the following line to make use of that.
    // you can uncomment these commented lines to make use of that.
    //await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.");
    }
    }
    @@ -53,13 +53,12 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    if (ConnectedChannels.TryGetValue(guild.Id, out client))
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
    var output = CreateStream(path).StandardOutput.BaseStream;

    // You can change the bitrate of the outgoing stream with an additional argument to CreatePCMStream().
    // If not specified, the default bitrate is 96*1024.
    var stream = client.CreatePCMStream(AudioApplication.Music);
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    using (var output = CreateStream(path).StandardOutput.BaseStream)
    using (var stream = client.CreatePCMStream(AudioApplication.Music))
    {
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    }
    }
    }

  6. Joe4evr revised this gist Jul 31, 2017. 2 changed files with 5 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -4,10 +4,11 @@
    public class AudioModule : ModuleBase<ICommandContext>
    {
    // Scroll down further for the AudioService.
    // Like, way down.
    // Hit 'End' on your keyboard if you still can't find it.
    // Like, way down
    private readonly AudioService _service;

    // Remember to add an instance of the AudioService
    // to your IServiceCollection when you initialize your bot
    public AudioModule(AudioService service)
    {
    _service = service;
    2 changes: 2 additions & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,8 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target)

    if (ConnectedChannels.TryAdd(guild.Id, audioClient))
    {
    // If you add a method to log happenings from this service,
    // you can uncomment the following line to make use of that.
    //await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.");
    }
    }
  7. Joe4evr revised this gist Jun 20, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -52,6 +52,9 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
    var output = CreateStream(path).StandardOutput.BaseStream;

    // You can change the bitrate of the outgoing stream with an additional argument to CreatePCMStream().
    // If not specified, the default bitrate is 96*1024.
    var stream = client.CreatePCMStream(AudioApplication.Music);
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
  8. Joe4evr revised this gist May 4, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    using System.Collections.Concurrent;
    using System.Diagnostics;
    using System.IO;
    using System.Threading.Tasks;
    using Discord;
    using Discord.Audio;
  9. Joe4evr revised this gist Apr 17, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
    var output = CreateStream(path).StandardOutput.BaseStream;
    var stream = client.CreatePCMStream(AudioApplication.Music, 1920);
    var stream = client.CreatePCMStream(AudioApplication.Music);
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    }
  10. Joe4evr revised this gist Feb 28, 2017. 2 changed files with 9 additions and 5 deletions.
    3 changes: 3 additions & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@
    public class AudioModule : ModuleBase<ICommandContext>
    {
    // Scroll down further for the AudioService.
    // Like, way down.
    // Hit 'End' on your keyboard if you still can't find it.
    private readonly AudioService _service;

    public AudioModule(AudioService service)
    @@ -21,6 +23,7 @@ public async Task JoinCmd()

    // Remember to add preconditions to your commands,
    // this is merely the minimal amount necessary.
    // Adding more commands of your own is also encouraged.
    [Command("leave", RunMode = RunMode.Async)]
    public async Task LeaveCmd()
    {
    11 changes: 6 additions & 5 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target)

    if (ConnectedChannels.TryAdd(guild.Id, audioClient))
    {
    //await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.").ConfigureAwait(false);
    //await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.");
    }
    }

    @@ -33,13 +33,14 @@ public async Task LeaveAudio(IGuild guild)
    IAudioClient client;
    if (ConnectedChannels.TryRemove(guild.Id, out client))
    {
    await client.DisconnectAsync();
    //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    await client.StopAsync();
    //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.");
    }
    }

    public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string path)
    {
    // Your task: Get a full path to the file if the value of 'path' is only a filename.
    if (!File.Exists(path))
    {
    await channel.SendMessageAsync("File does not exist.");
    @@ -48,9 +49,9 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    IAudioClient client;
    if (ConnectedChannels.TryGetValue(guild.Id, out client))
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}").ConfigureAwait(false);
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
    var output = CreateStream(path).StandardOutput.BaseStream;
    var stream = client.CreatePCMStream(1920);
    var stream = client.CreatePCMStream(AudioApplication.Music, 1920);
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    }
  11. Joe4evr revised this gist Feb 20, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@

    public class AudioModule : ModuleBase<ICommandContext>
    {
    // Scroll down further for the AudioService.
    private readonly AudioService _service;

    public AudioModule(AudioService service)
  12. Joe4evr revised this gist Feb 8, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -10,14 +10,16 @@ public AudioModule(AudioService service)
    _service = service;
    }

    // Remember to add preconditions to your commands,
    // this is merely the minimal amount necessary.
    // You *MUST* mark these commands with 'RunMode.Async'
    // otherwise the bot will not respond until the Task times out.
    [Command("join", RunMode = RunMode.Async)]
    public async Task JoinCmd()
    {
    await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
    }

    // Remember to add preconditions to your commands,
    // this is merely the minimal amount necessary.
    [Command("leave", RunMode = RunMode.Async)]
    public async Task LeaveCmd()
    {
  13. Joe4evr revised this gist Feb 7, 2017. 2 changed files with 4 additions and 0 deletions.
    1 change: 1 addition & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    using System.Threading.Tasks;
    using Discord.Commands;

    public class AudioModule : ModuleBase<ICommandContext>
    3 changes: 3 additions & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    using System.Collections.Concurrent;
    using System.Diagnostics;
    using System.Threading.Tasks;
    using Discord;
    using Discord.Audio;

    public class AudioService
  14. Joe4evr revised this gist Feb 6, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -12,20 +12,20 @@ public AudioModule(AudioService service)
    // Remember to add preconditions to your commands,
    // this is merely the minimal amount necessary.
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
    public async Task JoinCmd()
    {
    return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
    await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
    }

    [Command("leave", RunMode = RunMode.Async)]
    public Task LeaveCmd()
    public async Task LeaveCmd()
    {
    return _service.LeaveAudio(Context.Guild);
    await _service.LeaveAudio(Context.Guild);
    }

    [Command("play", RunMode = RunMode.Async)]
    public Task PlayCmd([Remainder] string song)
    public async Task PlayCmd([Remainder] string song)
    {
    return _service.SendAudioAsync(Context.Guild, Context.Channel, song);
    await _service.SendAudioAsync(Context.Guild, Context.Channel, song);
    }
    }
  15. Joe4evr revised this gist Feb 5, 2017. 2 changed files with 3 additions and 3 deletions.
    4 changes: 2 additions & 2 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,8 @@ public AudioModule(AudioService service)
    _service = service;
    }

    // Remember to add preconditions to your commands.
    // This is merely the minimal amount necessary.
    // Remember to add preconditions to your commands,
    // this is merely the minimal amount necessary.
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
    {
    2 changes: 1 addition & 1 deletion AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@

    public class AudioService
    {
    public ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels { get; } = new ConcurrentDictionary<ulong, IAudioClient>();
    private readonly ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels = new ConcurrentDictionary<ulong, IAudioClient>();

    public async Task JoinAudio(IGuild guild, IVoiceChannel target)
    {
  16. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ public AudioModule(AudioService service)
    _service = service;
    }

    // Remember to add more preconditions to your commands yourself.
    // Remember to add preconditions to your commands.
    // This is merely the minimal amount necessary.
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
  17. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,8 @@ public AudioModule(AudioService service)
    _service = service;
    }

    // Remember to add more preconditions to your commands yourself.
    // This is merely the minimal amount necessary.
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
    {
  18. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 7 additions and 4 deletions.
    11 changes: 7 additions & 4 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,8 @@ public class AudioService

    public async Task JoinAudio(IGuild guild, IVoiceChannel target)
    {
    if (ConnectedChannels.TryGetValue(guild.Id, out var _))
    IAudioClient client;
    if (ConnectedChannels.TryGetValue(guild.Id, out client))
    {
    return;
    }
    @@ -16,7 +17,7 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target)
    return;
    }

    var audioClient = await target.ConnectAsync().ConfigureAwait(false);
    var audioClient = await target.ConnectAsync();

    if (ConnectedChannels.TryAdd(guild.Id, audioClient))
    {
    @@ -26,7 +27,8 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target)

    public async Task LeaveAudio(IGuild guild)
    {
    if (ConnectedChannels.TryRemove(guild.Id, out var client))
    IAudioClient client;
    if (ConnectedChannels.TryRemove(guild.Id, out client))
    {
    await client.DisconnectAsync();
    //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    @@ -40,7 +42,8 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    await channel.SendMessageAsync("File does not exist.");
    return;
    }
    if (ConnectedChannels.TryGetValue(guild.Id, out var client))
    IAudioClient client;
    if (ConnectedChannels.TryGetValue(guild.Id, out client))
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}").ConfigureAwait(false);
    var output = CreateStream(path).StandardOutput.BaseStream;
  19. Joe4evr revised this gist Feb 5, 2017. 2 changed files with 7 additions and 14 deletions.
    3 changes: 0 additions & 3 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    using System.Threading.Tasks;
    using Discord.Commands;

    public class AudioModule : ModuleBase<ICommandContext>
    @@ -10,8 +9,6 @@ public AudioModule(AudioService service)
    _service = service;
    }

    // Remember to add more preconditions to your commands yourself.
    // This is merely the minimal amount necessary.
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
    {
    18 changes: 7 additions & 11 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    using System.Collections.Concurrent;
    using System.Diagnostics;
    using System.Threading.Tasks;
    using Discord.Audio;

    public class AudioService
    @@ -30,25 +28,24 @@ public async Task LeaveAudio(IGuild guild)
    {
    if (ConnectedChannels.TryRemove(guild.Id, out var client))
    {
    await client.DisconnectAsync().ConfigureAwait(false);
    await client.DisconnectAsync();
    //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    }
    }

    public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string path)
    {
    string v = Path.Combine(_config.MusicBasePath, path);
    if (!File.Exists(v))
    if (!File.Exists(path))
    {
    await channel.SendMessageAsync("File does not exist.").ConfigureAwait(false);
    await channel.SendMessageAsync("File does not exist.");
    return;
    }
    if (ConnectedChannels.TryGetValue(guild.Id, out var client))
    {
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}").ConfigureAwait(false);
    var output = CreateStream(v).StandardOutput.BaseStream;
    var output = CreateStream(path).StandardOutput.BaseStream;
    var stream = client.CreatePCMStream(1920);
    await output.CopyToAsync(stream, 81920, _cancel.Token).ConfigureAwait(false);
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    }
    }
    @@ -57,11 +54,10 @@ private Process CreateStream(string path)
    {
    return Process.Start(new ProcessStartInfo
    {
    FileName = Path.Combine(_config.FFMpegPath, "ffmpeg.exe"),
    FileName = "ffmpeg.exe",
    Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1",
    UseShellExecute = false,
    RedirectStandardOutput = true,
    CreateNoWindow = false
    RedirectStandardOutput = true
    });
    }
    }
  20. Joe4evr revised this gist Feb 5, 2017. 2 changed files with 5 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    using System.Threading.Tasks;
    using Discord.Commands;

    public class AudioModule : ModuleBase<ICommandContext>
    @@ -9,6 +10,8 @@ public AudioModule(AudioService service)
    _service = service;
    }

    // Remember to add more preconditions to your commands yourself.
    // This is merely the minimal amount necessary.
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
    {
    2 changes: 2 additions & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    using System.Collections.Concurrent;
    using System.Diagnostics;
    using System.Threading.Tasks;
    using Discord.Audio;

    public class AudioService
  21. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -43,7 +43,7 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p
    }
    if (ConnectedChannels.TryGetValue(guild.Id, out var client))
    {
    await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}").ConfigureAwait(false);
    //await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}").ConfigureAwait(false);
    var output = CreateStream(v).StandardOutput.BaseStream;
    var stream = client.CreatePCMStream(1920);
    await output.CopyToAsync(stream, 81920, _cancel.Token).ConfigureAwait(false);
  22. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 0 additions and 4 deletions.
    4 changes: 0 additions & 4 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -5,10 +5,6 @@ public class AudioService
    {
    public ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels { get; } = new ConcurrentDictionary<ulong, IAudioClient>();

    public AudioService()
    {
    }

    public async Task JoinAudio(IGuild guild, IVoiceChannel target)
    {
    if (ConnectedChannels.TryGetValue(guild.Id, out var _))
  23. Joe4evr revised this gist Feb 5, 2017. 2 changed files with 36 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -20,4 +20,10 @@ public Task LeaveCmd()
    {
    return _service.LeaveAudio(Context.Guild);
    }

    [Command("play", RunMode = RunMode.Async)]
    public Task PlayCmd([Remainder] string song)
    {
    return _service.SendAudioAsync(Context.Guild, Context.Channel, song);
    }
    }
    30 changes: 30 additions & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,34 @@ public async Task LeaveAudio(IGuild guild)
    //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    }
    }

    public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string path)
    {
    string v = Path.Combine(_config.MusicBasePath, path);
    if (!File.Exists(v))
    {
    await channel.SendMessageAsync("File does not exist.").ConfigureAwait(false);
    return;
    }
    if (ConnectedChannels.TryGetValue(guild.Id, out var client))
    {
    await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}").ConfigureAwait(false);
    var output = CreateStream(v).StandardOutput.BaseStream;
    var stream = client.CreatePCMStream(1920);
    await output.CopyToAsync(stream, 81920, _cancel.Token).ConfigureAwait(false);
    await stream.FlushAsync().ConfigureAwait(false);
    }
    }

    private Process CreateStream(string path)
    {
    return Process.Start(new ProcessStartInfo
    {
    FileName = Path.Combine(_config.FFMpegPath, "ffmpeg.exe"),
    Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1",
    UseShellExecute = false,
    RedirectStandardOutput = true,
    CreateNoWindow = false
    });
    }
    }
  24. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@ public AudioModule(AudioService service)
    _service = service;
    }

    [Command("join", RunMode = RunMode.Async)
    [Command("join", RunMode = RunMode.Async)]
    public Task JoinCmd()
    {
    return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
  25. Joe4evr revised this gist Feb 5, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ public AudioModule(AudioService service)
    }

    [Command("join", RunMode = RunMode.Async)
    public Task ConnectCmd()
    public Task JoinCmd()
    {
    return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
    }
  26. Joe4evr revised this gist Feb 5, 2017. 2 changed files with 9 additions and 5 deletions.
    4 changes: 3 additions & 1 deletion AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    using Discord.Commands;

    public class AudioModule : ModuleBase<ICommandContext>
    {
    private readonly AudioService _service;
    @@ -7,7 +9,7 @@ public AudioModule(AudioService service)
    _service = service;
    }

    [Command("connect", RunMode = RunMode.Async)
    [Command("join", RunMode = RunMode.Async)
    public Task ConnectCmd()
    {
    return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
    10 changes: 6 additions & 4 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,11 @@
    using System.Collections.Concurrent;
    using Discord.Audio;

    public class AudioService
    {

    public ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels { get; } = new ConcurrentDictionary<ulong, IAudioClient>();

    internal AudioService()
    public AudioService()
    {
    }

    @@ -22,7 +24,7 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target)

    if (ConnectedChannels.TryAdd(guild.Id, audioClient))
    {
    await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.").ConfigureAwait(false);
    //await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.").ConfigureAwait(false);
    }
    }

    @@ -31,7 +33,7 @@ public async Task LeaveAudio(IGuild guild)
    if (ConnectedChannels.TryRemove(guild.Id, out var client))
    {
    await client.DisconnectAsync().ConfigureAwait(false);
    await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    }
    }
    }
  27. Joe4evr created this gist Feb 5, 2017.
    21 changes: 21 additions & 0 deletions AudioModule.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    public class AudioModule : ModuleBase<ICommandContext>
    {
    private readonly AudioService _service;

    public AudioModule(AudioService service)
    {
    _service = service;
    }

    [Command("connect", RunMode = RunMode.Async)
    public Task ConnectCmd()
    {
    return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel);
    }

    [Command("leave", RunMode = RunMode.Async)]
    public Task LeaveCmd()
    {
    return _service.LeaveAudio(Context.Guild);
    }
    }
    37 changes: 37 additions & 0 deletions AudioService.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    public class AudioService
    {

    public ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels { get; } = new ConcurrentDictionary<ulong, IAudioClient>();

    internal AudioService()
    {
    }

    public async Task JoinAudio(IGuild guild, IVoiceChannel target)
    {
    if (ConnectedChannels.TryGetValue(guild.Id, out var _))
    {
    return;
    }
    if (target.Guild.Id != guild.Id)
    {
    return;
    }

    var audioClient = await target.ConnectAsync().ConfigureAwait(false);

    if (ConnectedChannels.TryAdd(guild.Id, audioClient))
    {
    await Log(LogSeverity.Info, $"Connected to voice on {guild.Name}.").ConfigureAwait(false);
    }
    }

    public async Task LeaveAudio(IGuild guild)
    {
    if (ConnectedChannels.TryRemove(guild.Id, out var client))
    {
    await client.DisconnectAsync().ConfigureAwait(false);
    await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false);
    }
    }
    }