Browse Source

Moved mentions to MessageHelper, added Escape()

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
cd408fea49
2 changed files with 46 additions and 3 deletions
  1. +46
    -0
      src/Discord.Net/MessageHelper.cs
  2. +0
    -3
      src/Discord.Net/Models/User.cs

+ 46
- 0
src/Discord.Net/MessageHelper.cs View 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}>";
}
}

+ 0
- 3
src/Discord.Net/Models/User.cs View File

@@ -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 "&lt;@Id&gt;" 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);



Loading…
Cancel
Save