From 602ac134e5c88f200815736573162145b7134b74 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sun, 26 Jun 2016 22:54:12 -0300 Subject: [PATCH] Added Prefix check extensions to IMessage --- .../Extensions/MessageExtensions.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/Discord.Net.Commands/Extensions/MessageExtensions.cs diff --git a/src/Discord.Net.Commands/Extensions/MessageExtensions.cs b/src/Discord.Net.Commands/Extensions/MessageExtensions.cs new file mode 100644 index 000000000..2ba4973fe --- /dev/null +++ b/src/Discord.Net.Commands/Extensions/MessageExtensions.cs @@ -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; + } + } +} \ No newline at end of file