PluralKit/PluralKit.Bot/Handlers/InteractionCreated.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2021-05-26 20:27:52 +00:00
using Autofac;
using Serilog;
2021-05-26 20:27:52 +00:00
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;
private readonly ILogger _logger;
2021-08-27 15:03:47 +00:00
public InteractionCreated(InteractionDispatchService interactionDispatch, ILifetimeScope services, ILogger logger)
{
_interactionDispatch = interactionDispatch;
_services = services;
_logger = logger;
}
2021-05-26 20:27:52 +00:00
public async Task Handle(int shardId, InteractionCreateEvent evt)
{
if (evt.Type == Interaction.InteractionType.MessageComponent)
2021-05-26 20:27:52 +00:00
{
2022-11-29 00:25:20 +00:00
_logger.Information("Discord debug: got interaction with ID {id} from custom ID {custom_id}", evt.Id, evt.Data?.CustomId);
var customId = evt.Data?.CustomId;
if (customId == null) return;
var ctx = new InteractionContext(evt, _services);
if (customId.Contains("help-menu"))
await Help.ButtonClick(ctx);
else
await _interactionDispatch.Dispatch(customId, ctx);
2021-05-26 20:27:52 +00:00
}
}
}