summaryrefslogtreecommitdiff
path: root/DiscoBot/Audio
diff options
context:
space:
mode:
authoruzvkl <dennis.kobert@student.kit.edu>2019-05-20 00:54:14 +0200
committeruzvkl <dennis.kobert@student.kit.edu>2019-05-20 00:54:14 +0200
commited26623e17e8dfcc036f88cca6de10d5a35697ec (patch)
tree26dae8b824631e6542c876c82ce0e15260c411bc /DiscoBot/Audio
parent2ab4051c6fe720dc47e99b0c305a0d779ee02d51 (diff)
Reorganize Code delete ZoBotanica
Diffstat (limited to 'DiscoBot/Audio')
-rw-r--r--DiscoBot/Audio/AudioModule.cs65
-rw-r--r--DiscoBot/Audio/AudioService.cs95
-rw-r--r--DiscoBot/Audio/Sound.cs18
-rw-r--r--DiscoBot/Audio/Voice.cs94
4 files changed, 0 insertions, 272 deletions
diff --git a/DiscoBot/Audio/AudioModule.cs b/DiscoBot/Audio/AudioModule.cs
deleted file mode 100644
index add4bf0..0000000
--- a/DiscoBot/Audio/AudioModule.cs
+++ /dev/null
@@ -1,65 +0,0 @@
-using System.Threading.Tasks;
-using Discord;
-using Discord.Commands;
-
-namespace DiscoBot.Audio
-{
- public class AudioModule : ModuleBase
- {
- // 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)
- {
- this.service = service;
- //Dsa.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.
- // Adding more commands of your own is also encouraged.
- [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)
- {
- /*if (Dsa.GeneralContext == null)
- {
- Dsa.GeneralContext = this.Context;
- }
-
- var sounds = Enum.GetValues(typeof(Sound));
- var soundList = new List<Sound>();
- foreach (var sound in sounds)
- {
- soundList.Add((Sound)sound);
- }
-
- var sc = new SpellCorrect();
-
- var tSound = soundList.OrderBy(x => sc.Compare(song, x.ToString())).First();
-
- if (sc.Compare(song, tSound.ToString()) > SpellCorrect.ErrorThreshold)
- {
- await _service.SendAudioAsync(Context.Guild, Context.Channel, song);
- }
-
- SoundEffects.Play(song);*/
- }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Audio/AudioService.cs b/DiscoBot/Audio/AudioService.cs
deleted file mode 100644
index a198eb2..0000000
--- a/DiscoBot/Audio/AudioService.cs
+++ /dev/null
@@ -1,95 +0,0 @@
-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>();
-
- public async Task JoinAudio(IGuild guild, IVoiceChannel target)
- {
- if (connectedChannels.TryGetValue(guild.Id, out var client)) return;
-
- if (target.Guild.Id != guild.Id) return;
-
- var audioClient = await target.ConnectAsync();
-
- 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}.");
- }
- }
-
- public async Task LeaveAudio(IGuild guild)
- {
- if (connectedChannels.TryRemove(guild.Id, out var 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) && 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}");
- using (var ffmpeg = CreateStream(path))
- using (var stream = client.CreatePCMStream(AudioApplication.Music))
- {
- try
- {
- await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream);
- }
- finally
- {
- await stream.FlushAsync();
- }
- }
- }
-
- 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;
-
- 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))
- using (var stream = client.CreatePCMStream(AudioApplication.Voice))
- {
- try { await ffmpeg.StandardOutput.BaseStream.CopyToAsync(stream); }
- finally { await stream.FlushAsync(); }
- }
- }*/
- }
-
- private static 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
- });
- }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Audio/Sound.cs b/DiscoBot/Audio/Sound.cs
deleted file mode 100644
index 85023c8..0000000
--- a/DiscoBot/Audio/Sound.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace DiscoBot.Audio
-{
- public class Sound
- {
- public Sound(string name, string url, int volume)
- {
- Name = name;
- Url = url;
- Volume = volume;
- }
-
- public string Name { get; }
-
- public string Url { get; }
-
- public int Volume { get; }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Audio/Voice.cs b/DiscoBot/Audio/Voice.cs
deleted file mode 100644
index c2a3097..0000000
--- a/DiscoBot/Audio/Voice.cs
+++ /dev/null
@@ -1,94 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Threading.Tasks;
-using DiscoBot.Auxiliary;
-using Discord;
-using Discord.Audio;
-using Discord.Commands;
-
-namespace DiscoBot.Audio
-{
- public class Voice : ModuleBase
- {
- public static IAudioClient Client { get; set; }
-
- public static void Send(string path, int volume = 256)
- {
- if (Client == null) throw new NullReferenceException("Bot befindet sich nicht in einem Sprachchannel");
-
- // Create FFmpeg using the previous example
- var ffmpeg = CreateStream(path, volume);
- var output = ffmpeg.StandardOutput.BaseStream;
- var barInvoker = new BackgroundWorker();
- barInvoker.DoWork += delegate
- {
- var discord = Client.CreatePCMStream(AudioApplication.Music);
- output.CopyToAsync(discord);
-
- discord.FlushAsync();
- };
-
- barInvoker.RunWorkerAsync();
- }
-
- [Command("join", RunMode = RunMode.Async)]
- public async Task JoinChannelAsync(IVoiceChannel channel = null)
- {
- var msg = Context.Message;
-
- // Get the audio channel
- channel = channel ?? (msg.Author as IGuildUser)?.VoiceChannel;
- if (channel == null)
- {
- await msg.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.
- var audioClient = await channel.ConnectAsync();
- Client = audioClient;
- }
-
- [Command("leave", RunMode = RunMode.Async)]
- public async Task LeaveChannelAsync(IVoiceChannel channel = null)
- {
-// Permissions.Test(this.Context, "Meister");
-
- if (Client != null)
- {
- await Client.StopAsync();
- Client = null;
- }
- }
-
-
- [Command("play", RunMode = RunMode.Async)]
- public async Task PlayAudioAsync(string path)
- {
- if (Client == null) await Context.Channel.SendMessageAsync("Erst Joinen!");
-
- //SoundEffects.Play(path);
-
- var sounds = Enum.GetValues(typeof(Sound));
- var soundList = new List<Sound>();
- foreach (var sound in sounds) soundList.Add((Sound) sound);
-
- var sc = new SpellCorrect();
- }
-
- private static Process CreateStream(string path, int vol = 256)
- {
- var ffmpeg = new ProcessStartInfo
- {
- FileName = "ffmpeg",
- Arguments = $"-i {path} -ac 2 -f s16le -ar 48000 -ab 620000 -vol {vol} pipe:1",
- UseShellExecute = false,
- RedirectStandardOutput = true
- };
- return Process.Start(ffmpeg);
- }
- }
-} \ No newline at end of file