2021-05-26 20:27:52 +00:00
|
|
|
using Autofac;
|
|
|
|
|
|
|
|
using Myriad.Gateway;
|
|
|
|
using Myriad.Rest;
|
|
|
|
using Myriad.Types;
|
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
namespace PluralKit.Bot;
|
|
|
|
|
|
|
|
public class InteractionContext
|
2021-05-26 20:27:52 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
private readonly ILifetimeScope _services;
|
|
|
|
|
|
|
|
public InteractionContext(InteractionCreateEvent evt, ILifetimeScope services)
|
2021-05-26 20:27:52 +00:00
|
|
|
{
|
2021-11-27 02:10:56 +00:00
|
|
|
Event = evt;
|
|
|
|
_services = services;
|
|
|
|
}
|
|
|
|
|
|
|
|
public InteractionCreateEvent Event { get; }
|
|
|
|
|
|
|
|
public ulong ChannelId => Event.ChannelId;
|
|
|
|
public ulong? MessageId => Event.Message?.Id;
|
|
|
|
public GuildMember? Member => Event.Member;
|
|
|
|
public User User => Event.Member?.User ?? Event.User;
|
|
|
|
public string Token => Event.Token;
|
|
|
|
public string? CustomId => Event.Data?.CustomId;
|
|
|
|
|
|
|
|
public async Task Reply(string content)
|
|
|
|
{
|
|
|
|
await Respond(InteractionResponse.ResponseType.ChannelMessageWithSource,
|
|
|
|
new InteractionApplicationCommandCallbackData { Content = content, Flags = Message.MessageFlags.Ephemeral });
|
|
|
|
}
|
|
|
|
|
|
|
|
public async Task Ignore()
|
|
|
|
{
|
|
|
|
await Respond(InteractionResponse.ResponseType.DeferredUpdateMessage,
|
|
|
|
new InteractionApplicationCommandCallbackData
|
2021-05-30 14:45:29 +00:00
|
|
|
{
|
2022-06-14 23:05:15 +00:00
|
|
|
Components = Event.Message.Components
|
2021-05-30 14:45:29 +00:00
|
|
|
});
|
2021-11-27 02:10:56 +00:00
|
|
|
}
|
2021-05-30 14:45:29 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public async Task Acknowledge()
|
|
|
|
{
|
|
|
|
await Respond(InteractionResponse.ResponseType.UpdateMessage,
|
|
|
|
new InteractionApplicationCommandCallbackData { Components = Array.Empty<MessageComponent>() });
|
|
|
|
}
|
2021-05-30 14:45:29 +00:00
|
|
|
|
2021-11-27 02:10:56 +00:00
|
|
|
public async Task Respond(InteractionResponse.ResponseType type,
|
|
|
|
InteractionApplicationCommandCallbackData? data)
|
|
|
|
{
|
|
|
|
var rest = _services.Resolve<DiscordApiClient>();
|
|
|
|
await rest.CreateInteractionResponse(Event.Id, Event.Token,
|
|
|
|
new InteractionResponse { Type = type, Data = data });
|
2021-05-26 20:27:52 +00:00
|
|
|
}
|
|
|
|
}
|