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