mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-10 07:47:53 +00:00
feat: remote await events from gateway
This commit is contained in:
parent
64ff69723c
commit
15c992c572
17 changed files with 439 additions and 30 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using System.Collections.Concurrent;
|
||||
|
||||
using Myriad.Cache;
|
||||
|
||||
using NodaTime;
|
||||
|
||||
using Serilog;
|
||||
|
|
@ -16,9 +18,12 @@ public class InteractionDispatchService: IDisposable
|
|||
private readonly ConcurrentDictionary<Guid, RegisteredInteraction> _handlers = new();
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public InteractionDispatchService(IClock clock, ILogger logger)
|
||||
private readonly IDiscordCache _cache;
|
||||
|
||||
public InteractionDispatchService(IClock clock, ILogger logger, IDiscordCache cache)
|
||||
{
|
||||
_clock = clock;
|
||||
_cache = cache;
|
||||
_logger = logger.ForContext<InteractionDispatchService>();
|
||||
|
||||
_cleanupWorker = CleanupLoop(_cts.Token);
|
||||
|
|
@ -50,9 +55,15 @@ public class InteractionDispatchService: IDisposable
|
|||
_handlers.TryRemove(customIdGuid, out _);
|
||||
}
|
||||
|
||||
public string Register(Func<InteractionContext, Task> callback, Duration? expiry = null)
|
||||
public string Register(int shardId, Func<InteractionContext, Task> callback, Duration? expiry = null)
|
||||
{
|
||||
var key = Guid.NewGuid();
|
||||
|
||||
// if http_cache, return RegisterRemote
|
||||
// not awaited here, it's probably fine
|
||||
if (_cache is HttpDiscordCache)
|
||||
(_cache as HttpDiscordCache).AwaitInteraction(shardId, key.ToString(), expiry);
|
||||
|
||||
var handler = new RegisteredInteraction
|
||||
{
|
||||
Callback = callback,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue