2023-10-20 07:49:23 +00:00
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using GethPlugin;
|
|
|
|
|
|
|
|
|
|
namespace BiblioTech.TokenCommands
|
|
|
|
|
{
|
|
|
|
|
public class EthAddressOption : CommandOption
|
|
|
|
|
{
|
|
|
|
|
public EthAddressOption()
|
2023-10-20 09:20:38 +00:00
|
|
|
|
: base(name: "ethaddress",
|
2023-10-20 07:49:23 +00:00
|
|
|
|
description: "Ethereum address starting with '0x'.",
|
2023-10-22 08:10:52 +00:00
|
|
|
|
type: Discord.ApplicationCommandOptionType.String,
|
|
|
|
|
isRequired: true)
|
2023-10-20 07:49:23 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<EthAddress?> Parse(SocketSlashCommand command)
|
|
|
|
|
{
|
|
|
|
|
var ethOptionData = command.Data.Options.SingleOrDefault(o => o.Name == Name);
|
|
|
|
|
if (ethOptionData == null)
|
|
|
|
|
{
|
|
|
|
|
await command.RespondAsync("EthAddress option not received.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var ethAddressStr = ethOptionData.Value as string;
|
|
|
|
|
if (string.IsNullOrEmpty(ethAddressStr))
|
|
|
|
|
{
|
|
|
|
|
// todo, validate that it is an eth address.
|
|
|
|
|
await command.RespondAsync("EthAddress is null or invalid.");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new EthAddress(ethAddressStr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|