feat(bot): correctly proxy voice messages

This commit is contained in:
spiral 2023-04-15 12:10:04 -04:00
parent 8187aa05b7
commit eefbaf0c1d
9 changed files with 21 additions and 11 deletions

View File

@ -150,7 +150,7 @@ public class BaseRestClient: IAsyncDisposable
if (files != null)
for (var i = 0; i < files.Length; i++)
{
var (filename, stream, _) = files[i];
var (filename, stream, _, _, _) = files[i];
mfd.Add(new StreamContent(stream), $"files[{i}]", filename);
}

View File

@ -1,3 +1,3 @@
namespace Myriad.Rest.Types;
public record MultipartFile(string Filename, Stream Data, string? Description);
public record MultipartFile(string Filename, Stream Data, string? Description, string? Waveform, float? DurationSecs);

View File

@ -11,4 +11,5 @@ public record ExecuteWebhookRequest
public Sticker[] Stickers { get; init; }
public Message.Attachment[] Attachments { get; set; }
public AllowedMentions? AllowedMentions { get; init; }
public Message.MessageFlags? Flags { get; set; }
}

View File

@ -14,7 +14,8 @@ public record Message
SuppressEmbeds = 1 << 2,
SourceMessageDeleted = 1 << 3,
Urgent = 1 << 4,
Ephemeral = 1 << 6
Ephemeral = 1 << 6,
VoiceMessage = 1 << 13,
}
public enum MessageType
@ -64,7 +65,7 @@ public record Message
public ulong? ApplicationId { get; init; }
public MessageType Type { get; init; }
public Reference? MessageReference { get; set; }
// public MessageFlags Flags { get; init; }
public MessageFlags Flags { get; init; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Optional<Message?> ReferencedMessage { get; init; }
@ -83,6 +84,8 @@ public record Message
public int Size { get; init; }
public string Url { get; init; }
public string ProxyUrl { get; init; }
public string? Waveform { get; init; }
public float? DurationSecs { get; init; }
// public int? Width { get; init; }
// public int? Height { get; init; }
}

View File

@ -121,7 +121,7 @@ public class ImportExport
var msg = await ctx.Rest.CreateMessage(dm,
new MessageRequest { Content = $"{Emojis.Success} Here you go!" },
new[] { new MultipartFile("system.json", stream, null) });
new[] { new MultipartFile("system.json", stream, null, null, null) });
await ctx.Rest.CreateMessage(dm, new MessageRequest { Content = $"<{msg.Attachments[0].Url}>" });
// If the original message wasn't posted in DMs, send a public reminder

View File

@ -285,7 +285,7 @@ public class ProxiedMessage
{
Content = $"{Emojis.Warn} Message contains codeblocks, raw source sent as an attachment."
},
new[] { new MultipartFile("message.txt", stream, null) });
new[] { new MultipartFile("message.txt", stream, null, null, null) });
}
return;

View File

@ -562,7 +562,7 @@ public class SystemEdit
var dm = await _dmCache.GetOrCreateDmChannel(ctx.Author.Id);
var msg = await ctx.Rest.CreateMessage(dm,
new MessageRequest { Content = $"{Emojis.Success} System deleted. If you want to set up your PluralKit system again, you can import the file below with `pk;import`." },
new[] { new MultipartFile("system.json", stream, null) });
new[] { new MultipartFile("system.json", stream, null, null, null) });
await ctx.Rest.CreateMessage(dm, new MessageRequest { Content = $"<{msg.Attachments[0].Url}>" });
// If the original message wasn't posted in DMs, send a public reminder

View File

@ -217,7 +217,8 @@ public class ProxyService
FileSizeLimit = guild.FileSizeLimit(),
Embeds = embeds.ToArray(),
Stickers = trigger.StickerItems,
AllowEveryone = allowEveryone
AllowEveryone = allowEveryone,
Flags = trigger.Flags.HasFlag(Message.MessageFlags.VoiceMessage) ? Message.MessageFlags.VoiceMessage : null,
});
await HandleProxyExecutedActions(ctx, autoproxySettings, trigger, proxyMessage, match);
}

View File

@ -43,6 +43,7 @@ public record ProxyRequest
public Embed[] Embeds { get; init; }
public Sticker[] Stickers { get; init; }
public bool AllowEveryone { get; init; }
public Message.MessageFlags? Flags { get; init; }
}
public class WebhookExecutorService
@ -129,6 +130,7 @@ public class WebhookExecutorService
AvatarUrl = !string.IsNullOrWhiteSpace(req.AvatarUrl) ? req.AvatarUrl : null,
Embeds = req.Embeds,
Stickers = req.Stickers,
Flags = req.Flags,
};
MultipartFile[] files = null;
@ -144,7 +146,9 @@ public class WebhookExecutorService
{
Id = (ulong)Array.IndexOf(files, f),
Description = f.Description,
Filename = f.Filename
Filename = f.Filename,
Waveform = f.Waveform,
DurationSecs = f.DurationSecs
}).ToArray();
}
@ -226,7 +230,8 @@ public class WebhookExecutorService
{
Id = (ulong)Array.IndexOf(files, f),
Description = f.Description,
Filename = f.Filename
Filename = f.Filename,
Waveform = f.Waveform
}).ToArray()
};
await _rest.ExecuteWebhook(webhook.Id, webhook.Token!, req, files, threadId);
@ -240,7 +245,7 @@ public class WebhookExecutorService
var attachmentResponse =
await _client.GetAsync(attachment.Url, HttpCompletionOption.ResponseHeadersRead);
return new MultipartFile(attachment.Filename, await attachmentResponse.Content.ReadAsStreamAsync(),
attachment.Description);
attachment.Description, attachment.Waveform, attachment.DurationSecs);
}
return await Task.WhenAll(attachments.Select(GetStream));