-
-
Notifications
You must be signed in to change notification settings - Fork 737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow attaching embeds alongside a file upload. #978
Conversation
God damn Discord is a mess.
Didn't actually need to change this, whoops.
@@ -29,6 +37,17 @@ public UploadFileParams(Stream file) | |||
d["tts"] = IsTTS.Value.ToString(); | |||
if (Nonce.IsSpecified) | |||
d["nonce"] = Nonce.Value; | |||
if (Embed.IsSpecified) | |||
{ | |||
var sb = new StringBuilder(256); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any cleaner approach here? The DefaultRestClient seems to support serializing Streams here, could use a MemoryStream+StreamWriter instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, the embed data needs to be URL encoded, something I'm not sure I can do from a MemoryStream without even more mess
|
||
namespace Discord.API.Rest | ||
{ | ||
internal class UploadFileParams | ||
{ | ||
// Fuckin Discord man. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd replace the sentimental comments with something more informational, like "needed to serialize embeds" or something
using (TextWriter text = new StringWriter(sb, CultureInfo.InvariantCulture)) | ||
using (JsonWriter writer = new JsonTextWriter(text)) | ||
{ | ||
// I apologise for the mess I've created here, god damn is this annoying. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't apologize, that's what git blame
is for
using (JsonWriter writer = new JsonTextWriter(text)) | ||
{ | ||
// I apologise for the mess I've created here, god damn is this annoying. | ||
_serializer.Serialize(writer, new Dictionary<string, object>() { { "embed", Embed.Value } }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we generally prefer Dictionary-initializer style (["key"] = "value"
)
commit a8bafb9 Merge: f38dd4c 7e04285 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 f38dd4c Author: WamWooWam <wamwoowam@gmail.com> Date: Mon Mar 12 08:05:49 2018 +0000 Cleaned up & fixed code style. commit 7e04285 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 3f5b2c8 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>
Merged via e9f9b48, thanks! |
commit a8bafb9 Merge: f38dd4c 7e04285 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 f38dd4c Author: WamWooWam <wamwoowam@gmail.com> Date: Mon Mar 12 08:05:49 2018 +0000 Cleaned up & fixed code style. commit 7e04285 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 3f5b2c8 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>
Abstract
This PR adds support for attaching embeds alongside file uploads, hopefully fixing #796.
Additions
Added an
Embed
parameter toIMessageChannel#SendFileAsync
and modified the rest of the code handling this to allow it, as such it should work now in most cases.Drawbacks
This is, naturally, a breaking change, which may cause issues for people passing
RequestOptions
to these methods, but shouldn't effect anyone else.