All works
This commit is contained in:
parent
e16b1ce079
commit
8ef2e6023e
|
@ -11,6 +11,7 @@ namespace BiblioTech.Commands
|
|||
public override string Name => "clear";
|
||||
public override string StartingMessage => "Hold on...";
|
||||
public override string Description => "Admin only. Clears current Eth address for a user, allowing them to set a new one.";
|
||||
public override CommandOption[] Options => new[] { user };
|
||||
|
||||
protected override async Task Invoke(SocketSlashCommand command)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace BiblioTech.Commands
|
|||
|
||||
public override string Name => "deployments";
|
||||
public override string StartingMessage => "Fetching deployments information...";
|
||||
public override string Description => "Lists known deployments";
|
||||
public override string Description => "Lists active TestNet deployments";
|
||||
|
||||
protected override async Task Invoke(SocketSlashCommand command)
|
||||
{
|
||||
|
|
|
@ -7,16 +7,17 @@ namespace BiblioTech.Commands
|
|||
{
|
||||
public class MintCommand : BaseNetCommand
|
||||
{
|
||||
private readonly string nl = Environment.NewLine;
|
||||
private readonly Ether defaultEthToSend = 10.Eth();
|
||||
private readonly TestToken defaultTestTokensToMint = 1024.TestTokens();
|
||||
private readonly UserOption optionalUser = new UserOption(
|
||||
description: "If set, mint tokens for this user. (Optional, admin-only)",
|
||||
isRequired: true);
|
||||
isRequired: false);
|
||||
private readonly UserAssociateCommand userAssociateCommand;
|
||||
|
||||
public MintCommand(DeploymentsFilesMonitor monitor, CoreInterface ci)
|
||||
public MintCommand(DeploymentsFilesMonitor monitor, CoreInterface ci, UserAssociateCommand userAssociateCommand)
|
||||
: base(monitor, ci)
|
||||
{
|
||||
this.userAssociateCommand = userAssociateCommand;
|
||||
}
|
||||
|
||||
public override string Name => "mint";
|
||||
|
@ -28,36 +29,57 @@ namespace BiblioTech.Commands
|
|||
{
|
||||
var userId = GetUserId(optionalUser, command);
|
||||
var addr = Program.UserRepo.GetCurrentAddressForUser(userId);
|
||||
if (addr == null) return;
|
||||
if (addr == null)
|
||||
{
|
||||
await command.FollowupAsync($"No address has been set for this user. Please use '/{userAssociateCommand.Name}' to set it first.");
|
||||
return;
|
||||
}
|
||||
|
||||
var report =
|
||||
ProcessEth(gethNode, addr) +
|
||||
ProcessTestTokens(gethNode, contracts, addr);
|
||||
var report = new List<string>();
|
||||
|
||||
await command.FollowupAsync(report);
|
||||
var sentEth = ProcessEth(gethNode, addr, report);
|
||||
var mintedTokens = ProcessTokens(gethNode, contracts, addr, report);
|
||||
|
||||
Program.UserRepo.AddMintEventForUser(userId, addr, sentEth, mintedTokens);
|
||||
|
||||
await command.FollowupAsync(string.Join(Environment.NewLine, report));
|
||||
}
|
||||
|
||||
private string ProcessTestTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr)
|
||||
private TestToken ProcessTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr, List<string> report)
|
||||
{
|
||||
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
|
||||
if (testTokens.Amount < 64m)
|
||||
if (ShouldMintTestTokens(gethNode, contracts, addr))
|
||||
{
|
||||
contracts.MintTestTokens(gethNode, addr, defaultTestTokensToMint);
|
||||
return $"Minted {defaultTestTokensToMint}." + nl;
|
||||
report.Add($"Minted {defaultTestTokensToMint}.");
|
||||
return defaultTestTokensToMint;
|
||||
}
|
||||
return "TestToken balance over threshold." + nl;
|
||||
|
||||
report.Add("TestToken balance over threshold.");
|
||||
return 0.TestTokens();
|
||||
}
|
||||
|
||||
private string ProcessEth(IGethNode gethNode, EthAddress addr)
|
||||
private Ether ProcessEth(IGethNode gethNode, EthAddress addr, List<string> report)
|
||||
{
|
||||
var eth = gethNode.GetEthBalance(addr);
|
||||
if (eth.Eth < 1.0m)
|
||||
if (ShouldSendEth(gethNode, addr))
|
||||
{
|
||||
gethNode.SendEth(addr, defaultEthToSend);
|
||||
return $"Sent {defaultEthToSend}." + nl;
|
||||
report.Add($"Sent {defaultEthToSend}.");
|
||||
return defaultEthToSend;
|
||||
}
|
||||
report.Add("Eth balance is over threshold.");
|
||||
return 0.Eth();
|
||||
}
|
||||
|
||||
return "Eth balance over threshold." + nl;
|
||||
private bool ShouldMintTestTokens(IGethNode gethNode, ICodexContracts contracts, EthAddress addr)
|
||||
{
|
||||
var testTokens = contracts.GetTestTokenBalance(gethNode, addr);
|
||||
return testTokens.Amount < 64m;
|
||||
}
|
||||
|
||||
private bool ShouldSendEth(IGethNode gethNode, EthAddress addr)
|
||||
{
|
||||
var eth = gethNode.GetEthBalance(addr);
|
||||
return eth.Eth < 1.0m;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace BiblioTech.Commands
|
|||
public override string Name => "report";
|
||||
public override string StartingMessage => "Getting that data...";
|
||||
public override string Description => "Admin only. Reports bot-interaction history for a user.";
|
||||
public override CommandOption[] Options => new[] { user };
|
||||
|
||||
protected override async Task Invoke(SocketSlashCommand command)
|
||||
{
|
||||
|
|
|
@ -11,10 +11,8 @@ namespace BiblioTech.Commands
|
|||
|
||||
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 };
|
||||
public override string Description => "Associates a Discord user with an Ethereum address.";
|
||||
public override CommandOption[] Options => new CommandOption[] { ethOption, optionalUser };
|
||||
|
||||
protected override async Task Invoke(SocketSlashCommand command)
|
||||
{
|
||||
|
|
|
@ -15,5 +15,8 @@ namespace BiblioTech
|
|||
|
||||
[Uniform("userdata", "u", "USERDATA", false, "Path where user data files will be saved.")]
|
||||
public string UserDataPath { get; set; } = "userdata";
|
||||
|
||||
[Uniform("admin-role", "a", "ADMINROLE", true, "Name of the Discord server admin role")]
|
||||
public string AdminRoleName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,11 @@ namespace BiblioTech
|
|||
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
|
||||
Config = uniformArgs.Parse();
|
||||
|
||||
if (!Directory.Exists(Config.UserDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(Config.UserDataPath);
|
||||
}
|
||||
|
||||
return new Program().MainAsync();
|
||||
}
|
||||
|
||||
|
@ -48,7 +53,7 @@ namespace BiblioTech
|
|||
var handler = new CommandHandler(client,
|
||||
new ClearUserAssociationCommand(),
|
||||
new GetBalanceCommand(monitor, ci, associateCommand),
|
||||
new MintCommand(monitor, ci),
|
||||
new MintCommand(monitor, ci, associateCommand),
|
||||
new ReportHistoryCommand(),
|
||||
associateCommand,
|
||||
new DeploymentsCommand(monitor)
|
||||
|
|
Loading…
Reference in New Issue