44 lines
1.6 KiB
C#
Raw Normal View History

2023-10-24 15:25:45 +02:00
using BiblioTech.Options;
2023-10-22 10:10:52 +02:00
2023-10-22 10:38:46 +02:00
namespace BiblioTech.Commands
2023-10-22 10:10:52 +02:00
{
public class UserAssociateCommand : BaseCommand
{
private readonly EthAddressOption ethOption = new EthAddressOption();
2023-10-22 10:38:46 +02:00
private readonly UserOption optionalUser = new UserOption(
description: "If set, associates Ethereum address for another user. (Optional, admin-only)",
isRequired: false);
2023-10-22 10:10:52 +02:00
public override string Name => "set";
public override string StartingMessage => "hold on...";
2023-10-22 11:10:45 +02:00
public override string Description => "Associates a Discord user with an Ethereum address.";
public override CommandOption[] Options => new CommandOption[] { ethOption, optionalUser };
2023-10-22 10:10:52 +02:00
2023-10-24 15:25:45 +02:00
protected override async Task Invoke(CommandContext context)
2023-10-22 10:10:52 +02:00
{
2023-10-24 15:25:45 +02:00
var userId = GetUserId(optionalUser, context);
var data = await ethOption.Parse(context);
2023-10-22 10:10:52 +02:00
if (data == null) return;
var currentAddress = Program.UserRepo.GetCurrentAddressForUser(userId);
2023-10-24 15:25:45 +02:00
if (currentAddress != null && !IsSenderAdmin(context.Command))
2023-10-22 10:10:52 +02:00
{
2023-10-24 15:25:45 +02:00
await context.Command.FollowupAsync($"You've already set your Ethereum address to {currentAddress}.");
2023-10-22 10:10:52 +02:00
return;
}
2023-10-25 10:25:00 +02:00
// private commands
var result = Program.UserRepo.AssociateUserWithAddress(userId, data);
if (result)
{
await context.Command.FollowupAsync("Done! Thank you for joining the test net!");
}
else
{
await context.Command.FollowupAsync("That didn't work.");
}
2023-10-22 10:10:52 +02:00
}
}
}