summaryrefslogtreecommitdiff
path: root/DiscoBot/Audio/AudioService.cs
diff options
context:
space:
mode:
authornatrixaeria <janng@gmx.de>2019-05-19 17:40:59 +0200
committernatrixaeria <janng@gmx.de>2019-05-19 17:40:59 +0200
commit1509b5ef3d7e9e71d9294e234ec0e39f2d831998 (patch)
tree78300ffff230958101b422a4e6026925b287822f /DiscoBot/Audio/AudioService.cs
parentc3bb858bb54dc8c64bbd48054c2c58dc0073f09c (diff)
parentc4d046858e0822b7c2c540ac2368b2c0e88e7a26 (diff)
Merge branch 'scribble' of https://github.com/TrueDoctor/DiscoBot into scribble
Diffstat (limited to 'DiscoBot/Audio/AudioService.cs')
-rw-r--r--DiscoBot/Audio/AudioService.cs70
1 files changed, 32 insertions, 38 deletions
diff --git a/DiscoBot/Audio/AudioService.cs b/DiscoBot/Audio/AudioService.cs
index 6e01980..a198eb2 100644
--- a/DiscoBot/Audio/AudioService.cs
+++ b/DiscoBot/Audio/AudioService.cs
@@ -1,34 +1,27 @@
-namespace DiscoBot.Audio
-{
- using System.Collections.Concurrent;
- using System.Diagnostics;
- using System.IO;
- using System.Threading.Tasks;
-
- using DiscoBot.DSA_Game;
-
- using Discord;
- using Discord.Audio;
+using System;
+using System.Collections.Concurrent;
+using System.Diagnostics;
+using System.IO;
+using System.Threading.Tasks;
+using Discord;
+using Discord.Audio;
+namespace DiscoBot.Audio
+{
public class AudioService
{
- private readonly ConcurrentDictionary<ulong, IAudioClient> connectedChannels = new ConcurrentDictionary<ulong, IAudioClient>();
+ private readonly ConcurrentDictionary<ulong, IAudioClient> connectedChannels =
+ new ConcurrentDictionary<ulong, IAudioClient>();
public async Task JoinAudio(IGuild guild, IVoiceChannel target)
{
- if (this.connectedChannels.TryGetValue(guild.Id, out var client))
- {
- return;
- }
+ if (connectedChannels.TryGetValue(guild.Id, out var client)) return;
- if (target.Guild.Id != guild.Id)
- {
- return;
- }
+ if (target.Guild.Id != guild.Id) return;
var audioClient = await target.ConnectAsync();
- if (this.connectedChannels.TryAdd(guild.Id, audioClient))
+ 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.
@@ -38,11 +31,9 @@
public async Task LeaveAudio(IGuild guild)
{
- if (this.connectedChannels.TryRemove(guild.Id, out var client))
- {
+ if (connectedChannels.TryRemove(guild.Id, out var client))
await client.StopAsync();
- //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.");
- }
+ //await Log(LogSeverity.Info, $"Disconnected from voice on {guild.Name}.");
}
public async Task SendAudioAsync(IGuild guild, IMessageChannel channel, string path)
@@ -54,28 +45,31 @@
return;
}
- if (this.connectedChannels.TryGetValue(guild.Id, out var client))
- {
+ if (connectedChannels.TryGetValue(guild.Id, out var client))
//await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
- using (var ffmpeg = this.CreateStream(path))
+ using (var ffmpeg = CreateStream(path))
using (var stream = client.CreatePCMStream(AudioApplication.Music))
{
- try { await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream); }
- finally { await stream.FlushAsync(); }
+ try
+ {
+ await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream);
+ }
+ finally
+ {
+ await stream.FlushAsync();
+ }
}
- }
}
- public async Task SendAudioAsync(string path, int Volume)
+ public async Task SendAudioAsync(string path, int volume)
{
// Your task: Get a full path to the file if the value of 'path' is only a filename.
if (!File.Exists(path) && false)
- {
//await channel.SendMessageAsync("File does not exist.");
return;
- }
- if (this.connectedChannels.TryGetValue(Dsa.GeneralContext.Guild.Id, out var client))
+ throw new NotImplementedException("get channel data from server");
+ /*if (this.connectedChannels.TryGetValue())
{
//await Log(LogSeverity.Debug, $"Starting playback of {path} in {guild.Name}");
using (var ffmpeg = this.CreateStream(path))
@@ -84,10 +78,10 @@
try { await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream); }
finally { await stream.FlushAsync(); }
}
- }
+ }*/
}
- private Process CreateStream(string path)
+ private static Process CreateStream(string path)
{
return Process.Start(new ProcessStartInfo
{
@@ -98,4 +92,4 @@
});
}
}
-}
+} \ No newline at end of file