From bba866652ebd42af0c6a382c62bc09ec186daef8 Mon Sep 17 00:00:00 2001 From: RogueException Date: Thu, 3 Dec 2015 06:37:11 -0400 Subject: [PATCH] Added Mention function to User, GlobalUser, Channel and Role. Obsoleted old Mention static class. --- src/Discord.Net/Models/Channel.cs | 3 +++ src/Discord.Net/Models/GlobalUser.cs | 4 +++- src/Discord.Net/Models/Role.cs | 6 +++++- src/Discord.Net/Models/User.cs | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net/Models/Channel.cs b/src/Discord.Net/Models/Channel.cs index b2233aa20..ef8c49409 100644 --- a/src/Discord.Net/Models/Channel.cs +++ b/src/Discord.Net/Models/Channel.cs @@ -91,6 +91,9 @@ namespace Discord private PermissionOverwrite[] _permissionOverwrites; public IEnumerable PermissionOverwrites { get { return _permissionOverwrites; } internal set { _permissionOverwrites = value.ToArray(); } } + /// Returns the string used to mention this channel. + public string Mention => $"<#{Id}>"; + internal Channel(DiscordClient client, long id, long? serverId, long? recipientId) : base(client, id) { diff --git a/src/Discord.Net/Models/GlobalUser.cs b/src/Discord.Net/Models/GlobalUser.cs index 016f522e0..edc08b988 100644 --- a/src/Discord.Net/Models/GlobalUser.cs +++ b/src/Discord.Net/Models/GlobalUser.cs @@ -8,7 +8,6 @@ namespace Discord { public sealed class GlobalUser : CachedObject { - /// Returns the email for this user. Note: this field is only ever populated for the current logged in user. [JsonIgnore] public string Email { get; private set; } @@ -39,6 +38,9 @@ namespace Discord private IEnumerable ServerIds => _users.Select(x => x.Key); private readonly ConcurrentDictionary _users; + /// Returns the string used to mention this user. + public string Mention => $"<@{Id}>"; + internal GlobalUser(DiscordClient client, long id) : base(client, id) { diff --git a/src/Discord.Net/Models/Role.cs b/src/Discord.Net/Models/Role.cs index 285cc59f3..c2f5c914a 100644 --- a/src/Discord.Net/Models/Role.cs +++ b/src/Discord.Net/Models/Role.cs @@ -1,12 +1,13 @@ using Discord.API; using Newtonsoft.Json; +using System; using System.Collections.Generic; using System.Linq; namespace Discord { public sealed class Role : CachedObject - { + { /// Returns the name of this role. public string Name { get; private set; } /// If true, this role is displayed isolated from other users. @@ -38,6 +39,9 @@ namespace Discord private IEnumerable MemberIds => Members.Select(x => x.Id); //TODO: Add local members cache + /// Returns the string used to mention this role. + public string Mention { get { if (IsEveryone) return "@everyone"; else throw new InvalidOperationException("Discord currently only supports referencing the everyone role"); } } + internal Role(DiscordClient client, long id, long serverId) : base(client, id) { diff --git a/src/Discord.Net/Models/User.cs b/src/Discord.Net/Models/User.cs index abbac205f..0e3f82b44 100644 --- a/src/Discord.Net/Models/User.cs +++ b/src/Discord.Net/Models/User.cs @@ -41,7 +41,6 @@ namespace Discord public bool IsServerMuted { get; private set; } public bool IsServerDeafened { get; private set; } public bool IsServerSuppressed { get; private set; } - public bool IsSpeaking { get; internal set; } public bool IsPrivate => _server.Id == null; public string SessionId { get; private set; } @@ -117,6 +116,9 @@ namespace Discord } } + /// Returns the string used to mention this user. + public string Mention => $"<@{Id}>"; + internal User(DiscordClient client, long id, long? serverId) : base(client, id) {