Browse Source

Added Prefix check extensions to IMessage

tags/1.0-rc
RogueException 9 years ago
parent
commit
602ac134e5
1 changed files with 44 additions and 0 deletions
  1. +44
    -0
      src/Discord.Net.Commands/Extensions/MessageExtensions.cs

+ 44
- 0
src/Discord.Net.Commands/Extensions/MessageExtensions.cs 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;
}
}
}

Loading…
Cancel
Save