From ed26623e17e8dfcc036f88cca6de10d5a35697ec Mon Sep 17 00:00:00 2001 From: uzvkl Date: Mon, 20 May 2019 00:54:14 +0200 Subject: Reorganize Code delete ZoBotanica --- DiscoBot/App.config | 4 +- DiscoBot/Audio/AudioModule.cs | 65 ---------------------- DiscoBot/Audio/AudioService.cs | 95 -------------------------------- DiscoBot/Audio/Sound.cs | 18 ------ DiscoBot/Audio/Voice.cs | 94 ------------------------------- DiscoBot/Commands/FileHandler.cs | 2 +- DiscoBot/Commands/MiscCommands.cs | 2 +- DiscoBot/DiscoBot.csproj | 71 +++++++++++++----------- DiscoBot/Program.cs | 4 +- DiscoBot/Properties/Settings.Designer.cs | 2 +- DiscoBot/Token | 1 + DiscoBot/packages.config | 50 ++++++++--------- 12 files changed, 71 insertions(+), 337 deletions(-) delete mode 100644 DiscoBot/Audio/AudioModule.cs delete mode 100644 DiscoBot/Audio/AudioService.cs delete mode 100644 DiscoBot/Audio/Sound.cs delete mode 100644 DiscoBot/Audio/Voice.cs create mode 100644 DiscoBot/Token (limited to 'DiscoBot') diff --git a/DiscoBot/App.config b/DiscoBot/App.config index e99cd82..c862b4e 100644 --- a/DiscoBot/App.config +++ b/DiscoBot/App.config @@ -6,7 +6,7 @@ - + @@ -28,7 +28,7 @@ - + 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(); - 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 connectedChannels = - new ConcurrentDictionary(); - - 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(); - 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 diff --git a/DiscoBot/Commands/FileHandler.cs b/DiscoBot/Commands/FileHandler.cs index 17928c8..4f8a785 100644 --- a/DiscoBot/Commands/FileHandler.cs +++ b/DiscoBot/Commands/FileHandler.cs @@ -8,7 +8,7 @@ namespace DiscoBot.Commands public class FileHandler : ModuleBase { //[Command("send"), Summary("fügt Helden hinzu")] - public async Task AddChar() + public void AddChar() { var msg = Context.Message; if (msg.Attachments == null) throw new ArgumentException("Es wurde keine Datei angehängt"); diff --git a/DiscoBot/Commands/MiscCommands.cs b/DiscoBot/Commands/MiscCommands.cs index 2bc2fad..738796c 100644 --- a/DiscoBot/Commands/MiscCommands.cs +++ b/DiscoBot/Commands/MiscCommands.cs @@ -124,7 +124,7 @@ namespace DiscoBot.Commands [Command("clear")] [Summary("Cleans up messages.")] - public async Task DeleteAsync(int count) + public void DeleteAsync(int count) { var messagesAsync = Context.Channel.GetMessagesAsync(count); if (messagesAsync != null) diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index 28f81a8..09f4cfd 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -8,7 +8,7 @@ Exe DiscoBot DiscoBot - v4.6.1 + v4.7.2 512 true @@ -35,43 +35,44 @@ 4 - - ..\packages\Discord.Net.Commands.2.0.0-beta\lib\netstandard1.1\Discord.Net.Commands.dll + + ..\packages\Discord.Net.Commands.2.1.0\lib\net46\Discord.Net.Commands.dll - - ..\packages\Discord.Net.Core.2.0.0-beta\lib\net45\Discord.Net.Core.dll + + ..\packages\Discord.Net.Core.2.1.0\lib\net46\Discord.Net.Core.dll - - ..\packages\Discord.Net.Rest.2.0.0-beta\lib\net45\Discord.Net.Rest.dll + + ..\packages\Discord.Net.Rest.2.1.0\lib\net46\Discord.Net.Rest.dll ..\packages\Discord.Net.Rpc.1.0.2\lib\net45\Discord.Net.Rpc.dll - - ..\packages\Discord.Net.Webhook.2.0.0-beta\lib\netstandard1.1\Discord.Net.Webhook.dll + + ..\packages\Discord.Net.Webhook.2.1.0\lib\netstandard1.3\Discord.Net.Webhook.dll - - ..\packages\Discord.Net.WebSocket.2.0.0-beta\lib\net45\Discord.Net.WebSocket.dll + + ..\packages\Discord.Net.WebSocket.2.1.0\lib\net46\Discord.Net.WebSocket.dll - - ..\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll + + ..\packages\FSharp.Core.4.6.2\lib\net45\FSharp.Core.dll - ..\packages\Microsoft.Extensions.DependencyInjection.2.2.0-preview2-35157\lib\net461\Microsoft.Extensions.DependencyInjection.dll + ..\packages\Microsoft.Extensions.DependencyInjection.2.2.0\lib\net461\Microsoft.Extensions.DependencyInjection.dll - ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0-preview2-35157\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll ..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll + - - ..\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll ..\packages\System.Interactive.Async.3.2.0\lib\net46\System.Interactive.Async.dll @@ -79,31 +80,43 @@ ..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll - - ..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll + True True ..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll + + ..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll + True + True + + + ..\packages\System.Runtime.Extensions.4.3.1\lib\net462\System.Runtime.Extensions.dll + True + True + False ..\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll True + + ..\packages\System.Text.RegularExpressions.4.3.1\lib\net463\System.Text.RegularExpressions.dll + True + True + - - - - @@ -123,13 +136,7 @@ - - {388dd4ed-29c4-4127-ac8f-34dd3fe9f9b0} - DSALib - - - - + diff --git a/DiscoBot/Program.cs b/DiscoBot/Program.cs index 6ddac5d..4314a8d 100644 --- a/DiscoBot/Program.cs +++ b/DiscoBot/Program.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Net; using System.Reflection; using System.Threading.Tasks; -using DiscoBot.Audio; using Discord; using Discord.Commands; using Discord.WebSocket; @@ -15,7 +14,7 @@ namespace DiscoBot { private DiscordSocketClient client; private CommandService commands; - private IServiceProvider services; + private IServiceProvider services = null; public static void Main(string[] args) { @@ -109,7 +108,6 @@ namespace DiscoBot private static void OnProcessExit(object sender, EventArgs e) { Console.WriteLine("I'm out of here"); - Voice.Client.StopAsync(); } } } \ No newline at end of file diff --git a/DiscoBot/Properties/Settings.Designer.cs b/DiscoBot/Properties/Settings.Designer.cs index 9813b8a..f80dfa5 100644 --- a/DiscoBot/Properties/Settings.Designer.cs +++ b/DiscoBot/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace DiscoBot.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/DiscoBot/Token b/DiscoBot/Token new file mode 100644 index 0000000..4b78e50 --- /dev/null +++ b/DiscoBot/Token @@ -0,0 +1 @@ +Mjk0NTU0MDU4Nzg4NzAwMTYx.DgAvuw.amZ0Ep7-FKjToTf_wnY3h5Ep4Ow \ No newline at end of file diff --git a/DiscoBot/packages.config b/DiscoBot/packages.config index 4aa29aa..75a1f83 100644 --- a/DiscoBot/packages.config +++ b/DiscoBot/packages.config @@ -1,60 +1,60 @@  - - - - + + + + - - - - - - + + + + + + - - + + - + - + - + - - - - + + + + - + - - + + - + - + - + -- cgit v1.3.1