cs-codex-dist-tests/Tools/BiblioTech/Commands/UserAssociateCommand.cs

37 lines
1.5 KiB
C#
Raw Normal View History

2023-10-22 08:10:52 +00:00
using Discord.WebSocket;
2023-10-22 08:38:46 +00:00
namespace BiblioTech.Commands
2023-10-22 08:10:52 +00:00
{
public class UserAssociateCommand : BaseCommand
{
private readonly EthAddressOption ethOption = new EthAddressOption();
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...";
public override string Description => "Associates a Discord user with an Ethereum address in the TestNet. " +
"Warning: You can set your Ethereum address only once! Double-check before hitting enter.";
public override CommandOption[] Options => new[] { ethOption };
protected override async Task Invoke(SocketSlashCommand command)
{
2023-10-22 08:38:46 +00:00
var userId = GetUserId(optionalUser, command);
2023-10-22 08:10:52 +00:00
var data = await ethOption.Parse(command);
if (data == null) return;
var currentAddress = Program.UserRepo.GetCurrentAddressForUser(userId);
2023-10-22 08:38:46 +00:00
if (currentAddress != null && !IsSenderAdmin(command))
2023-10-22 08:10:52 +00:00
{
await command.FollowupAsync($"You've already set your Ethereum address to {currentAddress}.");
return;
}
Program.UserRepo.AssociateUserWithAddress(userId, data);
await command.FollowupAsync("Done! Thank you for joining the test net!");
}
}
}