PluralKit/PluralKit.Bot/Handlers/InteractionCreated.cs

31 lines
890 B
C#
Raw Normal View History

2021-05-26 20:27:52 +00:00
using Autofac;
using Myriad.Gateway;
using Myriad.Types;
namespace PluralKit.Bot;
public class InteractionCreated: IEventHandler<InteractionCreateEvent>
2021-05-26 20:27:52 +00:00
{
private readonly InteractionDispatchService _interactionDispatch;
private readonly ILifetimeScope _services;
2021-08-27 15:03:47 +00:00
public InteractionCreated(InteractionDispatchService interactionDispatch, ILifetimeScope services)
{
_interactionDispatch = interactionDispatch;
_services = services;
}
2021-05-26 20:27:52 +00:00
public async Task Handle(Shard shard, InteractionCreateEvent evt)
{
if (evt.Type == Interaction.InteractionType.MessageComponent)
2021-05-26 20:27:52 +00:00
{
var customId = evt.Data?.CustomId;
if (customId != null)
2021-05-26 20:27:52 +00:00
{
var ctx = new InteractionContext(evt, _services);
await _interactionDispatch.Dispatch(customId, ctx);
2021-05-26 20:27:52 +00:00
}
}
}
}