Allow attaching embeds alongside a file upload. (#978)
commit a8bafb90cd1c5ea12abaa1aa01d0929833c999a8 Merge: f38dd4c4 7e04285e Author: WamWooWam <wamwoowam@gmail.com> Date: Mon Mar 12 08:05:52 2018 +0000 Merge branch 'dev' of https://github.com/WamWooWam/Discord.Net into dev commit f38dd4c42149380f3f7f86c21c86cb76d0f104b7 Author: WamWooWam <wamwoowam@gmail.com> Date: Mon Mar 12 08:05:49 2018 +0000 Cleaned up & fixed code style. commit 7e04285e5dcc0102c9b958e75155834ca35724b9 Author: Thomas May <wamwoowam@gmail.com> Date: Sun Mar 11 14:11:28 2018 +0000 Revert changes to DefaultRestClient Didn't actually need to change this, whoops. commit 3f5b2c8ef16d356e7b9588c4b36af03162ab7089 Author: WamWooWam <wamwoowam@gmail.com> Date: Sat Mar 10 19:30:44 2018 +0000 Enabled embeds alongside uploaded files. God damn Discord is a mess. Co-authored-by: WamWooWam <wamwoowam@gmail.com>
This commit is contained in:
@@ -1,18 +1,25 @@
|
||||
#pragma warning disable CS1591
|
||||
#pragma warning disable CS1591
|
||||
using Discord.Net.Converters;
|
||||
using Discord.Net.Rest;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Discord.API.Rest
|
||||
{
|
||||
internal class UploadFileParams
|
||||
{
|
||||
private static JsonSerializer _serializer = new JsonSerializer { ContractResolver = new DiscordContractResolver() };
|
||||
|
||||
public Stream File { get; }
|
||||
|
||||
public Optional<string> Filename { get; set; }
|
||||
public Optional<string> Content { get; set; }
|
||||
public Optional<string> Nonce { get; set; }
|
||||
public Optional<bool> IsTTS { get; set; }
|
||||
public Optional<Embed> Embed { get; set; }
|
||||
|
||||
public UploadFileParams(Stream file)
|
||||
{
|
||||
@@ -29,6 +36,19 @@ namespace Discord.API.Rest
|
||||
d["tts"] = IsTTS.Value.ToString();
|
||||
if (Nonce.IsSpecified)
|
||||
d["nonce"] = Nonce.Value;
|
||||
if (Embed.IsSpecified)
|
||||
{
|
||||
var sb = new StringBuilder(256);
|
||||
using (TextWriter text = new StringWriter(sb, CultureInfo.InvariantCulture))
|
||||
using (JsonWriter writer = new JsonTextWriter(text))
|
||||
{
|
||||
Dictionary<string, object> dictionary = new Dictionary<string, object>();
|
||||
dictionary["embed"] = Embed.Value;
|
||||
|
||||
_serializer.Serialize(writer, dictionary);
|
||||
}
|
||||
d["payload_json"] = sb.ToString();
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user