start member add responder

This commit is contained in:
sam 2024-08-20 21:03:03 +02:00
parent 633ba8f600
commit f0cb5a9d03
3 changed files with 105 additions and 7 deletions

View file

@ -5,6 +5,7 @@ using Catalogger.Backend.Extensions;
using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.API.Objects;
using Remora.Rest.Core;
using Guild = Catalogger.Backend.Database.Models.Guild;
@ -54,6 +55,8 @@ public class WebhookExecutorService(
public async Task QueueLogAsync(ulong channelId, IEmbed embed)
{
if (channelId == 0) return;
var queue = _cache.GetOrAdd(channelId, []);
queue.Enqueue(embed);
_cache[channelId] = queue;
@ -88,15 +91,17 @@ public class WebhookExecutorService(
embeds: embeds, username: _selfUser!.Username, avatarUrl: _selfUser.AvatarUrl());
}
public async Task SendLogWithAttachmentsAsync(ulong channelId, IEmbed embed, IEnumerable<FileData> files)
public async Task SendLogWithAttachmentsAsync(ulong channelId, List<Embed> embeds, IEnumerable<FileData> files)
{
if (channelId == 0) return;
var attachments = files
.Select<FileData, OneOf.OneOf<FileData, IPartialAttachment>>(f => f)
.ToList();
var webhook = await webhookCache.GetOrFetchWebhookAsync(channelId, id => FetchWebhookAsync(id));
await webhookApi.ExecuteWebhookAsync(DiscordSnowflake.New(webhook.Id), webhook.Token, shouldWait: false,
embeds: new List<IEmbed>([embed]), attachments: attachments, username: _selfUser!.Username,
embeds: embeds, attachments: attachments, username: _selfUser!.Username,
avatarUrl: _selfUser.AvatarUrl());
}