Changed GetPMChannel to GetOrCreatePMChannel, added SendPrivateMessage, hid User.PrivateChannel
This commit is contained in:
@@ -57,9 +57,6 @@ namespace Discord
|
||||
return _channels.Update(response.Id, serverId, response);
|
||||
}
|
||||
|
||||
/// <summary> Creates a new private channel with the provided user. </summary>
|
||||
public Task<Channel> CreatePMChannel(User user)
|
||||
=> CreatePMChannel(user?.Id);
|
||||
/// <summary> Creates a new private channel with the provided user. </summary>
|
||||
public async Task<Channel> CreatePMChannel(string userId)
|
||||
{
|
||||
@@ -278,6 +275,21 @@ namespace Discord
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/// <summary> Sends a private message to the provided channel. </summary>
|
||||
public async Task<Message[]> SendPrivateMessage(User user, string text)
|
||||
=> await SendMessage(await GetOrCreatePMChannel(user), text, new string[0]);
|
||||
/// <summary> Sends a private message to the provided channel. </summary>
|
||||
public async Task<Message[]> SendPrivateMessage(string userId, string text)
|
||||
=> await SendMessage(await GetOrCreatePMChannel(userId), text, new string[0]);
|
||||
/*/// <summary> Sends a private message to the provided user, mentioning certain users. </summary>
|
||||
/// <remarks> While not required, it is recommended to include a mention reference in the text (see User.Mention). </remarks>
|
||||
public async Task<Message[]> SendPrivateMessage(User user, string text, string[] mentions)
|
||||
=> SendMessage(await GetOrCreatePMChannel(user), text, mentions);
|
||||
/// <summary> Sends a private message to the provided user, mentioning certain users. </summary>
|
||||
/// <remarks> While not required, it is recommended to include a mention reference in the text (see User.Mention). </remarks>
|
||||
public async Task<Message[]> SendPrivateMessage(string userId, string text, string[] mentions)
|
||||
=> SendMessage(await GetOrCreatePMChannel(userId), text, mentions);*/
|
||||
|
||||
|
||||
/// <summary> Edits a message the provided message. </summary>
|
||||
public Task EditMessage(Message message, string text)
|
||||
|
||||
@@ -286,7 +286,8 @@ namespace Discord
|
||||
}
|
||||
|
||||
/// <summary> Returns the user with the specified id, or null if none was found. </summary>
|
||||
public User GetUser(string id) => _users[id];
|
||||
public User GetUser(string id)
|
||||
=> _users[id];
|
||||
/// <summary> Returns the user with the specified name and discriminator, or null if none was found. </summary>
|
||||
/// <remarks> Name formats supported: Name and @Name. Search is case-insensitive. </remarks>
|
||||
public User GetUser(string name, string discriminator)
|
||||
@@ -369,7 +370,8 @@ namespace Discord
|
||||
}
|
||||
|
||||
/// <summary> Returns the server with the specified id, or null if none was found. </summary>
|
||||
public Server GetServer(string id) => _servers[id];
|
||||
public Server GetServer(string id)
|
||||
=> _servers[id];
|
||||
/// <summary> Returns all servers with the specified name. </summary>
|
||||
/// <remarks> Search is case-insensitive. </remarks>
|
||||
public IEnumerable<Server> FindServers(string name)
|
||||
@@ -382,25 +384,21 @@ 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)
|
||||
/// <summary> Returns the private channel with the provided user, creating one if it does not currently exist. </summary>
|
||||
public Task<Channel> GetOrCreatePMChannel(string userId)
|
||||
=> GetOrCreatePMChannel(_users[userId]);
|
||||
/// <summary> Returns the private channel with the provided user, creating one if it does not currently exist. </summary>
|
||||
public async Task<Channel> GetOrCreatePMChannel(User user)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
if (createIfNotExists)
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
CheckReady();
|
||||
if (user == null) throw new ArgumentNullException(nameof(user));
|
||||
|
||||
var channel = user.PrivateChannel;
|
||||
if (channel == null && createIfNotExists)
|
||||
await CreatePMChannel(user);
|
||||
return channel;
|
||||
if (channel != null)
|
||||
return channel;
|
||||
return await CreatePMChannel(user?.Id);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
@@ -426,7 +424,8 @@ namespace Discord
|
||||
}
|
||||
|
||||
/// <summary> Returns the role with the specified id, or null if none was found. </summary>
|
||||
public Role GetRole(string id) => _roles[id];
|
||||
public Role GetRole(string id)
|
||||
=> _roles[id];
|
||||
/// <summary> Returns all roles with the specified server and name. </summary>
|
||||
/// <remarks> Name formats supported: Name and @Name. Search is case-insensitive. </remarks>
|
||||
public IEnumerable<Role> FindRoles(Server server, string name)
|
||||
@@ -452,6 +451,7 @@ namespace Discord
|
||||
}
|
||||
|
||||
/// <summary> Returns the message with the specified id, or null if none was found. </summary>
|
||||
public Message GetMessage(string id) => _messages[id];
|
||||
public Message GetMessage(string id)
|
||||
=> _messages[id];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace Discord
|
||||
/// <summary> Returns the string "<@Id>" to be used as a shortcut when including mentions in text. </summary>
|
||||
public string Mention => $"<@{Id}>";
|
||||
|
||||
public string PrivateChannelId { get; internal set; }
|
||||
public Channel PrivateChannel => _client.GetChannel(PrivateChannelId);
|
||||
internal string PrivateChannelId { get; internal set; }
|
||||
internal Channel PrivateChannel => _client.GetChannel(PrivateChannelId);
|
||||
|
||||
//TODO: Add voice
|
||||
/// <summary> Returns the time this user last sent a message. </summary>
|
||||
|
||||
Reference in New Issue
Block a user