summaryrefslogtreecommitdiff
path: root/DiscoBot
diff options
context:
space:
mode:
authorDennis Kobert <d-kobert@web.de>2017-08-22 14:14:39 +0200
committerDennis Kobert <d-kobert@web.de>2017-08-22 14:14:39 +0200
commit90285f40e5a5a51bc51cb972963f56f630bc2792 (patch)
treef3344de1d088e5d203f67846ea8fdefecab28142 /DiscoBot
parentabdb151ab34d1d5356dea59ceebb97072fd83920 (diff)
Initial push
Diffstat (limited to 'DiscoBot')
-rw-r--r--DiscoBot/App.config12
-rw-r--r--DiscoBot/AppControll.cs197
-rw-r--r--DiscoBot/DiscoBot.csproj46
-rw-r--r--DiscoBot/Form1.Designer.cs38
-rw-r--r--DiscoBot/Form1.cs426
-rw-r--r--DiscoBot/MyBot.cs113
-rw-r--r--DiscoBot/Program.cs7
-rw-r--r--DiscoBot/Properties/Settings.Designer.cs38
-rw-r--r--DiscoBot/Properties/Settings.settings9
-rw-r--r--DiscoBot/ServerControl.cs59
-rw-r--r--DiscoBot/imaginary.cs33
-rw-r--r--DiscoBot/packages.config9
12 files changed, 987 insertions, 0 deletions
diff --git a/DiscoBot/App.config b/DiscoBot/App.config
index 88fa402..fb543e1 100644
--- a/DiscoBot/App.config
+++ b/DiscoBot/App.config
@@ -1,6 +1,18 @@
<?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" />
</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
diff --git a/DiscoBot/AppControll.cs b/DiscoBot/AppControll.cs
new file mode 100644
index 0000000..c32f3a2
--- /dev/null
+++ b/DiscoBot/AppControll.cs
@@ -0,0 +1,197 @@
+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/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj
index e27809d..89b72f2 100644
--- a/DiscoBot/DiscoBot.csproj
+++ b/DiscoBot/DiscoBot.csproj
@@ -32,21 +32,67 @@
<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>
+ <Reference Include="Discord.Net.Commands, Version=0.9.6.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\Discord.Net.Commands.0.9.6\lib\net45\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>
+ <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>
+ <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>
+ <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>
+ <Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\RestSharp.105.2.3\lib\net452\RestSharp.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+ <Reference Include="System.Drawing" />
+ <Reference Include="System.Windows.Forms" />
<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>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Form1.cs">
+ <SubType>Form</SubType>
+ </Compile>
+ <Compile Include="Form1.Designer.cs">
+ <DependentUpon>Form1.cs</DependentUpon>
+ </Compile>
+ <Compile Include="imaginary.cs" />
+ <Compile Include="MyBot.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/Form1.Designer.cs b/DiscoBot/Form1.Designer.cs
new file mode 100644
index 0000000..0f56817
--- /dev/null
+++ b/DiscoBot/Form1.Designer.cs
@@ -0,0 +1,38 @@
+namespace DiscoBot
+{
+ partial class Form1
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Text = "Form1";
+ }
+
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/DiscoBot/Form1.cs b/DiscoBot/Form1.cs
new file mode 100644
index 0000000..42b7b44
--- /dev/null
+++ b/DiscoBot/Form1.cs
@@ -0,0 +1,426 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Threading;
+using System.Windows.Forms;
+
+namespace DiscoBot
+{
+
+ public partial class Form1 : Form
+ {
+ PictureBox Box = new PictureBox();
+
+ int farbtiefe = 255;
+ Bitmap Canvas;
+ int[,] plot;
+ List<Bitmap> maps;
+ bool working = false;
+
+ int zoomque = 1;
+ double zoomfactor = 10;
+ double minx = -2, maxx = 1, miny = -1, maxy = 1;
+
+
+ public Form1()
+ {
+ InitializeComponent();
+ //this.Show();
+ Box.Width = 500;
+ Box.Height = 500;
+
+ doStep();
+
+ }
+ public int Iterate(imaginary z)
+ {
+
+ imaginary c = new imaginary(z);
+ z.re = 0; z.im = 0;
+ int r=1;
+ double temp;
+ for (r = 0; r < farbtiefe; r++)//r=(int)Math.Pow(2, r))
+ {
+ z.step(c);
+ temp = z.re * z.re + z.im * z.im;
+ Console.WriteLine(r);
+ if (temp > 4)
+ break;
+
+
+ }
+
+
+ return r;
+
+ }
+
+ private Color colorMap(int i)
+ {
+ /*/return Color.FromArgb(1, (int)2 * 2, (int)4 * 3);
+ //i /= farbtiefe;
+ int r = (int)(farbtiefe * (i / (double)max));
+ //i /= farbtiefe;
+ int b = (int)(farbtiefe * (i / (double)max));
+ //i /= farbtiefe;
+ int g = (int)(farbtiefe * (i / (double)max));
+ */
+ //i = 255;
+ if (i != 0)
+ { }
+ var temp = new HSV();
+ temp.h = i;
+ temp.s = 1;
+ temp.v = 1;
+
+ return ColorFromHSL(temp);
+ }
+
+
+
+
+ public void doStep()
+ {
+ if (working == true)
+ return;
+ working = true;
+ Canvas = new Bitmap(Box.Width, Box.Height);
+ plot = new int[Box.Width, Box.Height];
+ int processors = Environment.ProcessorCount;//get number of processors
+ int perCore = (int)Box.Width / processors;//divide the cluster in equal parts
+ int left = Box.Width - perCore * processors;//calc remainder
+ List<Thread> threads = new List<Thread>();
+ //maps = new List<Bitmap>();
+
+
+ for (int i = 0; i < processors; i++)
+ {
+ int start = i * perCore;
+
+ int stop = start + perCore;
+ if (i == processors - 1)
+ stop += left - 1;
+ int s = i;
+ //maps.Add(new Bitmap(start-stop, Box.Height));
+ threads.Add(new Thread(delegate () { paint(start, stop, s); }));
+ threads.Last().Priority = ThreadPriority.BelowNormal;
+ threads.Last().Start();
+ }
+
+ while (threads.Exists(x => x.IsAlive))
+ {
+ //Thread.Sleep(10);
+ Application.DoEvents();
+ }
+
+ int max = 0;
+ foreach (int i in plot)
+ max = i > max ? i : max;
+
+ int min = 0;
+ foreach (int i in plot)
+ min = i < min ? i : min;
+
+ for (int x = 0; x < Box.Width; x++)
+ for (int y = 0; y < Box.Height; y++)
+ Canvas.SetPixel(x, y, colorMap(plot[x, y]));
+
+ //Box.Image = Canvas;//CombineBitmap(maps.ToArray());
+ //Box.Refresh();
+ Canvas.Save(@"C:\temp\temp.png");
+ working = false;
+ }
+
+ private void paint(int start, int stop, int thread)
+ {
+ //int[,] c = new int[stop - start, Box.Height];
+ for (int x = start; x < stop; x++)
+ for (int y = 0; y < Box.Height; y++)
+ {
+ plot[x, y] = Iterate(map(x, y));
+ Console.WriteLine(x);
+ }
+
+ /*int min = c.
+ for (int x = start; x < stop; x++)
+ for (int y = 0; y < Box.Height; y++)
+ maps[thread].SetPixel(x, y, colorMap(c[x-start,y],min,max));
+ */
+
+ }
+
+
+ public imaginary map(int x, int y)
+ {
+ double xl = Math.Abs(minx - maxx) * x / Box.Width + minx;
+ double yl = Math.Abs(miny - maxy) * y / Box.Height + miny;
+
+
+ return new imaginary(xl, yl);
+ }
+
+ private void zoom(object sender, MouseEventArgs e)
+ {
+ if (working == true)
+ {
+ if (e.Delta > 0)
+ zoomque++;
+ else
+ zoomque--;
+ return;
+ }
+ double zoom = Math.Abs((e.Delta / 120) * zoomfactor) * zoomque;
+
+ double xl = Math.Abs(minx - maxx) * e.X / Box.Width + minx;
+ double yl = Math.Abs(miny - maxy) * e.Y / Box.Height + miny;
+
+ if (e.Delta > 0)
+ {
+ minx += Math.Abs(xl - minx) / zoom;
+ miny += Math.Abs(yl - miny) / zoom;
+ maxx -= Math.Abs(xl - maxx) / zoom;
+ maxy -= Math.Abs(yl - maxy) / zoom;
+ }
+ else
+ {
+ minx -= Math.Abs(xl - maxx) / zoom;
+ miny -= Math.Abs(yl - maxy) / zoom;
+ maxx += Math.Abs(xl - minx) / zoom;
+ maxy += Math.Abs(yl - miny) / zoom;
+ }
+ doStep();
+ zoomque = 1;
+
+ }
+
+
+
+ private void Box_Click(object sender, EventArgs e)
+ {
+ doStep();
+
+
+ }
+
+ private void Form1_ResizeEnd(object sender, EventArgs e)
+ {
+ doStep();
+ }
+
+ public static System.Drawing.Bitmap CombineBitmap(Bitmap[] files)
+ {
+ //read all images into memory
+ List<System.Drawing.Bitmap> images = new List<System.Drawing.Bitmap>();
+ System.Drawing.Bitmap finalImage = null;
+
+ try
+ {
+ int width = 0;
+ int height = 0;
+
+ foreach (Bitmap image in files)
+ {
+ //create a Bitmap from the file and add it to the list
+ System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
+
+ //update the size of the final bitmap
+ width += bitmap.Width;
+ height = bitmap.Height > height ? bitmap.Height : height;
+
+ images.Add(bitmap);
+ }
+
+ //create a bitmap to hold the combined image
+ finalImage = new System.Drawing.Bitmap(width, height);
+
+ //get a graphics object from the image so we can draw on it
+ using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(finalImage))
+ {
+ //set background color
+ g.Clear(System.Drawing.Color.Black);
+
+ //go through each image and draw it on the final image
+ int offset = 0;
+ foreach (System.Drawing.Bitmap image in images)
+ {
+ g.DrawImage(image,
+ new System.Drawing.Rectangle(offset, 0, image.Width, image.Height));
+ offset += (int)image.Width / 2;
+ }
+ }
+
+ return finalImage;
+ }
+ catch (Exception)
+ {
+ if (finalImage != null)
+ finalImage.Dispose();
+ //throw ex;
+ throw;
+ }
+ finally
+ {
+ //clean up memory
+ foreach (System.Drawing.Bitmap image in images)
+ {
+ image.Dispose();
+ }
+ }
+ }
+
+ void HsvToRgb(double h, double S, double V, out int r, out int g, out int b)
+ {
+ // ######################################################################
+ // T. Nathan Mundhenk
+ // mundhenk@usc.edu
+ // C/C++ Macro HSV to RGB
+
+ double H = h;
+ while (H < 0) { H += 360; };
+ while (H >= 360) { H -= 360; };
+ double R, G, B;
+ if (V <= 0)
+ { R = G = B = 0; }
+ else if (S <= 0)
+ {
+ R = G = B = V;
+ }
+ else
+ {
+ double hf = H / 60.0;
+ int i = (int)Math.Floor(hf);
+ double f = hf - i;
+ double pv = V * (1 - S);
+ double qv = V * (1 - S * f);
+ double tv = V * (1 - S * (1 - f));
+ switch (i)
+ {
+
+ // Red is the dominant color
+
+ case 0:
+ R = V;
+ G = tv;
+ B = pv;
+ break;
+
+ // Green is the dominant color
+
+ case 1:
+ R = qv;
+ G = V;
+ B = pv;
+ break;
+ case 2:
+ R = pv;
+ G = V;
+ B = tv;
+ break;
+
+ // Blue is the dominant color
+
+ case 3:
+ R = pv;
+ G = qv;
+ B = V;
+ break;
+ case 4:
+ R = tv;
+ G = pv;
+ B = V;
+ break;
+
+ // Red is the dominant color
+
+ case 5:
+ R = V;
+ G = pv;
+ B = qv;
+ break;
+
+ // Just in case we overshoot on our math by a little, we put these here. Since its a switch it won't slow us down at all to put these here.
+
+ case 6:
+ R = V;
+ G = tv;
+ B = pv;
+ break;
+ case -1:
+ R = V;
+ G = pv;
+ B = qv;
+ break;
+
+ // The color is not defined, we should throw an error.
+
+ default:
+ //LFATAL("i Value error in Pixel conversion, Value is %d", i);
+ R = G = B = V; // Just pretend its black/white
+ break;
+ }
+ }
+ r = Clamp((int)(R * 255.0));
+ g = Clamp((int)(G * 255.0));
+ b = Clamp((int)(B * 255.0));
+ }
+
+ /// <summary>
+ /// Clamp a value to 0-255
+ /// </summary>
+ int Clamp(int i)
+ {
+ if (i < 0) return 0;
+ if (i > 255) return 255;
+ return i;
+ }
+
+
+ Color SetHue(Color oldColor)
+ {
+ var temp = new HSV();
+ temp.h = oldColor.GetHue();
+ temp.s = oldColor.GetSaturation();
+ return ColorFromHSL(temp);
+ }
+ public struct HSV { public float h; public float s; public float v; }
+
+ // the Color Converter
+ static public Color ColorFromHSL(HSV hsl)
+ {
+ if (hsl.s == 0)
+ { int L = (int)hsl.v; return Color.FromArgb(255, L, L, L); }
+
+ double min, max, h;
+ h = hsl.h / 360d;
+
+ max = hsl.v < 0.5d ? hsl.v * (1 + hsl.s) : (hsl.v + hsl.s) - (hsl.v * hsl.s);
+ min = (hsl.v * 2d) - max;
+
+
+ Color c = Color.FromArgb(255, (int)(255 * RGBChannelFromHue(min, max, h + 1 / 3d)),
+ (int)(255 * RGBChannelFromHue(min, max, h)),
+ (int)(255 * RGBChannelFromHue(min, max, h - 1 / 3d)));
+
+
+
+ return c;
+ }
+
+ static double RGBChannelFromHue(double m1, double m2, double h)
+ {
+ h = (h + 1d) % 1d;
+ if (h < 0) h += 1;
+ if (h * 6 < 1) return m1 + (m2 - m1) * 6 * h;
+ else if (h * 2 < 1) return m2;
+ else if (h * 3 < 2) return m1 + (m2 - m1) * 6 * (2d / 3d - h);
+ else return m1;
+
+ }
+ }
+
+}
diff --git a/DiscoBot/MyBot.cs b/DiscoBot/MyBot.cs
new file mode 100644
index 0000000..12f5e56
--- /dev/null
+++ b/DiscoBot/MyBot.cs
@@ -0,0 +1,113 @@
+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 eb90328..aa7b7ab 100644
--- a/DiscoBot/Program.cs
+++ b/DiscoBot/Program.cs
@@ -10,6 +10,13 @@ namespace DiscoBot
{
static void Main(string[] args)
{
+ //new Form1();
+ new System.Threading.Thread(Launch).Start();
+ //MyBot Bot2 = new MyBot("MjU1NDM1MDUyMTg2MzM3Mjkw.Cydmeg.AV2aEAwrM9UHqOUnmmUXaC5TBm4");
+ }
+ public static void Launch()
+ {
+ new MyBot();
}
}
}
diff --git a/DiscoBot/Properties/Settings.Designer.cs b/DiscoBot/Properties/Settings.Designer.cs
new file mode 100644
index 0000000..3bfda66
--- /dev/null
+++ b/DiscoBot/Properties/Settings.Designer.cs
@@ -0,0 +1,38 @@
+//------------------------------------------------------------------------------
+// <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
new file mode 100644
index 0000000..d7563a4
--- /dev/null
+++ b/DiscoBot/Properties/Settings.settings
@@ -0,0 +1,9 @@
+<?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
new file mode 100644
index 0000000..58da9fb
--- /dev/null
+++ b/DiscoBot/ServerControl.cs
@@ -0,0 +1,59 @@
+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/imaginary.cs b/DiscoBot/imaginary.cs
new file mode 100644
index 0000000..9855dc2
--- /dev/null
+++ b/DiscoBot/imaginary.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DiscoBot
+{
+ public class imaginary
+ {
+ public double re;
+ public double im;
+
+ public imaginary(imaginary i)
+ {
+ this.re = i.re;
+ this.im = i.im;
+ }
+ public imaginary(double r, double i)
+ {
+ this.re = r;
+ this.im = i;
+ }
+
+
+ public void step(imaginary c)
+ {
+ double temp = re;
+ re = (re * re) - (im * im) + c.re;
+ im = (2.0 * temp * im + c.im);
+ }
+ }
+}
diff --git a/DiscoBot/packages.config b/DiscoBot/packages.config
new file mode 100644
index 0000000..b7e5584
--- /dev/null
+++ b/DiscoBot/packages.config
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Discord.Net" version="0.9.6" targetFramework="net452" />
+ <package id="Discord.Net.Commands" 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" />
+</packages> \ No newline at end of file