2023-10-20 07:49:23 +00:00
|
|
|
|
using CodexContractsPlugin;
|
|
|
|
|
using Core;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using GethPlugin;
|
|
|
|
|
|
|
|
|
|
namespace BiblioTech.TokenCommands
|
|
|
|
|
{
|
|
|
|
|
public class GetBalanceCommand : BaseNetCommand
|
|
|
|
|
{
|
2023-10-22 08:10:52 +00:00
|
|
|
|
private readonly UserAssociateCommand userAssociateCommand;
|
|
|
|
|
private readonly UserOption optionalUser = new UserOption(
|
|
|
|
|
description: "If set, get balance for another user. (Optional, admin-only)",
|
|
|
|
|
isRequired: false);
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
2023-10-22 08:10:52 +00:00
|
|
|
|
public GetBalanceCommand(DeploymentsFilesMonitor monitor, CoreInterface ci, UserAssociateCommand userAssociateCommand)
|
2023-10-20 08:14:56 +00:00
|
|
|
|
: base(monitor, ci)
|
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-10-20 09:20:38 +00:00
|
|
|
|
public override string StartingMessage => "Fetching balance...";
|
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-20 08:14:56 +00:00
|
|
|
|
protected override async Task Execute(SocketSlashCommand command, IGethNode gethNode, ICodexContracts contracts)
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
2023-10-22 08:10:52 +00:00
|
|
|
|
var userId = GetUserId(optionalUser, command);
|
|
|
|
|
var addr = Program.UserRepo.GetCurrentAddressForUser(userId);
|
|
|
|
|
if (addr == null)
|
|
|
|
|
{
|
|
|
|
|
await command.FollowupAsync($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-20 07:49:23 +00:00
|
|
|
|
|
|
|
|
|
var eth = gethNode.GetEthBalance(addr);
|
|
|
|
|
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
|
|
|
|
|
|
2023-10-22 08:10:52 +00:00
|
|
|
|
await command.FollowupAsync($"{command.User.Username} has {eth} and {testTokens}.");
|
2023-10-20 07:49:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|