summaryrefslogtreecommitdiff
path: root/DiscoBot/Auxiliary
diff options
context:
space:
mode:
authoruzvkl <dennis.kobert@student.kit.edu>2019-06-11 23:05:52 +0200
committeruzvkl <dennis.kobert@student.kit.edu>2019-06-11 23:05:52 +0200
commite6181c24124d97f2fbc932b8a68311e625463156 (patch)
treec1f097c344ca266b7941c9668590b0fd35c7870a /DiscoBot/Auxiliary
parent2490ad5d31fe2ac778ff9303776f0e91f47a2862 (diff)
Move dsa related stuff to subfolder
Diffstat (limited to 'DiscoBot/Auxiliary')
-rw-r--r--DiscoBot/Auxiliary/CommandExtension.cs98
-rw-r--r--DiscoBot/Auxiliary/Dice.cs31
-rw-r--r--DiscoBot/Auxiliary/Permissions.cs32
-rw-r--r--DiscoBot/Auxiliary/RandomMisc.cs36
-rw-r--r--DiscoBot/Auxiliary/SpellCorrect.cs105
5 files changed, 0 insertions, 302 deletions
diff --git a/DiscoBot/Auxiliary/CommandExtension.cs b/DiscoBot/Auxiliary/CommandExtension.cs
deleted file mode 100644
index ad9f323..0000000
--- a/DiscoBot/Auxiliary/CommandExtension.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using Discord;
-using Discord.Commands;
-
-namespace DiscoBot.Auxiliary
-{
- public static class CommandExtension
- {
- private static WebClient _client;
-
- public static async Task ReplyTimedAsync(this ModuleBase m, string message, TimeSpan time)
- {
- var token = message.GetHashCode();
- var send = m.Context.Channel.SendMessageAsync($"#{token}\n```xl\n{message}```");
-
- var barInvoker = new BackgroundWorker();
- barInvoker.DoWork += delegate
- {
- Thread.Sleep(time);
- Delete(token, m);
- };
-
- await send;
- barInvoker.RunWorkerAsync();
- }
-
- private static void Delete(int token, ModuleBase m)
- {
- var messagesAsync = m.Context.Channel.GetMessagesAsync();
- Task.WaitAll(messagesAsync.ToArray());
- var list = messagesAsync.ToEnumerable().ToList();
- var messages = new List<IMessage>();
- foreach (var task in list) messages.AddRange(task.ToList());
-
- var test = messages.Where(x => x.Content.StartsWith($"#{token}\n") && x.Author.IsBot).Select(c => c);
- Task.WaitAll(test.Select(message => (message as IUserMessage)?.DeleteAsync()).ToArray());
- }
-
- public static async Task ReplyAsync(this ModuleBase m, IEnumerable<string> message, bool directMessage = false)
- {
- var sb = new StringBuilder();
- foreach (var re in message)
- {
- if (sb.Length + re.Length > 1798)
- {
- if (directMessage)
- await m.Context.User.SendMessageAsync("```xl\n" + sb + "\n```");
- else
- await m.Context.Channel.SendMessageAsync("```xl\n" + sb + "\n```");
-
- sb.Clear();
- }
-
- sb.AppendLine(re);
- }
-
- if (directMessage)
- await m.Context.User.SendMessageAsync("```xl\n" + sb + "\n```");
- else
- await m.Context.Channel.SendMessageAsync("```xl\n" + sb + "\n```");
- }
-
- public static async Task ReplyAsync(this ModuleBase m, IEnumerable<string> message, TimeSpan time)
- {
- var sb = new StringBuilder();
- foreach (var re in message)
- {
- if (sb.Length + re.Length > 1798)
- {
- await m.ReplyTimedAsync(sb.ToString(), time);
-
-
- sb.Clear();
- }
-
- sb.AppendLine(re);
- }
-
- await m.ReplyTimedAsync(sb.ToString(), TimeSpan.FromSeconds(90));
- }
-
- public static async Task SendWebFile(this IMessageChannel channel,
- string url = "https://i.imgur.com/0iHEycJ.png")
- {
- if (_client == null) _client = new WebClient();
-
- var stream = _client.OpenRead(url);
- await channel.SendFileAsync(stream, url.Split('/').Last());
- }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Auxiliary/Dice.cs b/DiscoBot/Auxiliary/Dice.cs
deleted file mode 100644
index f0f4def..0000000
--- a/DiscoBot/Auxiliary/Dice.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using System;
-
-namespace DiscoBot.Auxiliary
-{
- public static class Dice // roll it!
- {
- private static readonly Random Rnd = new Random();
-
- public static int Roll(int d = 20)
- {
- return Rnd.Next(d) + 1;
- }
-
-
- public static int Roll(int count, int d)
- {
- if (d <= 0) return 0;
-
- var sum = 0;
- for (var i = 0; i < Math.Abs(count); i++)
- {
- var roll = Roll(d);
- sum += roll;
- }
-
- sum *= Math.Abs(count) / count;
-
- return sum;
- }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Auxiliary/Permissions.cs b/DiscoBot/Auxiliary/Permissions.cs
deleted file mode 100644
index 3ec4a2e..0000000
--- a/DiscoBot/Auxiliary/Permissions.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using Discord.Commands;
-using Discord.WebSocket;
-
-namespace DiscoBot.Auxiliary
-{
- public static class Permissions
- {
- public static bool Check(ICommandContext c, string role)
- {
- return ((SocketGuildUser) c.User).Roles.ToList().Exists(v => v.Name.Equals(role));
- }
-
- public static bool Check(ICommandContext c, IEnumerable<string> roles)
- {
- return roles.Any(role => ((SocketGuildUser) c.User).Roles.ToList().Exists(v => v.Name.Equals(role)));
- }
-
- public static bool Test(ICommandContext c, string role)
- {
- if (Check(c, role)) return true;
- c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait();
- return false;
- }
-
- public static void Test(ICommandContext c, string[] roles)
- {
- if (!Check(c, roles)) c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait();
- }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Auxiliary/RandomMisc.cs b/DiscoBot/Auxiliary/RandomMisc.cs
deleted file mode 100644
index 205b3a7..0000000
--- a/DiscoBot/Auxiliary/RandomMisc.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System;
-using System.Linq;
-using System.Text;
-
-namespace DiscoBot.Auxiliary
-{
- public static class RandomMisc
- {
- public static string Roll(string input)
- {
- var output = new StringBuilder();
- var strings = input.Split('w', 'd').ToList();
- var count = Convert.ToInt32(strings[0]);
- strings = strings[1].Split(' ').ToList();
- var d = Convert.ToInt32(strings[0]);
-
- if (strings.Count > 0)
- {
- }
-
- var sum = 0;
- for (var i = 0; i < count; i++)
- {
- var roll = Dice.Roll(d);
- sum += roll;
- output.Append("[" + roll + "] ");
- }
-
- if (strings.Count <= 1) return output.ToString();
- sum += Convert.ToInt32(strings[1]);
- output.Append("sum: " + sum);
-
- return output.ToString();
- }
- }
-} \ No newline at end of file
diff --git a/DiscoBot/Auxiliary/SpellCorrect.cs b/DiscoBot/Auxiliary/SpellCorrect.cs
deleted file mode 100644
index c4bd4bf..0000000
--- a/DiscoBot/Auxiliary/SpellCorrect.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-using System;
-using System.Diagnostics;
-
-namespace DiscoBot.Auxiliary
-{
- public class SpellCorrect : StringComparer
- {
- public const int ErrorThreshold = 94100;
-
- public override int Compare(string x, string y)
- {
- return CompareEasy(x, y);
- }
-
- public static int CompareEasy(string x, string y)
- {
- if (string.IsNullOrEmpty(x)) throw new ArgumentException("message", nameof(x));
-
- if (string.IsNullOrEmpty(y)) throw new ArgumentException("message", nameof(y));
-
- if (x.Equals(y)) return 0;
-
- x = x.ToLower();
- y = y.ToLower();
- if (x.Equals(y)) return 1;
-
- var subs = y.Split(' ', '/');
- var score = subs.Length;
- foreach (var s in subs)
- if (s.Equals(x))
- score--;
-
- if (score < subs.Length) return score + 1;
-
- return 100000 - (int) (CompareExact(x, y) * 1000.0);
- /*if (y.Contains(x))
- return 6;*/
- }
-
- public override bool Equals(string x, string y)
- {
- Debug.Assert(x != null, nameof(x) + " != null");
- return x.Equals(y);
- }
-
- public override int GetHashCode(string obj)
- {
- throw new NotImplementedException();
- }
-
- public static double CompareExact(string s, string q)
- {
- s = s.ToLower();
- q = q.ToLower();
-
- int i, j;
- const double match = 3.0;
- const double gap = -2.0;
- const double mismatch = -2.0;
-
- double decay;
-
- var matrix = new double[s.Length + 1, q.Length + 1];
- var max = 0.0;
- matrix[0, 0] = 0.0;
-
- for (i = 1; i < s.Length; i++)
- // matrix[i, 0] = 0.0;
- matrix[i, 0] = i * gap;
-
- for (i = 1; i < q.Length; i++) matrix[0, i] = 0.0;
-
-
- for (i = 1; i <= s.Length; i++)
- for (j = 1; j <= q.Length; j++)
- {
- decay = j / (double) (s.Length * 1000);
- var add = s[i - 1] == q[j - 1] ? match - decay : mismatch;
- var score = matrix[i - 1, j - 1] + add;
-
- if (score < matrix[i - 1, j] + gap) score = matrix[i - 1, j] + gap;
-
- if (score < matrix[i, j - 1] + gap) score = matrix[i, j - 1] + gap;
-
- if (i > 1 && j > 1)
- if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1])
- {
- add = 3 / 2.0 * match - decay;
- if (score < matrix[i - 2, j - 2] + add) score = matrix[i - 2, j - 2] + add;
- }
-
- // if (score < 0)
- // {
- // score = 0;
- // }
-
- if (max < score && i == s.Length) max = score;
-
- matrix[i, j] = score;
- }
-
- return max;
- }
- }
-} \ No newline at end of file