Browse Source

Added GetPMChannel

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
2c7d049704
2 changed files with 30 additions and 3 deletions
  1. +27
    -3
      src/Discord.Net/DiscordClient.cs
  2. +3
    -0
      src/Discord.Net/User.cs

+ 27
- 3
src/Discord.Net/DiscordClient.cs View File

@@ -106,10 +106,23 @@ namespace Discord
{
var extendedModel = model as ChannelInfo;
channel.PermissionOverwrites = extendedModel.PermissionOverwrites;
channel.RecipientId = extendedModel.Recipient?.Id;
if (extendedModel.IsPrivate)
{
var user = _users.Update(extendedModel.Recipient.Id, extendedModel.Recipient);
channel.RecipientId = user.Id;
user.PrivateChannelId = channel.Id;
}
}
},
channel => { });
channel =>
{
if (channel.IsPrivate)
{
var user = channel.Recipient;
if (user.PrivateChannelId == channel.Id)
user.PrivateChannelId = null;
}
});
_messages = new AsyncCache<Message, API.Models.MessageReference>(
(key, parentKey) => new Message(key, parentKey, this),
(message, model) =>
@@ -451,7 +464,7 @@ namespace Discord
)
.FirstOrDefault();
}
/// <summary> Returns all users with the specified name. </summary>
/// <summary> Returns all users with the specified name across all servers. </summary>
/// <remarks> Name formats supported: Name and @Name. Search is case-insensitive. </remarks>
/*public IEnumerable<User> FindUsers(string name)
{
@@ -506,6 +519,17 @@ namespace Discord

/// <summary> Returns the channel with the specified id, or null if none was found. </summary>
public Channel GetChannel(string id) => _channels[id];
/// <summary> Returns a private channel with the provided user. </summary>
public Task<Channel> GetPMChannel(string userId, bool createIfNotExists = false)
=> GetPMChannel(_users[userId], createIfNotExists);
/// <summary> Returns a private channel with the provided user. </summary>
public async Task<Channel> GetPMChannel(User user, bool createIfNotExists = false)
{
var channel = user.PrivateChannel;
if (channel == null && createIfNotExists)
await CreatePMChannel(user);
return channel;
}
/// <summary> Returns all channels with the specified server and name. </summary>
/// <remarks> Name formats supported: Name and #Name. Search is case-insensitive. </remarks>
public IEnumerable<Channel> FindChannels(Server server, string name)


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

@@ -35,6 +35,9 @@ namespace Discord
/// <summary> Returns the string "&lt;@Id&gt;" to be used as a shortcut when including mentions in text. </summary>
public string Mention { get { return $"<@{Id}>"; } }

public string PrivateChannelId { get; internal set; }
public Channel PrivateChannel => _client.GetChannel(PrivateChannelId);

//TODO: Add voice
/// <summary> Returns the time this user last sent a message. </summary>
/// <remarks> Is not currently affected by voice activity </remarks>


Loading…
Cancel
Save