Practice better disposal hygiene
This commit is contained in:
parent
3fdfaeab01
commit
58cdb04ab9
@ -95,7 +95,7 @@ namespace PluralKit.Bot
|
|||||||
if (!await EnsureBotPermissions(channel)) return;
|
if (!await EnsureBotPermissions(channel)) return;
|
||||||
|
|
||||||
// Can't proxy a message with no content and no attachment
|
// Can't proxy a message with no content and no attachment
|
||||||
if (match.InnerText.Trim().Length == 0 && message.Attachments.Count == 0)
|
if (match.InnerText.Trim().Length == 0/* && message.Attachments.Count == 0*/) // TODO: undo when adding attachments back
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get variables in order and all
|
// Get variables in order and all
|
||||||
|
@ -53,11 +53,13 @@ namespace PluralKit.Bot
|
|||||||
IReadOnlyCollection<IAttachment> attachments, bool hasRetried = false)
|
IReadOnlyCollection<IAttachment> attachments, bool hasRetried = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
var mfd = new MultipartFormDataContent();
|
using var mfd = new MultipartFormDataContent
|
||||||
mfd.Add(new StringContent(content.Truncate(2000)), "content");
|
{
|
||||||
mfd.Add(new StringContent(FixClyde(name).Truncate(80)), "username");
|
{new StringContent(content.Truncate(2000)), "content"},
|
||||||
|
{new StringContent(FixClyde(name).Truncate(80)), "username"}
|
||||||
|
};
|
||||||
if (avatarUrl != null) mfd.Add(new StringContent(avatarUrl), "avatar_url");
|
if (avatarUrl != null) mfd.Add(new StringContent(avatarUrl), "avatar_url");
|
||||||
|
|
||||||
/*var attachmentChunks = ChunkAttachmentsOrThrow(attachments, 8 * 1024 * 1024);
|
/*var attachmentChunks = ChunkAttachmentsOrThrow(attachments, 8 * 1024 * 1024);
|
||||||
if (attachmentChunks.Count > 0)
|
if (attachmentChunks.Count > 0)
|
||||||
{
|
{
|
||||||
@ -65,9 +67,10 @@ namespace PluralKit.Bot
|
|||||||
await AddAttachmentsToMultipart(mfd, attachmentChunks.First());
|
await AddAttachmentsToMultipart(mfd, attachmentChunks.First());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
HttpResponseMessage response;
|
|
||||||
using (_metrics.Measure.Timer.Time(BotMetrics.WebhookResponseTime))
|
var timerCtx = _metrics.Measure.Timer.Time(BotMetrics.WebhookResponseTime);
|
||||||
response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd);
|
using var response = await _client.PostAsync($"{DiscordConfig.APIUrl}webhooks/{webhook.Id}/{webhook.Token}?wait=true", mfd);
|
||||||
|
timerCtx.Dispose();
|
||||||
|
|
||||||
// TODO: are there cases where an error won't also return a parseable JSON object?
|
// TODO: are there cases where an error won't also return a parseable JSON object?
|
||||||
var responseJson = JsonConvert.DeserializeObject<JObject>(await response.Content.ReadAsStringAsync());
|
var responseJson = JsonConvert.DeserializeObject<JObject>(await response.Content.ReadAsStringAsync());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user