Browse Source

Added Mention function to User, GlobalUser, Channel and Role. Obsoleted old Mention static class.

tags/docs-0.9
RogueException 9 years ago
parent
commit
bba866652e
4 changed files with 14 additions and 3 deletions
  1. +3
    -0
      src/Discord.Net/Models/Channel.cs
  2. +3
    -1
      src/Discord.Net/Models/GlobalUser.cs
  3. +5
    -1
      src/Discord.Net/Models/Role.cs
  4. +3
    -1
      src/Discord.Net/Models/User.cs

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

@@ -91,6 +91,9 @@ namespace Discord
private PermissionOverwrite[] _permissionOverwrites; private PermissionOverwrite[] _permissionOverwrites;
public IEnumerable<PermissionOverwrite> PermissionOverwrites { get { return _permissionOverwrites; } internal set { _permissionOverwrites = value.ToArray(); } } public IEnumerable<PermissionOverwrite> PermissionOverwrites { get { return _permissionOverwrites; } internal set { _permissionOverwrites = value.ToArray(); } }


/// <summary> Returns the string used to mention this channel. </summary>
public string Mention => $"<#{Id}>";

internal Channel(DiscordClient client, long id, long? serverId, long? recipientId) internal Channel(DiscordClient client, long id, long? serverId, long? recipientId)
: base(client, id) : base(client, id)
{ {


+ 3
- 1
src/Discord.Net/Models/GlobalUser.cs View File

@@ -8,7 +8,6 @@ namespace Discord
{ {
public sealed class GlobalUser : CachedObject<long> public sealed class GlobalUser : CachedObject<long>
{ {

/// <summary> Returns the email for this user. Note: this field is only ever populated for the current logged in user. </summary> /// <summary> Returns the email for this user. Note: this field is only ever populated for the current logged in user. </summary>
[JsonIgnore] [JsonIgnore]
public string Email { get; private set; } public string Email { get; private set; }
@@ -39,6 +38,9 @@ namespace Discord
private IEnumerable<long> ServerIds => _users.Select(x => x.Key); private IEnumerable<long> ServerIds => _users.Select(x => x.Key);
private readonly ConcurrentDictionary<long, User> _users; private readonly ConcurrentDictionary<long, User> _users;


/// <summary> Returns the string used to mention this user. </summary>
public string Mention => $"<@{Id}>";

internal GlobalUser(DiscordClient client, long id) internal GlobalUser(DiscordClient client, long id)
: base(client, id) : base(client, id)
{ {


+ 5
- 1
src/Discord.Net/Models/Role.cs View File

@@ -1,12 +1,13 @@
using Discord.API; using Discord.API;
using Newtonsoft.Json; using Newtonsoft.Json;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;


namespace Discord namespace Discord
{ {
public sealed class Role : CachedObject<long> public sealed class Role : CachedObject<long>
{
{
/// <summary> Returns the name of this role. </summary> /// <summary> Returns the name of this role. </summary>
public string Name { get; private set; } public string Name { get; private set; }
/// <summary> If true, this role is displayed isolated from other users. </summary> /// <summary> If true, this role is displayed isolated from other users. </summary>
@@ -38,6 +39,9 @@ namespace Discord
private IEnumerable<long> MemberIds => Members.Select(x => x.Id); private IEnumerable<long> MemberIds => Members.Select(x => x.Id);
//TODO: Add local members cache //TODO: Add local members cache


/// <summary> Returns the string used to mention this role. </summary>
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) internal Role(DiscordClient client, long id, long serverId)
: base(client, id) : base(client, id)
{ {


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

@@ -41,7 +41,6 @@ namespace Discord
public bool IsServerMuted { get; private set; } public bool IsServerMuted { get; private set; }
public bool IsServerDeafened { get; private set; } public bool IsServerDeafened { get; private set; }
public bool IsServerSuppressed { get; private set; } public bool IsServerSuppressed { get; private set; }
public bool IsSpeaking { get; internal set; }
public bool IsPrivate => _server.Id == null; public bool IsPrivate => _server.Id == null;


public string SessionId { get; private set; } public string SessionId { get; private set; }
@@ -117,6 +116,9 @@ namespace Discord
} }
} }


/// <summary> Returns the string used to mention this user. </summary>
public string Mention => $"<@{Id}>";

internal User(DiscordClient client, long id, long? serverId) internal User(DiscordClient client, long id, long? serverId)
: base(client, id) : base(client, id)
{ {


Loading…
Cancel
Save