summaryrefslogtreecommitdiff
path: root/DiscoBot/Audio
diff options
context:
space:
mode:
Diffstat (limited to 'DiscoBot/Audio')
-rw-r--r--DiscoBot/Audio/AudioModule.cs77
-rw-r--r--DiscoBot/Audio/AudioService.cs101
-rw-r--r--DiscoBot/Audio/Sound.cs24
-rw-r--r--DiscoBot/Audio/Soundeffects.cs93
-rw-r--r--DiscoBot/Audio/Voice.cs117
5 files changed, 0 insertions, 412 deletions
diff --git a/DiscoBot/Audio/AudioModule.cs b/DiscoBot/Audio/AudioModule.cs
deleted file mode 100644
index f8834f3..0000000
--- a/DiscoBot/Audio/AudioModule.cs
+++ /dev/null
@@ -1,77 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Threading.Tasks;
-
-using DiscoBot;
-using DiscoBot.Audio;
-using DiscoBot.Auxiliary;
-using DiscoBot.Commands;
-
-using Discord;
-using Discord.Commands;
-
-namespace DiscoBot.Audio
-{
- using DiscoBot.DSA_Game;
-
- 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)
- {
- _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 6e01980..0000000
--- a/DiscoBot/Audio/AudioService.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-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;
-
- public class AudioService
- {
- 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 (target.Guild.Id != guild.Id)
- {
- return;
- }
-
- var audioClient = await target.ConnectAsync();
-
- if (this.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 (this.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 (this.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 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;
- }
-
- if (this.connectedChannels.TryGetValue(Dsa.GeneralContext.Guild.Id, out var client))
- {
- //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 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
- });
- }
- }
-}
diff --git a/DiscoBot/Audio/Sound.cs b/DiscoBot/Audio/Sound.cs
deleted file mode 100644
index a9a2768..0000000
--- a/DiscoBot/Audio/Sound.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace DiscoBot.Audio
-{
- public class Sound
- {
- public Sound(string name, string url, int volume)
- {
- this.Name = name;
- this.Url = url;
- this.Volume = volume;
- }
-
- public string Name { get; }
-
- public string Url { get; }
-
- public int Volume { get; }
- }
-}
diff --git a/DiscoBot/Audio/Soundeffects.cs b/DiscoBot/Audio/Soundeffects.cs
deleted file mode 100644
index f3a014c..0000000
--- a/DiscoBot/Audio/Soundeffects.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-namespace DiscoBot.Audio
-{
- using System;
- using System.Linq;
- using System.Threading.Tasks;
-
- using DiscoBot.Auxiliary;
- using DiscoBot.Commands;
- using DiscoBot.DSA_Game;
-
- /*public enum Sound
- {
- Bell,
- Ding,
- Nooo,
- Monsterkill,
- Finish,
- Wrong,
- Magic,
- Stupid,
- Police,
- Roblox
- }*/
-
- public static class SoundEffects
- {
- public static int MaxVolume { get; set; } = 50;
-
- public static void Play(string s)
- {
- string url = string.Empty;
- int volume = 255;
-
- var tSound = DSA_Game.Save.Properties.Sounds.OrderBy(x => SpellCorrect.CompareEasy(s, x.Name)).First();
-
- url = s;
-
- switch (s)
- {
- case "Bell":
- case "Ding":
- url = "https://www.myinstants.com/media/sounds/boxing-bell.mp3";
- break;
- case "Finish":
- url = "https://www.myinstants.com/media/sounds/finishhim.swf.mp3";
- break;
- case "Magic":
- url = "https://www.myinstants.com/media/sounds/dream-harp-sound-effect.mp3";
- break;
- case "Monsterkill":
- url = "https://www.myinstants.com/media/sounds/announcer_kill_monster_01.mp3";
- break;
- case "Nooo":
- url = "https://www.myinstants.com/media/sounds/nooo.swf.mp3";
- break;
- case "Roblox":
- url = "https://www.myinstants.com/media/sounds/roblox-death-sound_ytkBL7X.mp3";
- break;
- case "Stupid":
- url = "https://www.myinstants.com/media/sounds/stupid_dum_03.mp3";
- volume = 10;
- break;
- case "Police":
- url = "https://www.myinstants.com/media/sounds/sound-of-the-police.mp3";
- break;
- case "Wrong":
- url = "https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3";
- volume = 50;
- break;
- }
-
-
-
- if (SpellCorrect.CompareEasy(s, tSound.Name) < SpellCorrect.ErrorThreshold)
- {
- url = tSound.Url;
- volume = tSound.Volume;
- }
-
- volume = (int)(volume * (MaxVolume / 100.0));
-
-
- if (url != string.Empty)
- {
- // await Dsa.Service.SendAudioAsync(url, vol);
- Voice.Send(url, volume);
- return;
- }
-
- throw new Exception("Ton Existiert nicht");
- }
- }
-}
diff --git a/DiscoBot/Audio/Voice.cs b/DiscoBot/Audio/Voice.cs
deleted file mode 100644
index 379f65b..0000000
--- a/DiscoBot/Audio/Voice.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-namespace DiscoBot.Audio
-{
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Linq;
- using System.Threading.Tasks;
-
- using DiscoBot.Auxiliary;
- using DiscoBot.DSA_Game;
-
- using Discord;
- using Discord.Audio;
- using Discord.Commands;
- using Discord.WebSocket;
-
- 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 = this.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)
- {
- SoundEffects.Play("Nooo");
- await Client.StopAsync();
- Client = null;
- }
- }
-
- [Command("volume")]
- public void SetVolume(int volume)
- {
- if (volume <= 100 && volume >= 0)
- {
- SoundEffects.MaxVolume = volume;
- }
- }
-
- [Command("play", RunMode = RunMode.Async)]
- public async Task PlayAudioAsync(string path)
- {
- if (Client == null)
- {
- await this.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);
- }
- }
-}