2021-05-26 20:27:52 +00:00
|
|
|
using Autofac;
|
|
|
|
|
2022-11-28 22:45:26 +00:00
|
|
|
using Serilog;
|
|
|
|
|
2021-05-26 20:27:52 +00:00
|
|
|
using Myriad.Gateway;
|
|
|
|
using Myriad.Types;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Bot;
|
|
|
|
|
|
|
|
public class InteractionCreated: IEventHandler<InteractionCreateEvent>
|
2021-05-26 20:27:52 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly InteractionDispatchService _interactionDispatch;
|
|
|
|
private readonly ILifetimeScope _services;
|
2022-11-28 22:45:26 +00:00
|
|
|
private readonly ILogger _logger;
|
2021-08-27 15:03:47 +00:00
|
|
|
|
2022-11-28 22:45:26 +00:00
|
|
|
public InteractionCreated(InteractionDispatchService interactionDispatch, ILifetimeScope services, ILogger logger)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
|
|
|
_interactionDispatch = interactionDispatch;
|
|
|
|
_services = services;
|
2022-11-28 22:45:26 +00:00
|
|
|
_logger = logger;
|
2021-11-27 02:10:56 +00:00
|
|
|
}
|
2021-05-26 20:27:52 +00:00
|
|
|
|
2022-01-14 23:39:03 +00:00
|
|
|
public async Task Handle(int shardId, InteractionCreateEvent evt)
|
2021-11-27 02:10:56 +00:00
|
|
|
{
|
|
|
|
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);
|
2021-11-27 02:10:56 +00:00
|
|
|
var customId = evt.Data?.CustomId;
|
2022-06-14 23:05:15 +00:00
|
|
|
if (customId == null) return;
|
|
|
|
|
|
|
|
var ctx = new InteractionContext(evt, _services);
|
|
|
|
|
|
|
|
if (customId.Contains("help-menu"))
|
|
|
|
await Help.ButtonClick(ctx);
|
|
|
|
else
|
2021-11-27 02:10:56 +00:00
|
|
|
await _interactionDispatch.Dispatch(customId, ctx);
|
2021-05-26 20:27:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|