diff options
author | Dennis Kobert <d-kobert@web.de> | 2017-11-03 20:07:03 +0100 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2017-11-03 20:07:03 +0100 |
commit | e49ac2778bb6d38517f14447c0675df354552528 (patch) | |
tree | b549066769229d8c7b189efad8ac5bc2dda08015 /DiscoBot | |
parent | 2fe5af08ab78e01ddda7fe31ab08526eb9a11f14 (diff) | |
parent | d59a67e552628b464f079bccae20349d649bdd61 (diff) |
test
Diffstat (limited to 'DiscoBot')
-rw-r--r-- | DiscoBot/App.config | 34 | ||||
-rw-r--r-- | DiscoBot/AppControll.cs | 197 | ||||
-rw-r--r-- | DiscoBot/Char.cs | 120 | ||||
-rw-r--r-- | DiscoBot/Commands.cs | 64 | ||||
-rw-r--r-- | DiscoBot/DiscoBot.csproj | 117 | ||||
-rw-r--r-- | DiscoBot/MyBot.cs | 113 | ||||
-rw-r--r-- | DiscoBot/Program.cs | 63 | ||||
-rw-r--r-- | DiscoBot/Properties/AssemblyInfo.cs | 2 | ||||
-rw-r--r-- | DiscoBot/Properties/Settings.Designer.cs | 38 | ||||
-rw-r--r-- | DiscoBot/Properties/Settings.settings | 9 | ||||
-rw-r--r-- | DiscoBot/ServerControl.cs | 59 | ||||
-rw-r--r-- | DiscoBot/packages.config | 64 |
12 files changed, 405 insertions, 475 deletions
diff --git a/DiscoBot/App.config b/DiscoBot/App.config index fb543e1..f107529 100644 --- a/DiscoBot/App.config +++ b/DiscoBot/App.config @@ -1,18 +1,22 @@ -<?xml version="1.0" encoding="utf-8" ?> +<?xml version="1.0" encoding="utf-8"?> <configuration> - <configSections> - <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > - <section name="DiscoBot.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> - </sectionGroup> - </configSections> <startup> - <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> - <userSettings> - <DiscoBot.Properties.Settings> - <setting name="ServerPaht" serializeAs="String"> - <value>C:\Users\Dennis\Downloads\FTBBeyondServer</value> - </setting> - </DiscoBot.Properties.Settings> - </userSettings> -</configuration>
\ No newline at end of file + <runtime> + <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> + <dependentAssembly> + <assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" /> + </dependentAssembly> + <dependentAssembly> + <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> + <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" /> + </dependentAssembly> + </assemblyBinding> + </runtime> +</configuration> diff --git a/DiscoBot/AppControll.cs b/DiscoBot/AppControll.cs deleted file mode 100644 index c32f3a2..0000000 --- a/DiscoBot/AppControll.cs +++ /dev/null @@ -1,197 +0,0 @@ -using System; -using System.Diagnostics; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - -namespace DiscoBot -{ - public class ConsoleAppManager - { - private readonly string appName; - private readonly Process process = new Process(); - private readonly object theLock = new object(); - private SynchronizationContext context; - private string pendingWriteData; - - public ConsoleAppManager(string appName) - { - this.appName = appName; - - this.process.StartInfo.FileName = this.appName; - this.process.StartInfo.RedirectStandardError = true; - this.process.StartInfo.StandardErrorEncoding = Encoding.UTF8; - - this.process.StartInfo.RedirectStandardInput = true; - this.process.StartInfo.RedirectStandardOutput = true; - this.process.EnableRaisingEvents = true; - this.process.StartInfo.CreateNoWindow = true; - - this.process.StartInfo.UseShellExecute = false; - - this.process.StartInfo.StandardOutputEncoding = Encoding.UTF8; - - this.process.Exited += this.ProcessOnExited; - } - - public event EventHandler<string> ErrorTextReceived; - public event EventHandler ProcessExited; - public event EventHandler<string> StandartTextReceived; - - public int ExitCode - { - get { return this.process.ExitCode; } - } - - public bool Running - { - get; private set; - } - - public void ExecuteAsync(params string[] args) - { - if (this.Running) - { - throw new InvalidOperationException( - "Process is still Running. Please wait for the process to complete."); - } - - string arguments = string.Join(" ", args); - - this.process.StartInfo.Arguments = arguments; - - this.context = SynchronizationContext.Current; - - this.process.Start(); - this.Running = true; - - new Task(this.ReadOutputAsync).Start(); - new Task(this.WriteInputTask).Start(); - new Task(this.ReadOutputErrorAsync).Start(); - } - - public void Write(string data) - { - if (data == null) - { - return; - } - - lock (this.theLock) - { - this.pendingWriteData = data; - } - } - - public void WriteLine(string data) - { - this.Write(data + Environment.NewLine); - } - - protected virtual void OnErrorTextReceived(string e) - { - EventHandler<string> handler = this.ErrorTextReceived; - - if (handler != null) - { - if (this.context != null) - { - this.context.Post(delegate { handler(this, e); }, null); - } - else - { - handler(this, e); - } - } - } - - protected virtual void OnProcessExited() - { - EventHandler handler = this.ProcessExited; - if (handler != null) - { - handler(this, EventArgs.Empty); - } - } - - protected virtual void OnStandartTextReceived(string e) - { - EventHandler<string> handler = this.StandartTextReceived; - - if (handler != null) - { - if (this.context != null) - { - this.context.Post(delegate { handler(this, e); }, null); - } - else - { - handler(this, e); - } - } - } - - private void ProcessOnExited(object sender, EventArgs eventArgs) - { - this.OnProcessExited(); - } - - private async void ReadOutputAsync() - { - var standart = new StringBuilder(); - char[] buff = new char[1024]; - int length; - - while (this.process.HasExited == false) - { - standart.Clear(); - - length = await this.process.StandardOutput.ReadAsync(buff, 0, buff.Length); - char[] temp = new char[1024]; - Array.Copy(buff, temp, length); - standart.Append(temp); - this.OnStandartTextReceived(standart.ToString()); - Thread.Sleep(1); - } - - this.Running = false; - } - - private async void ReadOutputErrorAsync() - { - var sb = new StringBuilder(); - - do - { - sb.Clear(); - var buff = new char[1024]; - int length = await this.process.StandardError.ReadAsync(buff, 0, buff.Length); - char[] temp = new char[1024]; - Array.Copy(buff, temp, length); - sb.Append(temp); - this.OnErrorTextReceived(sb.ToString()); - Thread.Sleep(1); - } - while (this.process.HasExited == false); - } - - private async void WriteInputTask() - { - while (this.process.HasExited == false) - { - Thread.Sleep(1); - - if (this.pendingWriteData != null) - { - await this.process.StandardInput.WriteLineAsync(this.pendingWriteData); - await this.process.StandardInput.FlushAsync(); - - lock (this.theLock) - { - this.pendingWriteData = null; - } - } - } - } - } -}
\ No newline at end of file diff --git a/DiscoBot/Char.cs b/DiscoBot/Char.cs new file mode 100644 index 0000000..28ed7b9 --- /dev/null +++ b/DiscoBot/Char.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace DiscoBot +{ + public class Char + { + + string name; + public Dictionary<string, int> eigenschaften = new Dictionary<string, int>(); + public List<Talent> talente = new List<Talent>(); + public List<Kampf> kampftalente = new List<Kampf>(); + + public Dictionary<string, string> Proptable = new Dictionary<string, string>(); + + + public Char(String path = "Felis.xml") + { + + Load(path); + } + + private void Load(string path) + { + XmlTextReader reader = new XmlTextReader(path); + while (reader.Read()) + { + if (reader.NodeType == XmlNodeType.Element) + switch (reader.Name) + { + case "held": + name = reader.GetAttribute("name"); + break; + case "eigenschaft": + eigenschaften.Add(reader.GetAttribute("name"), Convert.ToInt32(reader.GetAttribute("value")) + Convert.ToInt32(reader.GetAttribute("mod"))); + break; + case "talentliste": + reader.Read(); + while (reader.Name.Equals("talent")) + { + talente.Add(new Talent(reader.GetAttribute("name"), reader.GetAttribute("probe").Remove(0, 2).Trim(')'), Convert.ToInt32(reader.GetAttribute("value")))); + reader.Read(); + } + break; + case "kampfwerte": + string atname = reader.GetAttribute("name"); + reader.Read(); + int at = Convert.ToInt32(reader.GetAttribute("value")); + reader.Read(); + int pa = Convert.ToInt32(reader.GetAttribute("value")); + kampftalente.Add(new Kampf(atname, at, pa)); + break; + } + + + + } + Proptable.Add("MU", "Mut"); + Proptable.Add("KL", "Klugheit"); + Proptable.Add("IN", "Intuition"); + Proptable.Add("CH", "Charisma"); + Proptable.Add("FF", "Fingerfertigkeit"); + Proptable.Add("GE", "Gewandtheit"); + Proptable.Add("KO", "Konstitution"); + Proptable.Add("KK", "Körperkraft"); + + } + public string TestTalent(string talent) + { + var output = new StringBuilder(); + var ttalent = talente.Find(v => v.name.Equals(talent)); + var props =ttalent.Test(); + int tap = ttalent.value; + for (int i = 0; i <= 2; i++) + { + int temp = dice.Rolld20(); + int eigenschaft = eigenschaften[Proptable[props[i]]]; + if (eigenschaft < temp) + tap -= temp - eigenschaft ; + output.Append(temp+" "); + } + output.Append("tap: "+ tap); + return output.ToString(); + } + + } + public class Talent + { + public string name, probe; + public int value; + public Talent(string name, string probe, int value) { this.name = name; this.probe = probe; this.value = value; } + public string[] Test() + { + var temp = probe.Split('/'); + foreach (string s in temp) + s.Replace("/", ""); + return temp; + } + + } + public class Kampf + { + string name; + private int at, pa; + public Kampf(string name, int at, int pa) { this.name = name; this.at = at; this.pa = pa; } + void Test() { } + } + public static class dice + { + static System.Random rnd = new System.Random(); + public static int Rolld20() + { + return rnd.Next(1,21) ; + } + } +} diff --git a/DiscoBot/Commands.cs b/DiscoBot/Commands.cs new file mode 100644 index 0000000..6984761 --- /dev/null +++ b/DiscoBot/Commands.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord; +using Discord.Commands; +using Discord.WebSocket; + + +namespace DiscoBot +{ + class Commands + { + } + public class Info : ModuleBase + { + // ~say hello -> hello + [Command("say"), Summary("Echos a message.")] + public async Task Say([Remainder, Summary("The text to echo")] string echo) + { + + + // ReplyAsync is a method on ModuleBase + await ReplyAsync(echo); + + } + } + + public class Abfrage : ModuleBase + { + Char test = new Char(); + // ~say hello -> hello + [Command("t"), Summary("tests a talent.")] + public async Task Say([Remainder, Summary("The text to echo")] string talent) + { + // ReplyAsync is a method on ModuleBase + + await ReplyAsync("```xl\n" + test.TestTalent(talent) + "\n```"); + + } + } + + [Group("sample")] + public class Sample : ModuleBase + { + // ~sample square 20 -> 400 + [Command("square"), Summary("Squares a number.")] + public async Task Square([Summary("The number to square.")] int num) + { + // We can also access the channel from the Command Context. + await Context.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}"); + } + + [Command("userinfo"), Summary("Returns info about the current user, or the user parameter, if one passed.")] + [Alias("user", "whois")] + public async Task UserInfo([Summary("The (optional) user to get info for")] IUser user = null) + { + var userInfo = user ?? Context.Client.CurrentUser; + await ReplyAsync($"{userInfo.Username}#{userInfo.Discriminator}"); + } + } + +} diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj index b2ff7bd..9920f40 100644 --- a/DiscoBot/DiscoBot.csproj +++ b/DiscoBot/DiscoBot.csproj @@ -4,13 +4,14 @@ <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{1273D5D1-9F46-492F-9DFE-0098CD00405C}</ProjectGuid> + <ProjectGuid>{1186AF1C-BC46-4B3D-BEE0-CE478B8AEAC7}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>DiscoBot</RootNamespace> <AssemblyName>DiscoBot</AssemblyName> - <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <TargetFrameworkProfile /> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> @@ -32,57 +33,111 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> - <Reference Include="Discord.Net, Version=0.9.6.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Discord.Net.0.9.6\lib\net45\Discord.Net.dll</HintPath> + <Reference Include="Discord.Net.Commands, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Commands.1.0.1\lib\netstandard1.1\Discord.Net.Commands.dll</HintPath> </Reference> - <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> + <Reference Include="Discord.Net.Core, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Core.1.0.1\lib\net45\Discord.Net.Core.dll</HintPath> </Reference> - <Reference Include="Nito.AsyncEx, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll</HintPath> + <Reference Include="Discord.Net.Rest, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Rest.1.0.1\lib\net45\Discord.Net.Rest.dll</HintPath> </Reference> - <Reference Include="Nito.AsyncEx.Concurrent, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.Concurrent.dll</HintPath> + <Reference Include="Discord.Net.Rpc, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Rpc.1.0.1\lib\net45\Discord.Net.Rpc.dll</HintPath> </Reference> - <Reference Include="Nito.AsyncEx.Enlightenment, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.Enlightenment.dll</HintPath> + <Reference Include="Discord.Net.Webhook, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.Webhook.1.0.1\lib\netstandard1.1\Discord.Net.Webhook.dll</HintPath> </Reference> - <Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL"> - <HintPath>..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath> + <Reference Include="Discord.Net.WebSocket, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL"> + <HintPath>..\packages\Discord.Net.WebSocket.1.0.1\lib\net45\Discord.Net.WebSocket.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.DependencyInjection, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.1.1.1\lib\netstandard1.1\Microsoft.Extensions.DependencyInjection.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.1.1.1\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath> + </Reference> + <Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath> + </Reference> + <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> + <HintPath>..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> <Reference Include="System" /> + <Reference Include="System.AppContext, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll</HintPath> + </Reference> + <Reference Include="System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System.ComponentModel.Composition" /> + <Reference Include="System.Console, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Console.4.3.0\lib\net46\System.Console.dll</HintPath> + </Reference> <Reference Include="System.Core" /> - <Reference Include="System.Drawing" /> - <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Diagnostics.DiagnosticSource.4.3.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath> + </Reference> + <Reference Include="System.Globalization.Calendars, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll</HintPath> + </Reference> + <Reference Include="System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net46\System.Interactive.Async.dll</HintPath> + </Reference> + <Reference Include="System.IO.Compression, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll</HintPath> + </Reference> + <Reference Include="System.IO.Compression.FileSystem" /> + <Reference Include="System.IO.Compression.ZipFile, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"> + <HintPath>..\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll</HintPath> + </Reference> + <Reference Include="System.IO.FileSystem, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll</HintPath> + </Reference> + <Reference Include="System.IO.FileSystem.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath> + </Reference> + <Reference Include="System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Net.Http.4.3.0\lib\net46\System.Net.Http.dll</HintPath> + </Reference> + <Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath> + </Reference> + <Reference Include="System.Numerics" /> + <Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath> + </Reference> + <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath> + </Reference> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Data" /> - <Reference Include="System.Net.Http" /> <Reference Include="System.Xml" /> - <Reference Include="WebSocket4Net, Version=0.14.1.0, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL"> - <HintPath>..\packages\WebSocket4Net.0.14.1\lib\net45\WebSocket4Net.dll</HintPath> + <Reference Include="System.Xml.ReaderWriter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> + <HintPath>..\packages\System.Xml.ReaderWriter.4.3.0\lib\net46\System.Xml.ReaderWriter.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> - <Compile Include="MyBot.cs" /> + <Compile Include="Char.cs" /> + <Compile Include="Commands.cs" /> <Compile Include="Program.cs" /> - <Compile Include="AppControll.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="Properties\Settings.Designer.cs"> - <AutoGen>True</AutoGen> - <DesignTimeSharedInput>True</DesignTimeSharedInput> - <DependentUpon>Settings.settings</DependentUpon> - </Compile> - <Compile Include="ServerControl.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> <None Include="packages.config" /> - <None Include="Properties\Settings.settings"> - <Generator>SettingsSingleFileGenerator</Generator> - <LastGenOutput>Settings.Designer.cs</LastGenOutput> - </None> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/DiscoBot/MyBot.cs b/DiscoBot/MyBot.cs deleted file mode 100644 index f9bd427..0000000 --- a/DiscoBot/MyBot.cs +++ /dev/null @@ -1,113 +0,0 @@ -using Discord; -using Discord.Commands; - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Drawing; -using System.Windows; - -namespace DiscoBot -{ - class MyBot - { - DiscordClient discord; - CommandService commands; - private String token; - ServerControl FTB = new ServerControl(); - - public MyBot(string token = "Mjk0NTU0MDU4Nzg4NzAwMTYx.C7XGwQ.VwCAM10lDmwUe01NhBvDKNbd17I") - { - this.token = token; - - discord = new DiscordClient(x => - { - x.LogLevel = LogSeverity.Info; - x.LogHandler = Log; - }); - - discord.UsingCommands(x => - { - x.PrefixChar = '!'; - x.AllowMentionPrefix = true; - }); - - commands = discord.GetService<CommandService>(); - //Mandelbrot(); - //Server(); - DSA(); - - discord.ExecuteAndWait(async () => - { - await discord.Connect(token, TokenType.Bot); - }); - } - - private void Mandelbrot() - { - commands.CreateCommand("mandelbrot") - .Do(async (e) => - { - //await e.Channel.SendMessage("!hallo"); - - await e.Channel.SendFile(@"C:\temp\temp.png"); - - - }); - } - private void Server() - { - - commands.CreateCommand("start") - .Do(async (e) => - { - await e.Channel.SendMessage("Server wird gestartet"); - - FTB.Start(); - - }); - commands.CreateCommand("stop") - .Do(async (e) => - { - await e.Channel.SendMessage("Server wird gestoppt"); - - //FTB.Stop(); - }); - commands.CreateCommand("/") - .Parameter("command",ParameterType.Required) - .Parameter("value",ParameterType.Multiple) - .Do(async (e) => - { - await e.Channel.SendMessage("Command wird ausgeführt"); - - FTB.Command(e.GetArg("command")+" "+e.GetArg("value")); - }); - - commands.CreateCommand("restart") - .Do(async (e) => - { - await e.Channel.SendMessage("Server wird neu gestartet"); - - FTB.Stop(); - }); - - } - private void DSA() - { - commands.CreateCommand("wer ist Schuld?") - .Do(async (e) => - { - await e.Channel.SendMessage(e.Channel.Users.ToArray()[new Random().Next(0,4)].ToString()); - - FTB.Stop(); - }); - } - - private void Log(object sender, LogMessageEventArgs e) - { - Console.WriteLine(e.Message); - } - } -} diff --git a/DiscoBot/Program.cs b/DiscoBot/Program.cs index aa7b7ab..962e416 100644 --- a/DiscoBot/Program.cs +++ b/DiscoBot/Program.cs @@ -3,20 +3,69 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Reflection; +using Discord; +using Discord.WebSocket; +using Discord.Commands; +using Microsoft.Extensions.DependencyInjection; + namespace DiscoBot { - class Program + public class Program { - static void Main(string[] args) + private CommandService commands; + private DiscordSocketClient client; + private IServiceProvider services; + + public Char a = new Char(); + + + static void Main(string[] args) => new Program().Start().GetAwaiter().GetResult(); + + public async Task Start() { - //new Form1(); - new System.Threading.Thread(Launch).Start(); - //MyBot Bot2 = new MyBot("MjU1NDM1MDUyMTg2MzM3Mjkw.Cydmeg.AV2aEAwrM9UHqOUnmmUXaC5TBm4"); + client = new DiscordSocketClient(); + commands = new CommandService(); + + string token = "Mjk0NTU0MDU4Nzg4NzAwMTYx.C7XGwQ.VwCAM10lDmwUe01NhBvDKNbd17I"; + + services = new ServiceCollection() + .BuildServiceProvider(); + + await InstallCommands(); + + await client.LoginAsync(TokenType.Bot, token); + await client.StartAsync(); + + await Task.Delay(-1); } - public static void Launch() + + public async Task InstallCommands() { - new MyBot(); + // Hook the MessageReceived Event into our Command Handler + client.MessageReceived += HandleCommand; + // Discover all of the commands in this assembly and load them. + await commands.AddModulesAsync(Assembly.GetEntryAssembly()); + } + + public async Task HandleCommand(SocketMessage messageParam) + { + // Don't process the command if it was a System Message + var message = messageParam as SocketUserMessage; + if (message == null) return; + // Create a number to track where the prefix ends and the command begins + int argPos = 0; + // Determine if the message is a command, based on if it starts with '!' or a mention prefix + if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return; + // Create a Command Context + var context = new CommandContext(client, message); + // Execute the command. (result does not indicate a return value, + // rather an object stating if the command executed successfully) + var result = await commands.ExecuteAsync(context, argPos, services); + if (!result.IsSuccess) + await context.Channel.SendMessageAsync(result.ErrorReason); } } + } diff --git a/DiscoBot/Properties/AssemblyInfo.cs b/DiscoBot/Properties/AssemblyInfo.cs index 700b7d6..1ff6b8f 100644 --- a/DiscoBot/Properties/AssemblyInfo.cs +++ b/DiscoBot/Properties/AssemblyInfo.cs @@ -20,7 +20,7 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird -[assembly: Guid("1273d5d1-9f46-492f-9dfe-0098cd00405c")] +[assembly: Guid("1186af1c-bc46-4b3d-bee0-ce478b8aeac7")] // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: // diff --git a/DiscoBot/Properties/Settings.Designer.cs b/DiscoBot/Properties/Settings.Designer.cs deleted file mode 100644 index 3bfda66..0000000 --- a/DiscoBot/Properties/Settings.Designer.cs +++ /dev/null @@ -1,38 +0,0 @@ -//------------------------------------------------------------------------------ -// <auto-generated> -// Dieser Code wurde von einem Tool generiert. -// Laufzeitversion:4.0.30319.42000 -// -// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn -// der Code erneut generiert wird. -// </auto-generated> -//------------------------------------------------------------------------------ - -namespace DiscoBot.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.0.1.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("C:\\Users\\Dennis\\Downloads\\FTBBeyondServer")] - public string ServerPaht { - get { - return ((string)(this["ServerPaht"])); - } - set { - this["ServerPaht"] = value; - } - } - } -} diff --git a/DiscoBot/Properties/Settings.settings b/DiscoBot/Properties/Settings.settings deleted file mode 100644 index d7563a4..0000000 --- a/DiscoBot/Properties/Settings.settings +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version='1.0' encoding='utf-8'?> -<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DiscoBot.Properties" GeneratedClassName="Settings"> - <Profiles /> - <Settings> - <Setting Name="ServerPaht" Type="System.String" Scope="User"> - <Value Profile="(Default)">C:\Users\Dennis\Downloads\FTBBeyondServer</Value> - </Setting> - </Settings> -</SettingsFile>
\ No newline at end of file diff --git a/DiscoBot/ServerControl.cs b/DiscoBot/ServerControl.cs deleted file mode 100644 index 58da9fb..0000000 --- a/DiscoBot/ServerControl.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Diagnostics; -using System.IO; - -namespace DiscoBot -{ - class ServerControl - { - Process FTBProcess = new Process(); - ConsoleAppManager manager; - - public ServerControl() - { - manager = new ConsoleAppManager(DiscoBot.Properties.Settings.Default.ServerPaht + @"\ServerStart.bat"); - - FTBProcess.StartInfo.FileName = /*@"C:\Program Files\Java\jdk1.8.0_101\jre\bin\java.exe";//*/DiscoBot.Properties.Settings.Default.ServerPaht + @"\ServerStart.bat"; - //FTBProcess.StartInfo.Arguments = @"-server -Xms512M -Xmx6G -XX:PermSize=256M -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar C:\Users\Dennis\Downloads\FTBBeyondServer\minecraft_server.1.10.2.jar nogui"; - FTBProcess.StartInfo.WorkingDirectory = /*@"C:\Program Files\Java\jdk1.8.0_101\jre\bin";*/Properties.Settings.Default.ServerPaht; - - - - } - - - private void Refresh() - { - while(true) - Console.WriteLine(FTBProcess.StandardOutput.ReadToEnd()); - } - - public void Start() - { - FTBProcess.Start(); - new System.Threading.Thread(Refresh).Start(); - - } - - - public void Command(string c) - { - FTBProcess.StandardInput.WriteLine(c); - } - - public void Stop() - { - Process[] myProcesses; - myProcesses = Process.GetProcessesByName("java"); - foreach (Process p in myProcesses) - p.Kill(); - - - } - - } -} diff --git a/DiscoBot/packages.config b/DiscoBot/packages.config index 02a056d..cf276c0 100644 --- a/DiscoBot/packages.config +++ b/DiscoBot/packages.config @@ -1,8 +1,62 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Discord.Net" version="0.9.6" targetFramework="net452" /> - <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net452" /> - <package id="Nito.AsyncEx" version="3.0.1" targetFramework="net452" /> - <package id="RestSharp" version="105.2.3" targetFramework="net452" /> - <package id="WebSocket4Net" version="0.14.1" targetFramework="net452" /> + <package id="Discord.Net" version="1.0.1" targetFramework="net461" /> + <package id="Discord.Net.Commands" version="1.0.1" targetFramework="net461" /> + <package id="Discord.Net.Core" version="1.0.1" targetFramework="net461" /> + <package id="Discord.Net.Rest" version="1.0.1" targetFramework="net461" /> + <package id="Discord.Net.Rpc" version="1.0.1" targetFramework="net461" /> + <package id="Discord.Net.Webhook" version="1.0.1" targetFramework="net461" /> + <package id="Discord.Net.WebSocket" version="1.0.1" targetFramework="net461" /> + <package id="Microsoft.Extensions.DependencyInjection" version="1.1.1" targetFramework="net461" /> + <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.1.1" targetFramework="net461" /> + <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" /> + <package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="NETStandard.Library" version="1.6.1" targetFramework="net461" /> + <package id="Newtonsoft.Json" version="10.0.2" targetFramework="net461" /> + <package id="System.AppContext" version="4.3.0" targetFramework="net461" /> + <package id="System.Collections" version="4.3.0" targetFramework="net461" /> + <package id="System.Collections.Concurrent" version="4.3.0" targetFramework="net461" /> + <package id="System.Collections.Immutable" version="1.3.1" targetFramework="net461" /> + <package id="System.ComponentModel" version="4.3.0" targetFramework="net461" /> + <package id="System.Console" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.Debug" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.Tools" version="4.3.0" targetFramework="net461" /> + <package id="System.Diagnostics.Tracing" version="4.3.0" targetFramework="net461" /> + <package id="System.Globalization" version="4.3.0" targetFramework="net461" /> + <package id="System.Globalization.Calendars" version="4.3.0" targetFramework="net461" /> + <package id="System.Interactive.Async" version="3.1.1" targetFramework="net461" /> + <package id="System.IO" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.Compression" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.Compression.ZipFile" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.FileSystem" version="4.3.0" targetFramework="net461" /> + <package id="System.IO.FileSystem.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="System.Linq" version="4.3.0" targetFramework="net461" /> + <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net461" /> + <package id="System.Net.Http" version="4.3.0" targetFramework="net461" /> + <package id="System.Net.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="System.Net.Sockets" version="4.3.0" targetFramework="net461" /> + <package id="System.ObjectModel" version="4.3.0" targetFramework="net461" /> + <package id="System.Reflection" version="4.3.0" targetFramework="net461" /> + <package id="System.Reflection.Extensions" version="4.3.0" targetFramework="net461" /> + <package id="System.Reflection.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="System.Resources.ResourceManager" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.Extensions" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.Handles" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.InteropServices" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" /> + <package id="System.Runtime.Numerics" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net461" /> + <package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net461" /> + <package id="System.Text.Encoding" version="4.3.0" targetFramework="net461" /> + <package id="System.Text.Encoding.Extensions" version="4.3.0" targetFramework="net461" /> + <package id="System.Text.RegularExpressions" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading.Tasks" version="4.3.0" targetFramework="net461" /> + <package id="System.Threading.Timer" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.ReaderWriter" version="4.3.0" targetFramework="net461" /> + <package id="System.Xml.XDocument" version="4.3.0" targetFramework="net461" /> </packages>
\ No newline at end of file |