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/Commands/MiscCommands.cs | 32 +++++++++++ DiscoBot/Commands/ProbenTest.cs | 47 ++++++++++++++++ DiscoBot/Commands/Test.cs | 47 ---------------- DiscoBot/Commands/Utility.cs | 32 ----------- DiscoBot/Commands/Voice.cs | 115 -------------------------------------- 5 files changed, 79 insertions(+), 194 deletions(-) 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/Commands') 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); - } - } -} -- cgit v1.3.1