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