51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Discord;
|
|
|
|
namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
|
|
{
|
|
public class RequestParameter
|
|
{
|
|
public ParameterMatcher.ParameterType Type { get; }
|
|
private readonly string _value;
|
|
|
|
public RequestParameter(string value, ParameterMatcher.ParameterType type)
|
|
{
|
|
Type = type;
|
|
_value = value;
|
|
}
|
|
|
|
public int? AsInt()
|
|
{
|
|
if (int.TryParse(_value, out var i))
|
|
{
|
|
return i;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public string AsString()
|
|
{
|
|
return _value;
|
|
}
|
|
|
|
public ulong? AsUlong()
|
|
{
|
|
if (ulong.TryParse(_value, out var i))
|
|
{
|
|
return i;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public async Task<IGuildUser> AsDiscordUser(IGuild guild)
|
|
{
|
|
if (ulong.TryParse(_value, out var i))
|
|
{
|
|
return await guild.GetUserAsync(i);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |