Added Prefix check extensions to IMessage

This commit is contained in:
RogueException
2016-06-26 22:54:12 -03:00
parent f76d468582
commit 602ac134e5

View File

@@ -0,0 +1,44 @@
namespace Discord.Commands
{
public static class MessageExtensions
{
public static bool HasCharPrefix(this IMessage msg, char c, ref int argPos)
{
var text = msg.RawText;
if (text.Length > 0 && text[0] == c)
{
argPos = 1;
return true;
}
return false;
}
public static bool HasStringPrefix(this IMessage msg, string str, ref int argPos)
{
var text = msg.RawText;
str = str + ' ';
if (text.StartsWith(str))
{
argPos = str.Length;
return true;
}
return false;
}
public static bool HasMentionPrefix(this IMessage msg, IUser user, ref int argPos)
{
var text = msg.RawText;
string mention = user.Mention + ' ';
if (text.StartsWith(mention))
{
argPos = mention.Length;
return true;
}
string nickMention = user.NicknameMention + ' ';
if (text.StartsWith(mention))
{
argPos = nickMention.Length;
return true;
}
return false;
}
}
}