Last active
February 27, 2025 23:17
-
-
Save Joe4evr/773d3ce6cc10dbea6924d59bbfa3c62a to your computer and use it in GitHub Desktop.
Revisions
-
Joe4evr revised this gist
Jun 29, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 CreateProcess(string path) { return Process.Start(new ProcessStartInfo { -
Joe4evr revised this gist
Mar 22, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ffmpeg = CreateProcess(path)) using (var stream = client.CreatePCMStream(AudioApplication.Music)) { try { await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream); } finally { await stream.FlushAsync(); } } } -
Joe4evr revised this gist
Oct 20, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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(); } } } } -
Joe4evr revised this gist
Oct 20, 2017 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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)) { try { await output.CopyToAsync(stream); } finally { await stream.FlushAsync().ConfigureAwait(false); } } } } -
Joe4evr revised this gist
Oct 20, 2017 . 1 changed file with 7 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 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}"); using (var output = CreateStream(path).StandardOutput.BaseStream) using (var stream = client.CreatePCMStream(AudioApplication.Music)) { await output.CopyToAsync(stream); await stream.FlushAsync().ConfigureAwait(false); } } } -
Joe4evr revised this gist
Jul 31, 2017 . 2 changed files with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 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; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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}."); } } -
Joe4evr revised this gist
Jun 20, 2017 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); -
Joe4evr revised this gist
May 4, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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; -
Joe4evr revised this gist
Apr 17, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); await output.CopyToAsync(stream); await stream.FlushAsync().ConfigureAwait(false); } -
Joe4evr revised this gist
Feb 28, 2017 . 2 changed files with 9 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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}."); } } @@ -33,13 +33,14 @@ public async Task LeaveAudio(IGuild guild) IAudioClient client; if (ConnectedChannels.TryRemove(guild.Id, out client)) { 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}"); var output = CreateStream(path).StandardOutput.BaseStream; var stream = client.CreatePCMStream(AudioApplication.Music, 1920); await output.CopyToAsync(stream); await stream.FlushAsync().ConfigureAwait(false); } -
Joe4evr revised this gist
Feb 20, 2017 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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) -
Joe4evr revised this gist
Feb 8, 2017 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,14 +10,16 @@ public AudioModule(AudioService service) _service = service; } // 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() { -
Joe4evr revised this gist
Feb 7, 2017 . 2 changed files with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
Joe4evr revised this gist
Feb 6, 2017 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 async Task JoinCmd() { await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel); } [Command("leave", RunMode = RunMode.Async)] public async Task LeaveCmd() { await _service.LeaveAudio(Context.Guild); } [Command("play", RunMode = RunMode.Async)] public async Task PlayCmd([Remainder] string song) { await _service.SendAudioAsync(Context.Guild, Context.Channel, song); } } -
Joe4evr revised this gist
Feb 5, 2017 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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. [Command("join", RunMode = RunMode.Async)] public Task JoinCmd() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ public class AudioService { private readonly ConcurrentDictionary<ulong, IAudioClient> ConnectedChannels = new ConcurrentDictionary<ulong, IAudioClient>(); public async Task JoinAudio(IGuild guild, IVoiceChannel target) { -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ public AudioModule(AudioService service) _service = service; } // Remember to add preconditions to your commands. // This is merely the minimal amount necessary. [Command("join", RunMode = RunMode.Async)] public Task JoinCmd() -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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() { -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,8 @@ public class AudioService public async Task JoinAudio(IGuild guild, IVoiceChannel target) { 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(); if (ConnectedChannels.TryAdd(guild.Id, audioClient)) { @@ -26,7 +27,8 @@ public async Task JoinAudio(IGuild guild, IVoiceChannel target) 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); @@ -40,7 +42,8 @@ public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string p await channel.SendMessageAsync("File does not exist."); return; } 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; -
Joe4evr revised this gist
Feb 5, 2017 . 2 changed files with 7 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ using Discord.Commands; public class AudioModule : ModuleBase<ICommandContext> @@ -10,8 +9,6 @@ public AudioModule(AudioService service) _service = service; } [Command("join", RunMode = RunMode.Async)] public Task JoinCmd() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,4 @@ using System.Collections.Concurrent; 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(); //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.").ConfigureAwait(false); } } public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string path) { if (!File.Exists(path)) { 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(path).StandardOutput.BaseStream; var stream = client.CreatePCMStream(1920); await output.CopyToAsync(stream); await stream.FlushAsync().ConfigureAwait(false); } } @@ -57,11 +54,10 @@ private Process CreateStream(string path) { return Process.Start(new ProcessStartInfo { FileName = "ffmpeg.exe", Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1", UseShellExecute = false, RedirectStandardOutput = true }); } } -
Joe4evr revised this gist
Feb 5, 2017 . 2 changed files with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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() { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); var output = CreateStream(v).StandardOutput.BaseStream; var stream = client.CreatePCMStream(1920); await output.CopyToAsync(stream, 81920, _cancel.Token).ConfigureAwait(false); -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 0 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 async Task JoinAudio(IGuild guild, IVoiceChannel target) { if (ConnectedChannels.TryGetValue(guild.Id, out var _)) -
Joe4evr revised this gist
Feb 5, 2017 . 2 changed files with 36 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 }); } } -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ public AudioModule(AudioService service) _service = service; } [Command("join", RunMode = RunMode.Async)] public Task JoinCmd() { return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel); -
Joe4evr revised this gist
Feb 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ public AudioModule(AudioService service) } [Command("join", RunMode = RunMode.Async) public Task JoinCmd() { return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel); } -
Joe4evr revised this gist
Feb 5, 2017 . 2 changed files with 9 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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("join", RunMode = RunMode.Async) public Task ConnectCmd() { return _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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>(); 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); } } @@ -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); } } } -
Joe4evr created this gist
Feb 5, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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); } } }