DeukBot4/DeukBot4/MessageHandlers/CommandHandler/RequestStructure/RequestParameter.cs

49 lines
1017 B
C#
Raw Normal View History

2018-03-28 23:34:48 +00:00
using System;
2018-03-30 12:51:38 +00:00
using System.Linq;
using System.Threading.Tasks;
using Discord;
2018-03-28 23:34:48 +00:00
namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
{
public class RequestParameter
{
private readonly string _value;
public RequestParameter(string value)
{
_value = value;
}
2018-03-30 17:03:25 +00:00
public int? AsInt()
2018-03-28 23:34:48 +00:00
{
if (int.TryParse(_value, out var i))
{
return i;
}
2018-03-30 17:03:25 +00:00
return null;
2018-03-28 23:34:48 +00:00
}
public string AsString()
{
return _value;
}
2018-03-29 19:57:16 +00:00
2018-03-30 17:03:25 +00:00
public ulong? AsUlong()
2018-03-29 19:57:16 +00:00
{
if (ulong.TryParse(_value, out var i))
{
return i;
}
2018-03-30 17:03:25 +00:00
return null;
2018-03-29 19:57:16 +00:00
}
2018-03-30 12:51:38 +00:00
public async Task<IGuildUser> AsDiscordUser(IGuild guild)
{
if (ulong.TryParse(_value, out var i))
{
return await guild.GetUserAsync(i);
}
return null;
}
2018-03-28 23:34:48 +00:00
}
}