diff --git a/src/Discord.Net/MessageHelper.cs b/src/Discord.Net/MessageHelper.cs new file mode 100644 index 000000000..06f05350f --- /dev/null +++ b/src/Discord.Net/MessageHelper.cs @@ -0,0 +1,46 @@ +using System.Text; + +namespace Discord +{ + public static class MessageHelper + { + private static char[] specialChars = new char[] {'_', '*', '\\' }; //Backslash must always be last! + + /// Removes all special formatting characters from the provided text. + public static string Escape(string text) + { + if (text.IndexOfAny(specialChars) >= 0) + { + StringBuilder builder = new StringBuilder(text); + foreach (char c in specialChars) + { + int length = builder.Length; + for (int i = 0; i < length; i++) + { + if (builder[i] == c) + { + builder.Insert(i, '\\'); + length++; + } + } + } + return builder.ToString(); + } + return text; + } + + /// Returns the string used to create a user mention. + public static string User(User user) + => $"<@{user.Id}>"; + /// Returns the string used to create a user mention. + public static string User(string userId) + => $"<@{userId}>"; + + /// Returns the string used to create a channel mention. + public static string Channel(Channel channel) + => $"<#{channel.Id}>"; + /// Returns the string used to create a channel mention. + public static string Channel(string channelId) + => $"<#{channelId}>"; + } +} diff --git a/src/Discord.Net/Models/User.cs b/src/Discord.Net/Models/User.cs index 870341130..19575d014 100644 --- a/src/Discord.Net/Models/User.cs +++ b/src/Discord.Net/Models/User.cs @@ -28,9 +28,6 @@ namespace Discord /// This field is only ever populated for the current logged in user. public bool IsVerified { get; internal set; } - /// Returns the string "<@Id>" to be used as a shortcut when including mentions in text. - public string Mention => $"<@{Id}>"; - public string PrivateChannelId { get; set; } public Channel PrivateChannel => _client.GetChannel(PrivateChannelId);