Moved mentions to MessageHelper, added Escape()
This commit is contained in:
46
src/Discord.Net/MessageHelper.cs
Normal file
46
src/Discord.Net/MessageHelper.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public static class MessageHelper
|
||||
{
|
||||
private static char[] specialChars = new char[] {'_', '*', '\\' }; //Backslash must always be last!
|
||||
|
||||
/// <summary> Removes all special formatting characters from the provided text. </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary> Returns the string used to create a user mention. </summary>
|
||||
public static string User(User user)
|
||||
=> $"<@{user.Id}>";
|
||||
/// <summary> Returns the string used to create a user mention. </summary>
|
||||
public static string User(string userId)
|
||||
=> $"<@{userId}>";
|
||||
|
||||
/// <summary> Returns the string used to create a channel mention. </summary>
|
||||
public static string Channel(Channel channel)
|
||||
=> $"<#{channel.Id}>";
|
||||
/// <summary> Returns the string used to create a channel mention. </summary>
|
||||
public static string Channel(string channelId)
|
||||
=> $"<#{channelId}>";
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,6 @@ namespace Discord
|
||||
/// <remarks> This field is only ever populated for the current logged in user. </remarks>
|
||||
public bool IsVerified { get; internal set; }
|
||||
|
||||
/// <summary> Returns the string "<@Id>" to be used as a shortcut when including mentions in text. </summary>
|
||||
public string Mention => $"<@{Id}>";
|
||||
|
||||
public string PrivateChannelId { get; set; }
|
||||
public Channel PrivateChannel => _client.GetChannel(PrivateChannelId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user