feat: remote await events from gateway

This commit is contained in:
alyssa 2025-03-29 17:55:01 +00:00
parent 64ff69723c
commit 15c992c572
17 changed files with 439 additions and 30 deletions

View file

@ -28,7 +28,7 @@ public abstract class BaseInteractive
ButtonStyle style = ButtonStyle.Secondary, bool disabled = false)
{
var dispatch = _ctx.Services.Resolve<InteractionDispatchService>();
var customId = dispatch.Register(handler, Timeout);
var customId = dispatch.Register(_ctx.ShardId, handler, Timeout);
var button = new Button
{
@ -89,7 +89,7 @@ public abstract class BaseInteractive
{
var dispatch = ctx.Services.Resolve<InteractionDispatchService>();
foreach (var button in _buttons)
button.CustomId = dispatch.Register(button.Handler, Timeout);
button.CustomId = dispatch.Register(_ctx.ShardId, button.Handler, Timeout);
}
public abstract Task Start();

View file

@ -1,5 +1,6 @@
using Autofac;
using Myriad.Cache;
using Myriad.Gateway;
using Myriad.Rest.Types;
using Myriad.Types;
@ -69,6 +70,9 @@ public class YesNoPrompt: BaseInteractive
return true;
}
// no need to reawait message
// gateway will already have sent us only matching messages
return false;
}
@ -88,6 +92,17 @@ public class YesNoPrompt: BaseInteractive
{
try
{
// check if http gateway and set listener
// todo: this one needs to handle options for message
if (_ctx.Cache is HttpDiscordCache)
await (_ctx.Cache as HttpDiscordCache).AwaitMessage(
_ctx.Guild?.Id ?? 0,
_ctx.Channel.Id,
_ctx.Author.Id,
Timeout,
options: new[] { "yes", "y", "no", "n" }
);
await queue.WaitFor(MessagePredicate, Timeout, cts.Token);
}
catch (TimeoutException e)