summaryrefslogtreecommitdiff
path: root/DiscoBot
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-09-26 20:51:37 +0200
committerTrueDoctor <d-kobert@web.de>2018-09-26 20:51:37 +0200
commitb411aa2128c2724bec0ecedb8cb4e1ffa59f3b53 (patch)
tree14e0a0cca2cf66b95fda402c8c7d7b6bd5b7b222 /DiscoBot
parent92e8bb7523c775014ccf68355e3f0178ebf4a61c (diff)
disconnected most vital calles from the Discord Bot
Diffstat (limited to 'DiscoBot')
-rw-r--r--DiscoBot/Auxiliary/TalentEnumerableExtension.cs9
-rw-r--r--DiscoBot/Commands/CommandExtension.cs119
-rw-r--r--DiscoBot/Commands/FileHandler.cs1
-rw-r--r--DiscoBot/Commands/Gm.cs1
-rw-r--r--DiscoBot/Commands/LebenUndAstral.cs1
-rw-r--r--DiscoBot/DSA_Game/Characters/Character.cs5
-rw-r--r--DiscoBot/DSA_Game/Characters/NPC.cs1
-rw-r--r--DiscoBot/DSA_Game/Characters/SaveChar.cs1
-rw-r--r--DiscoBot/DSA_Game/Dsa.cs5
-rw-r--r--DiscoBot/DiscoBot.csproj2
-rw-r--r--DiscoBot/Rework/Permissions.cs43
11 files changed, 180 insertions, 8 deletions
diff --git a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs
index 43c917e..df01de3 100644
--- a/DiscoBot/Auxiliary/TalentEnumerableExtension.cs
+++ b/DiscoBot/Auxiliary/TalentEnumerableExtension.cs
@@ -1,16 +1,15 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Threading.Tasks;
+using DSALib;
+
namespace DiscoBot.Auxiliary
{
using DiscoBot.Audio;
- using DiscoBot.Commands;
- using DiscoBot.DSA_Game;
using DiscoBot.DSA_Game.Characters;
+
public static class TalentEnumerableExtension
{
public static string ProbenTest(this IEnumerable<Talent> List, Character c, string talent, int erschwernis = 0)
diff --git a/DiscoBot/Commands/CommandExtension.cs b/DiscoBot/Commands/CommandExtension.cs
new file mode 100644
index 0000000..098e35f
--- /dev/null
+++ b/DiscoBot/Commands/CommandExtension.cs
@@ -0,0 +1,119 @@
+namespace DiscoBot.Auxiliary
+{
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.IO;
+ using System.Linq;
+ using System.Net;
+ using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
+
+ using Discord;
+ using Discord.Commands;
+
+ 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}```", false);
+
+ 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 );
+ var waiters = new List<Task>();
+ foreach (var message in test)
+ {
+ waiters.Add((message as IUserMessage).DeleteAsync());
+ }
+ Task.WaitAll(waiters.ToArray());
+ }
+
+ public static async Task ReplyAsync(this ModuleBase m, IEnumerable<string> message, bool directMessage = false)
+ {
+ var sb = new StringBuilder();
+ foreach (string 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 (string 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();
+ }
+
+ Stream stream = client.OpenRead(url);
+ await channel.SendFileAsync(stream, url.Split('/').Last());
+ }
+ }
+}
diff --git a/DiscoBot/Commands/FileHandler.cs b/DiscoBot/Commands/FileHandler.cs
index 52c8476..943a6e4 100644
--- a/DiscoBot/Commands/FileHandler.cs
+++ b/DiscoBot/Commands/FileHandler.cs
@@ -9,6 +9,7 @@
using DiscoBot.DSA_Game.Characters;
using Discord.Commands;
+ using DSALib;
public class FileHandler : ModuleBase
{
diff --git a/DiscoBot/Commands/Gm.cs b/DiscoBot/Commands/Gm.cs
index 540682c..6447f43 100644
--- a/DiscoBot/Commands/Gm.cs
+++ b/DiscoBot/Commands/Gm.cs
@@ -9,6 +9,7 @@ namespace DiscoBot.Commands
using DiscoBot.DSA_Game;
using Discord.Commands;
+ using DSALib.Characters;
public class Iam : ModuleBase
{
diff --git a/DiscoBot/Commands/LebenUndAstral.cs b/DiscoBot/Commands/LebenUndAstral.cs
index 2b5e8f1..456d2f2 100644
--- a/DiscoBot/Commands/LebenUndAstral.cs
+++ b/DiscoBot/Commands/LebenUndAstral.cs
@@ -9,6 +9,7 @@
using DiscoBot.DSA_Game.Characters;
using Discord.Commands;
+ using DSALib.Characters;
public class LE : ModuleBase
{
diff --git a/DiscoBot/DSA_Game/Characters/Character.cs b/DiscoBot/DSA_Game/Characters/Character.cs
index d14f28e..81c11fc 100644
--- a/DiscoBot/DSA_Game/Characters/Character.cs
+++ b/DiscoBot/DSA_Game/Characters/Character.cs
@@ -1,4 +1,7 @@
-namespace DiscoBot.DSA_Game.Characters
+using DSALib;
+using DSALib.Characters;
+
+namespace DiscoBot.DSA_Game.Characters
{
using System;
using System.Collections.Generic;
diff --git a/DiscoBot/DSA_Game/Characters/NPC.cs b/DiscoBot/DSA_Game/Characters/NPC.cs
index c135e30..b1b8e82 100644
--- a/DiscoBot/DSA_Game/Characters/NPC.cs
+++ b/DiscoBot/DSA_Game/Characters/NPC.cs
@@ -4,6 +4,7 @@
using DiscoBot.Auxiliary;
using DiscoBot.DSA_Game.Characters;
+ using DSALib.Characters;
public class Npc : Being, ICharacter
{
diff --git a/DiscoBot/DSA_Game/Characters/SaveChar.cs b/DiscoBot/DSA_Game/Characters/SaveChar.cs
index 4c9a940..272f516 100644
--- a/DiscoBot/DSA_Game/Characters/SaveChar.cs
+++ b/DiscoBot/DSA_Game/Characters/SaveChar.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace DiscoBot.DSA_Game.Characters
{
using Discord;
+ using DSALib.Characters;
public class SaveChar
{
diff --git a/DiscoBot/DSA_Game/Dsa.cs b/DiscoBot/DSA_Game/Dsa.cs
index 139ad91..fd60c9a 100644
--- a/DiscoBot/DSA_Game/Dsa.cs
+++ b/DiscoBot/DSA_Game/Dsa.cs
@@ -1,4 +1,7 @@
-namespace DiscoBot.DSA_Game
+using DSALib;
+using DSALib.Characters;
+
+namespace DiscoBot.DSA_Game
{
using System;
using System.Collections.Generic;
diff --git a/DiscoBot/DiscoBot.csproj b/DiscoBot/DiscoBot.csproj
index 1f3a799..30f4755 100644
--- a/DiscoBot/DiscoBot.csproj
+++ b/DiscoBot/DiscoBot.csproj
@@ -148,7 +148,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DSALib\DSALib.csproj">
- <Project>{33281e45-1d5c-4645-8d2b-dd05b40fdfd5}</Project>
+ <Project>{388dd4ed-29c4-4127-ac8f-34dd3fe9f9b0}</Project>
<Name>DSALib</Name>
</ProjectReference>
</ItemGroup>
diff --git a/DiscoBot/Rework/Permissions.cs b/DiscoBot/Rework/Permissions.cs
new file mode 100644
index 0000000..4d73146
--- /dev/null
+++ b/DiscoBot/Rework/Permissions.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DiscoBot.Auxiliary
+{
+ using Discord.Commands;
+ using Discord.WebSocket;
+
+ 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, 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))
+ {
+ c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait();
+ return false;
+ }
+
+ return true;
+ }
+
+ public static void Test(ICommandContext c, string[] roles)
+ {
+ if (!Check(c, roles))
+ {
+ c.Channel.SendMessageAsync("```xl\n Keine ausreichenden Berechtigungen\n```").Wait();
+ }
+ }
+ }
+}