Cleaned up mention logic, removed User.NicknameMention
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
public static bool HasStringPrefix(this IMessage msg, string str, ref int argPos)
|
||||
{
|
||||
var text = msg.Content;
|
||||
//str = str + ' ';
|
||||
if (text.StartsWith(str))
|
||||
{
|
||||
argPos = str.Length;
|
||||
@@ -26,19 +25,14 @@
|
||||
public static bool HasMentionPrefix(this IMessage msg, IUser user, ref int argPos)
|
||||
{
|
||||
var text = msg.Content;
|
||||
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;
|
||||
if (text.Length <= 3 || text[0] != '<' || text[1] != '@') return false;
|
||||
|
||||
int endPos = text.IndexOf('>');
|
||||
if (endPos == -1) return false;
|
||||
|
||||
ulong userId;
|
||||
if (!MentionUtils.TryParseUser(text.Substring(0, endPos), out userId)) return false;
|
||||
return userId == user.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,8 @@ namespace Discord
|
||||
public ushort DiscriminatorValue => User.DiscriminatorValue;
|
||||
public bool IsAttached => User.IsAttached;
|
||||
public bool IsBot => User.IsBot;
|
||||
public string Mention => User.Mention;
|
||||
public string NicknameMention => User.NicknameMention;
|
||||
public string Username => User.Username;
|
||||
public string Mention => MentionUtils.Mention(this, false);
|
||||
|
||||
public virtual UserStatus Status => UserStatus.Unknown;
|
||||
public virtual Game Game => null;
|
||||
|
||||
@@ -29,8 +29,7 @@ namespace Discord
|
||||
public ushort DiscriminatorValue => User.DiscriminatorValue;
|
||||
public bool IsAttached => User.IsAttached;
|
||||
public bool IsBot => User.IsBot;
|
||||
public string Mention => User.Mention;
|
||||
public string NicknameMention => User.NicknameMention;
|
||||
public string Mention => MentionUtils.Mention(this, Nickname != null);
|
||||
public string Username => User.Username;
|
||||
|
||||
public virtual UserStatus Status => UserStatus.Unknown;
|
||||
|
||||
@@ -12,7 +12,5 @@ namespace Discord
|
||||
bool IsBot { get; }
|
||||
/// <summary> Gets the username for this user. </summary>
|
||||
string Username { get; }
|
||||
/// <summary> Returns a special string used to mention this object, by nickname. </summary>
|
||||
string NicknameMention { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@ namespace Discord
|
||||
|
||||
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, _avatarId);
|
||||
public string Discriminator => DiscriminatorValue.ToString("D4");
|
||||
public string Mention => MentionUtils.Mention(this, false);
|
||||
public string NicknameMention => MentionUtils.Mention(this, true);
|
||||
public string Mention => MentionUtils.Mention(this);
|
||||
public virtual Game Game => null;
|
||||
public virtual UserStatus Status => UserStatus.Unknown;
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@ namespace Discord
|
||||
public ushort DiscriminatorValue => User.DiscriminatorValue;
|
||||
public bool IsAttached => User.IsAttached;
|
||||
public bool IsBot => User.IsBot;
|
||||
public string Mention => User.Mention;
|
||||
public string NicknameMention => User.NicknameMention;
|
||||
public string Mention => MentionUtils.Mention(this);
|
||||
public string Username => User.Username;
|
||||
|
||||
public CachedDMUser(CachedGlobalUser user)
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace Discord
|
||||
private static readonly Regex _channelRegex = new Regex(@"<#([0-9]+)>", RegexOptions.Compiled);
|
||||
private static readonly Regex _roleRegex = new Regex(@"<@&([0-9]+)>", RegexOptions.Compiled);
|
||||
|
||||
internal static string Mention(IUser user, bool useNickname) => useNickname ? $"<@!{user.Id}>" : $"<@{user.Id}>";
|
||||
//Unsure the system can be positive a user doesn't have a nickname, assume useNickname = true (source: Jake)
|
||||
internal static string Mention(IUser user, bool useNickname = true) => useNickname ? $"<@!{user.Id}>" : $"<@{user.Id}>";
|
||||
internal static string Mention(IChannel channel) => $"<#{channel.Id}>";
|
||||
internal static string Mention(IRole role) => $"<&{role.Id}>";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user