2023-10-24 13:25:45 +00:00
|
|
|
|
using BiblioTech.Options;
|
|
|
|
|
using CodexContractsPlugin;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
using GethPlugin;
|
|
|
|
|
|
2023-10-22 08:38:46 +00:00
|
|
|
|
namespace BiblioTech.Commands
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
2023-11-02 11:30:48 +00:00
|
|
|
|
public class GetBalanceCommand : BaseGethCommand
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
2023-10-22 08:10:52 +00:00
|
|
|
|
private readonly UserAssociateCommand userAssociateCommand;
|
|
|
|
|
private readonly UserOption optionalUser = new UserOption(
|
2023-10-22 08:38:46 +00:00
|
|
|
|
description: "If set, get balance for another user. (Optional, admin-only)",
|
2023-10-22 08:10:52 +00:00
|
|
|
|
isRequired: false);
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
2023-12-11 10:01:12 +00:00
|
|
|
|
public GetBalanceCommand(UserAssociateCommand userAssociateCommand)
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
2023-10-22 08:10:52 +00:00
|
|
|
|
this.userAssociateCommand = userAssociateCommand;
|
2023-10-20 07:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name => "balance";
|
2023-11-02 11:30:48 +00:00
|
|
|
|
public override string StartingMessage => RandomBusyMessage.Get();
|
2023-10-20 07:49:23 +00:00
|
|
|
|
public override string Description => "Shows Eth and TestToken balance of an eth address.";
|
2023-10-22 08:10:52 +00:00
|
|
|
|
public override CommandOption[] Options => new[] { optionalUser };
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
2023-10-24 13:25:45 +00:00
|
|
|
|
protected override async Task Execute(CommandContext context, IGethNode gethNode, ICodexContracts contracts)
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
2023-10-25 09:25:27 +00:00
|
|
|
|
var userId = GetUserFromCommand(optionalUser, context);
|
2023-10-22 08:10:52 +00:00
|
|
|
|
var addr = Program.UserRepo.GetCurrentAddressForUser(userId);
|
|
|
|
|
if (addr == null)
|
|
|
|
|
{
|
2023-10-25 08:54:26 +00:00
|
|
|
|
await context.Followup($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
|
2023-10-22 08:10:52 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
|
|
|
|
var eth = gethNode.GetEthBalance(addr);
|
2023-10-30 12:30:14 +00:00
|
|
|
|
var testTokens = contracts.GetTestTokenBalance(addr);
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
2023-10-25 08:54:26 +00:00
|
|
|
|
await context.Followup($"{context.Command.User.Username} has {eth} and {testTokens}.");
|
2023-10-20 07:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|