feature: Add support for spoiler formatting & attachments (#1255)
Resolves #1216. * Add support for spoiler formatting * Implement support for sending message attachments that are spoilers * use consistent naming * update docstring for new isSpoiler param * move extension method to be under core project, make spoiler prefix a const * typo fix * update missing xmldocs * move SpoilerPrefix const outside of interface * Add isSpoiler support to webhook client adds the isSpoiler field to uploading files with a webhook, which will only insert "SPOILER_" to the start of the filename. This does not include other fields in the payload, as this is not in the documentation, and was not observed like in the regular client
This commit is contained in:
committed by
Christopher F
parent
76f82d687b
commit
f3b20b2b6d
@@ -19,6 +19,7 @@ namespace Discord.API.Rest
|
||||
public Optional<string> Nonce { get; set; }
|
||||
public Optional<bool> IsTTS { get; set; }
|
||||
public Optional<Embed> Embed { get; set; }
|
||||
public bool IsSpoiler { get; set; } = false;
|
||||
|
||||
public UploadFileParams(Stream file)
|
||||
{
|
||||
@@ -28,7 +29,10 @@ namespace Discord.API.Rest
|
||||
public IReadOnlyDictionary<string, object> ToDictionary()
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
d["file"] = new MultipartFile(File, Filename.GetValueOrDefault("unknown.dat"));
|
||||
var filename = Filename.GetValueOrDefault("unknown.dat");
|
||||
if (IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix))
|
||||
filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix);
|
||||
d["file"] = new MultipartFile(File, filename);
|
||||
|
||||
var payload = new Dictionary<string, object>();
|
||||
if (Content.IsSpecified)
|
||||
@@ -39,6 +43,8 @@ namespace Discord.API.Rest
|
||||
payload["nonce"] = Nonce.Value;
|
||||
if (Embed.IsSpecified)
|
||||
payload["embed"] = Embed.Value;
|
||||
if (IsSpoiler)
|
||||
payload["hasSpoiler"] = IsSpoiler.ToString();
|
||||
|
||||
var json = new StringBuilder();
|
||||
using (var text = new StringWriter(json))
|
||||
|
||||
@@ -22,6 +22,8 @@ namespace Discord.API.Rest
|
||||
public Optional<string> AvatarUrl { get; set; }
|
||||
public Optional<Embed[]> Embeds { get; set; }
|
||||
|
||||
public bool IsSpoiler { get; set; } = false;
|
||||
|
||||
public UploadWebhookFileParams(Stream file)
|
||||
{
|
||||
File = file;
|
||||
@@ -30,7 +32,11 @@ namespace Discord.API.Rest
|
||||
public IReadOnlyDictionary<string, object> ToDictionary()
|
||||
{
|
||||
var d = new Dictionary<string, object>();
|
||||
d["file"] = new MultipartFile(File, Filename.GetValueOrDefault("unknown.dat"));
|
||||
var filename = Filename.GetValueOrDefault("unknown.dat");
|
||||
if (IsSpoiler && !filename.StartsWith(AttachmentExtensions.SpoilerPrefix))
|
||||
filename = filename.Insert(0, AttachmentExtensions.SpoilerPrefix);
|
||||
|
||||
d["file"] = new MultipartFile(File, filename);
|
||||
|
||||
var payload = new Dictionary<string, object>();
|
||||
if (Content.IsSpecified)
|
||||
|
||||
Reference in New Issue
Block a user