feat(bot): add poll proxying

This commit is contained in:
ambdroid 2024-10-01 08:38:35 -04:00 committed by GitHub
parent b72805c51c
commit 9699490674
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 2 deletions

View file

@ -4,6 +4,8 @@ using App.Metrics;
using Humanizer;
using NodaTime.Text;
using Myriad.Cache;
using Myriad.Extensions;
using Myriad.Rest;
@ -35,6 +37,7 @@ public record ProxyRequest
public ulong GuildId { get; init; }
public ulong ChannelId { get; init; }
public ulong? ThreadId { get; init; }
public ulong MessageId { get; init; }
public string Name { get; init; }
public string? AvatarUrl { get; init; }
public string? Content { get; init; }
@ -45,6 +48,7 @@ public record ProxyRequest
public bool AllowEveryone { get; init; }
public Message.MessageFlags? Flags { get; init; }
public bool Tts { get; init; }
public Message.MessagePoll? Poll { get; init; }
}
public class WebhookExecutorService
@ -154,6 +158,26 @@ public class WebhookExecutorService
}).ToArray();
}
if (req.Poll is Message.MessagePoll poll)
{
int? duration = null;
if (poll.Expiry is string expiry)
{
var then = OffsetDateTimePattern.ExtendedIso.Parse(expiry).Value.ToInstant();
var now = DiscordUtils.SnowflakeToInstant(req.MessageId);
// in theory .TotalHours should be exact, but just in case
duration = (int)Math.Round((then - now).TotalMinutes / 60.0);
}
webhookReq.Poll = new ExecuteWebhookRequest.WebhookPoll
{
Question = poll.Question,
Answers = poll.Answers,
Duration = duration,
AllowMultiselect = poll.AllowMultiselect,
LayoutType = poll.LayoutType
};
}
Message webhookMessage;
using (_metrics.Measure.Timer.Time(BotMetrics.WebhookResponseTime))
{