From e5e0c1c5c9fb6afd68ebe9dc075af23f46f11e25 Mon Sep 17 00:00:00 2001 From: TrueDoctor Date: Wed, 11 Apr 2018 14:41:01 +0200 Subject: General Cleanup and retructuring --- DiscoBot/Audio/AudioModule.cs | 89 ++++++++++++++-------------- DiscoBot/Audio/Soundeffects.cs | 60 +++++++++++++++++++ DiscoBot/Audio/Voice.cs | 112 ++++++++++++++++++++++++++++++++++++ DiscoBot/Auxiliary/Misc.cs | 51 ---------------- DiscoBot/Auxiliary/RandomMisc.cs | 51 ++++++++++++++++ DiscoBot/Auxiliary/Soundeffects.cs | 66 --------------------- DiscoBot/Auxiliary/Talent.cs | 2 +- DiscoBot/Characters/Character.cs | 11 ++-- DiscoBot/Characters/NPC.cs | 4 +- DiscoBot/Commands/MiscCommands.cs | 32 +++++++++++ DiscoBot/Commands/ProbenTest.cs | 47 +++++++++++++++ DiscoBot/Commands/Test.cs | 47 --------------- DiscoBot/Commands/Utility.cs | 32 ----------- DiscoBot/Commands/Voice.cs | 115 ------------------------------------- DiscoBot/DiscoBot.csproj | 10 ++-- 15 files changed, 362 insertions(+), 367 deletions(-) create mode 100644 DiscoBot/Audio/Soundeffects.cs create mode 100644 DiscoBot/Audio/Voice.cs delete mode 100644 DiscoBot/Auxiliary/Misc.cs create mode 100644 DiscoBot/Auxiliary/RandomMisc.cs delete mode 100644 DiscoBot/Auxiliary/Soundeffects.cs create mode 100644 DiscoBot/Commands/MiscCommands.cs create mode 100644 DiscoBot/Commands/ProbenTest.cs delete mode 100644 DiscoBot/Commands/Test.cs delete mode 100644 DiscoBot/Commands/Utility.cs delete mode 100644 DiscoBot/Commands/Voice.cs (limited to 'DiscoBot') diff --git a/DiscoBot/Audio/AudioModule.cs b/DiscoBot/Audio/AudioModule.cs index 0c3814f..9eaf1f2 100644 --- a/DiscoBot/Audio/AudioModule.cs +++ b/DiscoBot/Audio/AudioModule.cs @@ -12,61 +12,64 @@ using DiscoBot.Commands; using Discord; using Discord.Commands; -public class AudioModule : ModuleBase +namespace DiscoBot.Audio { - // 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() + public class AudioModule : ModuleBase { - await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel); - } + // Scroll down further for the AudioService. + // Like, way down + private readonly AudioService _service; - // 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); - } + // 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; + } - [Command("_play", RunMode = RunMode.Async)] - public async Task PlayCmd([Remainder] string song) - { - if (Dsa.GeneralContext == null) + // 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() { - Dsa.GeneralContext = this.Context; + await _service.JoinAudio(Context.Guild, (Context.User as IVoiceState).VoiceChannel); } - var sounds = Enum.GetValues(typeof(Sound)); - var soundList = new List(); - foreach (var sound in sounds) + // 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() { - soundList.Add((Sound)sound); + await _service.LeaveAudio(Context.Guild); } - var sc = new SpellCorrect(); + [Command("_play", RunMode = RunMode.Async)] + public async Task PlayCmd([Remainder] string song) + { + if (Dsa.GeneralContext == null) + { + Dsa.GeneralContext = this.Context; + } - var tSound = soundList.OrderBy(x => sc.Compare(song, x.ToString())).First(); + var sounds = Enum.GetValues(typeof(Sound)); + var soundList = new List(); + foreach (var sound in sounds) + { + soundList.Add((Sound)sound); + } - if (sc.Compare(song, tSound.ToString()) > SpellCorrect.ErrorThreshold) - { - await _service.SendAudioAsync(Context.Guild, Context.Channel, song); - } + var sc = new SpellCorrect(); + + var tSound = soundList.OrderBy(x => sc.Compare(song, x.ToString())).First(); - await SoundEffects.Play(tSound); + if (sc.Compare(song, tSound.ToString()) > SpellCorrect.ErrorThreshold) + { + await _service.SendAudioAsync(Context.Guild, Context.Channel, song); + } + + await SoundEffects.Play(tSound); + } } } \ No newline at end of file diff --git a/DiscoBot/Audio/Soundeffects.cs b/DiscoBot/Audio/Soundeffects.cs new file mode 100644 index 0000000..555a79c --- /dev/null +++ b/DiscoBot/Audio/Soundeffects.cs @@ -0,0 +1,60 @@ +namespace DiscoBot.Audio +{ + using System; + using System.Threading.Tasks; + + using DiscoBot.Commands; + + public enum Sound + { + Bell, + Ding, + Nooo, + Monterkill, + Finish, + Wrong, + Magic + } + + public static class SoundEffects + { + public static async Task Play(Sound s) + { + string url = string.Empty; + int vol = 256; + switch (s) + { + case Sound.Bell: + case Sound.Ding: + url = "https://www.myinstants.com/media/sounds/boxing-bell.mp3"; + break; + case Sound.Finish: + url = "https://www.myinstants.com/media/sounds/finishhim.swf.mp3"; + break; + case Sound.Magic: + url = "https://www.myinstants.com/media/sounds/dream-harp-sound-effect.mp3"; + break; + case Sound.Monterkill: + url = "https://www.myinstants.com/media/sounds/announcer_kill_monster_01.mp3"; + break; + case Sound.Nooo: + url = "https://www.myinstants.com/media/sounds/nooo.swf.mp3"; + break; + case Sound.Wrong: + // url = "https://www.myinstants.com/media/sounds/stupid_dum_03.mp3"; + // vol = 10; + url = "https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3"; + vol = 50; + break; + } + + if (url != string.Empty) + { + // await Dsa.Service.SendAudioAsync(url, vol); + await Voice.SendAsync(url, vol); + } + + throw new Exception("Ton Existiert nicht"); + } + } +} diff --git a/DiscoBot/Audio/Voice.cs b/DiscoBot/Audio/Voice.cs new file mode 100644 index 0000000..d1f7915 --- /dev/null +++ b/DiscoBot/Audio/Voice.cs @@ -0,0 +1,112 @@ +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 Discord; + using Discord.Audio; + using Discord.Commands; + + public class Voice : ModuleBase + { + public static IAudioClient Client { get; set; } + + public static async Task SendAsync(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) + { + if (Client != null) + { + var wait = SoundEffects.Play(Sound.Nooo); + await Client.StopAsync(); + Client = null; + wait.Wait(); + } + } + + [Command("play", RunMode = RunMode.Async)] + public async Task PlayAudioAsync(string path) + { + if (Client == null) + { + await this.Context.Channel.SendMessageAsync("Erst Joinen!"); + } + + var sounds = Enum.GetValues(typeof(Sound)); + var soundList = new List(); + foreach (var sound in sounds) + { + soundList.Add((Sound)sound); + } + + var sc = new SpellCorrect(); + + var tSound = soundList.OrderBy(x => sc.Compare(path, x.ToString())).First(); + + if (sc.Compare(path, tSound.ToString()) > SpellCorrect.ErrorThreshold) + { + await Task.Run(() => Voice.SendAsync(path)); + } + + await Task.Run(() => SoundEffects.Play(tSound)); + } + + 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); + } + } +} diff --git a/DiscoBot/Auxiliary/Misc.cs b/DiscoBot/Auxiliary/Misc.cs deleted file mode 100644 index 2531f12..0000000 --- a/DiscoBot/Auxiliary/Misc.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace DiscoBot.Auxiliary -{ - using System; - using System.Linq; - using System.Text; - - public static class Misc - { - private static readonly Random Rand = new Random(); - - // use: 4w6 +4 - public static string Roll(string input) - { - var output = new StringBuilder(); - var strings = input.Split('w', 'd').ToList(); - int count = Convert.ToInt32(strings[0]); - strings = strings[1].Split(' ').ToList(); - int d = Convert.ToInt32(strings[0]); - - if (strings.Count > 0) - { - } - - int sum = 0; - for (int i = 0; i < count; i++) - { - var roll = Dice.Roll(d); - sum += roll; - output.Append("[" + roll + "] "); - } - - if (count > 1) - { - output.Append("sum: " + sum); - } - - return output.ToString(); - } - - public static double Random(double stdDev = 1, double mean = 0) - { - double u1 = Rand.NextDouble(); // uniform(0,1) random doubles - double u2 = Rand.NextDouble(); - double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * - Math.Sin(2.0 * Math.PI * u2); // random normal(0,1) - double randNormal = - mean + stdDev * randStdNormal; // random normal(mean,stdDev^2) - return randNormal; - } - } -} diff --git a/DiscoBot/Auxiliary/RandomMisc.cs b/DiscoBot/Auxiliary/RandomMisc.cs new file mode 100644 index 0000000..b0df456 --- /dev/null +++ b/DiscoBot/Auxiliary/RandomMisc.cs @@ -0,0 +1,51 @@ +namespace DiscoBot.Auxiliary +{ + using System; + using System.Linq; + using System.Text; + + public static class RandomMisc + { + private static readonly Random Rand = new Random(); + + // use: 4w6 +4 + public static string Roll(string input) + { + var output = new StringBuilder(); + var strings = input.Split('w', 'd').ToList(); + int count = Convert.ToInt32(strings[0]); + strings = strings[1].Split(' ').ToList(); + int d = Convert.ToInt32(strings[0]); + + if (strings.Count > 0) + { + } + + int sum = 0; + for (int i = 0; i < count; i++) + { + var roll = Dice.Roll(d); + sum += roll; + output.Append("[" + roll + "] "); + } + + if (count > 1) + { + output.Append("sum: " + sum); + } + + return output.ToString(); + } + + public static double Random(double stdDev = 1, double mean = 0) + { + double u1 = Rand.NextDouble(); // uniform(0,1) random doubles + double u2 = Rand.NextDouble(); + double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) * + Math.Sin(2.0 * Math.PI * u2); // random normal(0,1) + double randNormal = + mean + stdDev * randStdNormal; // random normal(mean,stdDev^2) + return randNormal; + } + } +} diff --git a/DiscoBot/Auxiliary/Soundeffects.cs b/DiscoBot/Auxiliary/Soundeffects.cs deleted file mode 100644 index c959156..0000000 --- a/DiscoBot/Auxiliary/Soundeffects.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DiscoBot.Auxiliary -{ - using System.Runtime.CompilerServices; - using System.Threading; - - using DiscoBot.Commands; - - public enum Sound - { - Bell, - Ding, - Nooo, - Monterkill, - Finish, - Wrong, - Magic - } - - public static class SoundEffects - { - public static async Task Play(Sound s) - { - string url = string.Empty; - int vol = 256; - switch (s) - { - case Sound.Bell: - case Sound.Ding: - url = "https://www.myinstants.com/media/sounds/boxing-bell.mp3"; - break; - case Sound.Finish: - url = "https://www.myinstants.com/media/sounds/finishhim.swf.mp3"; - break; - case Sound.Magic: - url = "https://www.myinstants.com/media/sounds/dream-harp-sound-effect.mp3"; - break; - case Sound.Monterkill: - url = "https://www.myinstants.com/media/sounds/announcer_kill_monster_01.mp3"; - break; - case Sound.Nooo: - url = "https://www.myinstants.com/media/sounds/nooo.swf.mp3"; - break; - case Sound.Wrong: - // url = "https://www.myinstants.com/media/sounds/stupid_dum_03.mp3"; - // vol = 10; - url = "https://www.myinstants.com/media/sounds/wrong-answer-sound-effect.mp3"; - vol = 50; - break; - } - - if (url != string.Empty) - { - // await Dsa.Service.SendAudioAsync(url, vol); - await Voice.SendAsync(url, vol); - } - - throw new Exception("Ton Existiert nicht"); - } - } -} diff --git a/DiscoBot/Auxiliary/Talent.cs b/DiscoBot/Auxiliary/Talent.cs index 969304c..e93aa18 100644 --- a/DiscoBot/Auxiliary/Talent.cs +++ b/DiscoBot/Auxiliary/Talent.cs @@ -17,7 +17,7 @@ public int Value { get; set; } - public string[] Test() // turn XX/XX/XX into string[]{XX,XX,XX} + public string[] GetEigenschaften() // turn XX/XX/XX into string[]{XX,XX,XX} { var temp = this.Probe.Split('/'); for (var index = 0; index < temp.Length; index++) diff --git a/DiscoBot/Characters/Character.cs b/DiscoBot/Characters/Character.cs index 6884eaf..9d84fa8 100644 --- a/DiscoBot/Characters/Character.cs +++ b/DiscoBot/Characters/Character.cs @@ -6,6 +6,7 @@ using System.Text; using System.Xml; + using DiscoBot.Audio; using DiscoBot.Auxiliary; public class Character : ICharacter @@ -33,22 +34,22 @@ this.Name = name; foreach (var i in c.Eigenschaften) { - this.Eigenschaften.Add(i.Key, i.Value + (int)Math.Round(Misc.Random(stDv))); + this.Eigenschaften.Add(i.Key, i.Value + (int)Math.Round(RandomMisc.Random(stDv))); } foreach (var i in c.Vorteile) { - this.Vorteile.Add(new Vorteil(i.Name, i.Value + (int)Math.Round(Misc.Random(stDv)))); + this.Vorteile.Add(new Vorteil(i.Name, i.Value + (int)Math.Round(RandomMisc.Random(stDv)))); } foreach (var i in c.Talente) { - this.Talente.Add(new Talent(i.Name, i.Probe, i.Value + (int)Math.Round(Misc.Random(stDv)))); + this.Talente.Add(new Talent(i.Name, i.Probe, i.Value + (int)Math.Round(RandomMisc.Random(stDv)))); } foreach (var i in c.Kampftalente) { - this.Kampftalente.Add(new KampfTalent(i.Name, i.At + (int)Math.Round(Misc.Random(stDv)), i.Pa + (int)Math.Round(Misc.Random(stDv)))); + this.Kampftalente.Add(new KampfTalent(i.Name, i.At + (int)Math.Round(RandomMisc.Random(stDv)), i.Pa + (int)Math.Round(RandomMisc.Random(stDv)))); } } @@ -80,7 +81,7 @@ return $"{this.Name} kann nicht {talent}..."; } - var props = tTalent.Test(); // get the required properties + var props = tTalent.GetEigenschaften(); // get the required properties int tap = tTalent.Value; // get taw var werte = props.Select(p => this.Eigenschaften[this.PropTable[p]]).ToList(); diff --git a/DiscoBot/Characters/NPC.cs b/DiscoBot/Characters/NPC.cs index f399a70..341f775 100644 --- a/DiscoBot/Characters/NPC.cs +++ b/DiscoBot/Characters/NPC.cs @@ -25,7 +25,7 @@ { // foreach property, dice and tap int temp = Dice.Roll(); - int eigenschaft = (int)Math.Round(Misc.Random(this.stDv, this.mean)); + int eigenschaft = (int)Math.Round(RandomMisc.Random(this.stDv, this.mean)); if (eigenschaft < temp) { @@ -45,7 +45,7 @@ public string TestEigenschaft(string eigenschaft, int erschwernis = 0) { int temp = Dice.Roll(); - int prop = (int)Math.Round(Misc.Random(this.stDv, this.stDv)); + int prop = (int)Math.Round(RandomMisc.Random(this.stDv, this.stDv)); if (temp + erschwernis < prop) { diff --git a/DiscoBot/Commands/MiscCommands.cs b/DiscoBot/Commands/MiscCommands.cs new file mode 100644 index 0000000..c067507 --- /dev/null +++ b/DiscoBot/Commands/MiscCommands.cs @@ -0,0 +1,32 @@ +namespace DiscoBot.Commands +{ + using System.Threading.Tasks; + + using DiscoBot.Auxiliary; + + using Discord.Commands; + + public class MiscCommands : ModuleBase + { + [Command("r"), Summary("Würfelt ")] + [Alias("R", "Roll", "roll", "Würfle")] + public Task RollAsync([Remainder, Summary("Weapon")] string roll) + { + return this.ReplyAsync("```xl\n" + RandomMisc.Roll(roll) + "\n```"); + } + + [Command("general"), Summary("Set General ")] + public Task SetGeneralAsync([Remainder, Summary("Set General")] int i = 0) + { + Dsa.GeneralContext = this.Context; + return this.Context.Channel.SendMessageAsync($"```xl\n Der Dachs hat in '{this.Context.Channel.Name}' ein Zuhause gefunden. Gm Nachrichten werden nun auch in diesem Channel gepostet. \n```"); + } + + [Command("say"), Summary("Echos a message.")] + [Alias("s")] + public Task SayAsync([Remainder, Summary("The text to echo")] string echo) + { + return this.ReplyAsync(echo); + } + } +} diff --git a/DiscoBot/Commands/ProbenTest.cs b/DiscoBot/Commands/ProbenTest.cs new file mode 100644 index 0000000..a73f4fd --- /dev/null +++ b/DiscoBot/Commands/ProbenTest.cs @@ -0,0 +1,47 @@ +namespace DiscoBot.Commands +{ + using System.Threading.Tasks; + + using Discord.Commands; + + public class ProbenTest : ModuleBase + { + [Command("t"), Summary("Würfelt ein Talent-/Zauberprobe")] + [Alias("T", "Talent", "talent", "zauber", "z", "versuche")] + public Task TalentAsync([Summary("Talent oder Zaubername")] string talent, int erschwernis = 0) + { + string res = Gm.CheckCommand(Dsa.Relation[this.Context.User.Username], CommandTypes.Talent, talent, erschwernis); + return this.ReplyAsync("```xl\n" + res + "\n```"); + } + + [Command("e"), Summary("Würfelt eine Eigenschaftsprobe")] + [Alias("E", "Eigenschaft", "eigenschaft", "eigen")] + public Task EigenschaftAsync([Summary("Eigenschaftskürzel und Erschwernis")] string talent, int erschwernis = 0) + { + var chr = Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])); + string res = chr.TestEigenschaft(talent, erschwernis); + return this.ReplyAsync("```xl\n" + res + "\n```"); + } + + [Command("a"), Summary("Würfelt ein Angriff")] + [Alias("At", "at", "Angriff", "angriff", "attackiere_mit", "attacke", "Attacke")] + public Task AngriffAsync([Summary("Weapon")] string weapon, int erschwernis = 0) + { + return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])).Angriff(weapon, erschwernis) + "\n```"); + } + + [Command("p"), Summary("Würfelt eine Parade Probe")] + [Alias("P", "Parade", "parade", "pariere_mit")] + public Task ParadeAsync([Summary("Parade Weapon")] string talent, int erschwernis = 0) + { + return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])).Parade(talent, erschwernis) + "\n```"); + } + + [Command("f"), Summary("Führt eine Fernkampfprobe aus")] + [Alias("F", "fernkampf", "Fernkampf", "schieße", "schieße_mit")] + public Task FernkampfAsync([Summary("Fernkampfwaffe")] string waffe, int erschwernis = 0) + { + return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])).Fernkampf(waffe, erschwernis) + "\n```"); + } + } +} diff --git a/DiscoBot/Commands/Test.cs b/DiscoBot/Commands/Test.cs deleted file mode 100644 index d56a43c..0000000 --- a/DiscoBot/Commands/Test.cs +++ /dev/null @@ -1,47 +0,0 @@ -namespace DiscoBot.Commands -{ - using System.Threading.Tasks; - - using Discord.Commands; - - public class Test : ModuleBase - { - [Command("t"), Summary("Würfelt ein Talent-/Zauberprobe")] - [Alias("T", "Talent", "talent", "zauber", "z", "versuche")] - public Task TalentAsync([Summary("Talent oder Zaubername")] string talent, int erschwernis = 0) - { - string res = Gm.CheckCommand(Dsa.Relation[this.Context.User.Username], CommandTypes.Talent, talent, erschwernis); - return this.ReplyAsync("```xl\n" + res + "\n```"); - } - - [Command("e"), Summary("Würfelt eine Eigenschaftsprobe")] - [Alias("E", "Eigenschaft", "eigenschaft", "eigen")] - public Task EigenschaftAsync([Summary("Eigenschaftskürzel und Erschwernis")] string talent, int erschwernis = 0) - { - var chr = Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])); - string res = chr.TestEigenschaft(talent, erschwernis); - return this.ReplyAsync("```xl\n" + res + "\n```"); - } - - [Command("a"), Summary("Würfelt ein Angriff")] - [Alias("At", "at", "Angriff", "angriff", "attackiere_mit", "attacke", "Attacke")] - public Task AngriffAsync([Summary("Weapon")] string weapon, int erschwernis = 0) - { - return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])).Angriff(weapon, erschwernis) + "\n```"); - } - - [Command("p"), Summary("Würfelt eine Parade Probe")] - [Alias("P", "Parade", "parade", "pariere_mit")] - public Task ParadeAsync([Summary("Parade Weapon")] string talent, int erschwernis = 0) - { - return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])).Parade(talent, erschwernis) + "\n```"); - } - - [Command("f"), Summary("Führt eine Fernkampfprobe aus")] - [Alias("F", "fernkampf", "Fernkampf", "schieße", "schieße_mit")] - public Task FernkampfAsync([Summary("Fernkampfwaffe")] string waffe, int erschwernis = 0) - { - return this.ReplyAsync("```xl\n" + Dsa.Chars.Find(x => x.Name.Equals(Dsa.Relation[this.Context.User.Username])).Fernkampf(waffe, erschwernis) + "\n```"); - } - } -} diff --git a/DiscoBot/Commands/Utility.cs b/DiscoBot/Commands/Utility.cs deleted file mode 100644 index bbba1a1..0000000 --- a/DiscoBot/Commands/Utility.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace DiscoBot.Commands -{ - using System.Threading.Tasks; - - using DiscoBot.Auxiliary; - - using Discord.Commands; - - public class Utility : ModuleBase - { - [Command("r"), Summary("Würfelt ")] - [Alias("R", "Roll", "roll", "Würfle")] - public Task RollAsync([Remainder, Summary("Weapon")] string roll) - { - return this.ReplyAsync("```xl\n" + Misc.Roll(roll) + "\n```"); - } - - [Command("general"), Summary("Set General ")] - public Task SetGeneralAsync([Remainder, Summary("Set General")] int i = 0) - { - Dsa.GeneralContext = this.Context; - return this.Context.Channel.SendMessageAsync($"```xl\n Der Dachs hat in '{this.Context.Channel.Name}' ein Zuhause gefunden. Gm Nachrichten werden nun auch in diesem Channel gepostet. \n```"); - } - - [Command("say"), Summary("Echos a message.")] - [Alias("s")] - public Task SayAsync([Remainder, Summary("The text to echo")] string echo) - { - return this.ReplyAsync(echo); - } - } -} diff --git a/DiscoBot/Commands/Voice.cs b/DiscoBot/Commands/Voice.cs deleted file mode 100644 index 9e94a30..0000000 --- a/DiscoBot/Commands/Voice.cs +++ /dev/null @@ -1,115 +0,0 @@ -namespace DiscoBot.Commands -{ - using System; - using System.Collections.Generic; - using System.ComponentModel; - using System.Diagnostics; - using System.Linq; - using System.Media; - using System.Threading; - using System.Threading.Tasks; - - using DiscoBot.Audio; - using DiscoBot.Auxiliary; - - using Discord; - using Discord.Audio; - using Discord.Commands; - - public class Voice : ModuleBase - { - public static IAudioClient Client { get; set; } - - public static async Task SendAsync(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) - { - if (Client != null) - { - var wait = SoundEffects.Play(Sound.Nooo); - await Client.StopAsync(); - Client = null; - wait.Wait(); - } - } - - [Command("play", RunMode = RunMode.Async)] - public async Task PlayAudioAsync(string path) - { - if (Client == null) - { - await this.Context.Channel.SendMessageAsync("Erst Joinen!"); - } - - var sounds = Enum.GetValues(typeof(Sound)); - var soundList = new List(); - foreach (var sound in sounds) - { - soundList.Add((Sound)sound); - } - - var sc = new SpellCorrect(); - - var tSound = soundList.OrderBy(x => sc.Compare(path, x.ToString())).First(); - - if (sc.Compare(path, tSound.ToString()) > SpellCorrect.ErrorThreshold) - { - await Task.Run(() => Voice.SendAsync(path)); - } - - await Task.Run(() => SoundEffects.Play(tSound)); - } - - 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); - } - } -} diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index 899a485..b6635ea 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -144,7 +144,8 @@ - + + @@ -155,11 +156,10 @@ - - - + + - + -- cgit v1.2.3-70-g09d2