2
0
mirror of synced 2025-02-13 08:56:30 +00:00
cs-codex-dist-tests/Tools/BiblioTech/Commands/UserAssociateCommand.cs

53 lines
2.1 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
{
2024-01-22 10:27:07 +01:00
public UserAssociateCommand(NotifyCommand notifyCommand)
{
this.notifyCommand = notifyCommand;
}
private readonly NotifyCommand notifyCommand;
2023-10-25 11:25:27 +02:00
private readonly EthAddressOption ethOption = new EthAddressOption(isRequired: false);
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";
2023-11-02 12:30:48 +01:00
public override string StartingMessage => RandomBusyMessage.Get();
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-25 11:25:27 +02:00
var user = GetUserFromCommand(optionalUser, context);
2023-10-24 15:25:45 +02:00
var data = await ethOption.Parse(context);
2023-10-22 10:10:52 +02:00
if (data == null) return;
2023-10-25 11:25:27 +02:00
var currentAddress = Program.UserRepo.GetCurrentAddressForUser(user);
2023-10-24 15:25:45 +02:00
if (currentAddress != null && !IsSenderAdmin(context.Command))
2023-10-22 10:10:52 +02:00
{
2023-10-25 10:54:26 +02:00
await context.Followup($"You've already set your Ethereum address to {currentAddress}.");
2023-10-22 10:10:52 +02:00
return;
}
2023-10-25 11:25:27 +02:00
var result = Program.UserRepo.AssociateUserWithAddress(user, data);
2023-10-25 10:25:00 +02:00
if (result)
{
2024-01-22 10:27:07 +01:00
await context.Followup(new string[]
{
"Done! Thank you for joining the test net!",
"By default, the bot will @-mention you with test-net reward related notifications.",
$"You can enable/disable this behavior with the '/{notifyCommand.Name}' command."
});
2023-10-25 10:25:00 +02:00
}
else
{
2023-10-25 10:54:26 +02:00
await context.Followup("That didn't work.");
2023-10-25 10:25:00 +02:00
}
2023-10-22 10:10:52 +02:00
}
}
}