Browse Source

Update MessageExtensions.cs

pull/1130/head
JustNrik GitHub 7 years ago
parent
commit
a2b88b51bf
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 0 deletions
  1. +17
    -0
      src/Discord.Net.Commands/Extensions/MessageExtensions.cs

+ 17
- 0
src/Discord.Net.Commands/Extensions/MessageExtensions.cs View File

@@ -42,5 +42,22 @@ namespace Discord.Commands
}
return false;
}
public static bool HasCharSuffix(this IUserMessage msg, char c)
=> msg.Content.Length > 0 && msg.Content[msg.Content.Length - 1] == c;
public static bool HasStringSuffix(this IUserMessage msg, string str, StringComparison comparisonType = StringComparison.Ordinal)
=> msg.Content.EndsWith(str, comparisonType);
public static bool HasMentionSuffix(this IUserMessage msg, IUser user)
{
var text = msg.Content;
if (text.Length <= 3 || text[text.Length - 1] != '>') return false;

int iniPos = text.IndexOf('<');
if (iniPos == -1) return false;
if (!MentionUtils.TryParseUser(text.Substring(iniPos, text.Length - iniPos), out ulong userId)) return false;
if (user.Id == userId) return true;

return false;
}
}
}

Loading…
Cancel
Save