summaryrefslogtreecommitdiff
path: root/DiscoBot
diff options
context:
space:
mode:
authorTrueDoctor <d-kobert@web.de>2018-07-08 23:01:19 +0200
committerTrueDoctor <d-kobert@web.de>2018-07-08 23:01:19 +0200
commit6ecf94cfc3e780d4c960447375b138e7473f6926 (patch)
tree77654523901f42ed3c26ddcde12bc1ff5314531d /DiscoBot
parentb9abcb7ed618f08d7b2614843ab6c4feea5ff573 (diff)
implemented Channel.SendWebFile
for usage see !save
Diffstat (limited to 'DiscoBot')
-rw-r--r--DiscoBot/Auxiliary/CommandExtension.cs15
-rw-r--r--DiscoBot/DSA_Game/Save/SaveCommand.cs6
-rw-r--r--DiscoBot/DSA_Game/Save/Session.cs3
3 files changed, 22 insertions, 2 deletions
diff --git a/DiscoBot/Auxiliary/CommandExtension.cs b/DiscoBot/Auxiliary/CommandExtension.cs
index 973bafa..e19149b 100644
--- a/DiscoBot/Auxiliary/CommandExtension.cs
+++ b/DiscoBot/Auxiliary/CommandExtension.cs
@@ -3,7 +3,9 @@
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;
@@ -13,6 +15,8 @@
public static class CommandExtension
{
+ private static WebClient client;
+
public static async Task ReplyTimedAsync(this ModuleBase m, string message, TimeSpan time)
{
var token = message.GetHashCode();
@@ -95,5 +99,16 @@
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/DSA_Game/Save/SaveCommand.cs b/DiscoBot/DSA_Game/Save/SaveCommand.cs
index 07bcbac..8566076 100644
--- a/DiscoBot/DSA_Game/Save/SaveCommand.cs
+++ b/DiscoBot/DSA_Game/Save/SaveCommand.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace DiscoBot.DSA_Game.Save
{
using System.IO;
+ using System.Net;
using System.Net.Http;
using DiscoBot.Auxiliary;
@@ -34,9 +35,11 @@ namespace DiscoBot.DSA_Game.Save
await this.ReplyAsync($"{name} wurde geladen");
}
- [Command("save"), Summary("Save Session")]
+ [Command("save", RunMode = RunMode.Async), Summary("Save Session")]
public async Task SessionSaveAsync([Remainder, Summary("Session Name")] string name = "")
{
+ var sendFile = this.Context.Channel.SendWebFile("https://cdn.discordapp.com/attachments/377123019673567232/465615882048110603/giphy.gif");
+
if (name.Equals("?") || name.Equals(string.Empty))
{
await this.ReplyAsync($"Gespeicherte Sessions:");
@@ -58,6 +61,7 @@ namespace DiscoBot.DSA_Game.Save
}
await this.ReplyAsync($"{name} wurde gespeichert");
+ await sendFile;
}
private string[] ListSessions()
diff --git a/DiscoBot/DSA_Game/Save/Session.cs b/DiscoBot/DSA_Game/Save/Session.cs
index 0358b22..578fa50 100644
--- a/DiscoBot/DSA_Game/Save/Session.cs
+++ b/DiscoBot/DSA_Game/Save/Session.cs
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
namespace DiscoBot.DSA_Game.Save
{
using System.IO;
+ using System.Runtime.CompilerServices;
using DiscoBot.DSA_Game.Characters;
@@ -37,7 +38,7 @@ namespace DiscoBot.DSA_Game.Save
{
// ignored
var log = new LogMessage(LogSeverity.Warning, "Properties", $"Laden von Save-File {path} fehlgeschlagen.", e);
- Console.WriteLine(log);
+ Console.WriteLine(log);
return null;
}
}