mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
feat(bot): add poll proxying
This commit is contained in:
parent
b72805c51c
commit
9699490674
4 changed files with 55 additions and 2 deletions
|
|
@ -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))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue