Add basic interactivity framework
This commit is contained in:
43
PluralKit.Bot/Interactive/YesNoPrompt.cs
Normal file
43
PluralKit.Bot/Interactive/YesNoPrompt.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
namespace PluralKit.Bot.Interactive
|
||||
{
|
||||
public class YesNoPrompt: BaseInteractive
|
||||
{
|
||||
public bool? Result { get; private set; }
|
||||
public ulong? User { get; set; }
|
||||
public string Message { get; set; } = "Are you sure?";
|
||||
|
||||
public string AcceptLabel { get; set; } = "OK";
|
||||
public ButtonStyle AcceptStyle { get; set; } = ButtonStyle.Primary;
|
||||
|
||||
public string CancelLabel { get; set; } = "Cancel";
|
||||
public ButtonStyle CancelStyle { get; set; } = ButtonStyle.Secondary;
|
||||
|
||||
public override async Task Start()
|
||||
{
|
||||
AddButton(ctx => OnButtonClick(ctx, true), AcceptLabel, AcceptStyle);
|
||||
AddButton(ctx => OnButtonClick(ctx, false), CancelLabel, CancelStyle);
|
||||
await Send(Message);
|
||||
}
|
||||
|
||||
private async Task OnButtonClick(InteractionContext ctx, bool result)
|
||||
{
|
||||
if (ctx.User.Id != User)
|
||||
{
|
||||
await Update(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
Result = result;
|
||||
await Finish(ctx);
|
||||
}
|
||||
|
||||
public YesNoPrompt(Context ctx): base(ctx)
|
||||
{
|
||||
User = ctx.Author.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user