Added CreatePMChannel
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Discord.Net.Tests
|
||||
Task.WaitAll(_bot2.Servers.Select(x => _bot2.LeaveServer(x)).ToArray());
|
||||
|
||||
//Create new server and invite other bot to it
|
||||
_testServer = _bot1.CreateServer("Discord.Net Testbed", Regions.US_East).Result;
|
||||
_testServer = _bot1.CreateServer("Discord.Net Testing", Regions.US_East).Result;
|
||||
_testServerChannel = _testServer.DefaultChannel;
|
||||
Invite invite = _bot1.CreateInvite(_testServer, 60, 1, false, false).Result;
|
||||
_bot2.AcceptInvite(invite).Wait();
|
||||
|
||||
@@ -41,6 +41,11 @@ namespace Discord.API
|
||||
var request = new APIRequests.CreateChannel { Name = name, Type = channelType };
|
||||
return Http.Post<APIResponses.CreateChannel>(Endpoints.ServerChannels(serverId), request, options);
|
||||
}
|
||||
public static Task<APIResponses.CreateChannel> CreatePMChannel(string myId, string recipientId, HttpOptions options)
|
||||
{
|
||||
var request = new APIRequests.CreatePMChannel { RecipientId = recipientId };
|
||||
return Http.Post<APIResponses.CreateChannel>(Endpoints.UserChannels(myId), request, options);
|
||||
}
|
||||
public static Task<APIResponses.DestroyChannel> DestroyChannel(string channelId, HttpOptions options)
|
||||
=> Http.Delete<APIResponses.DestroyChannel>(Endpoints.Channel(channelId), options);
|
||||
public static Task<APIResponses.GetMessages[]> GetMessages(string channelId, HttpOptions options)
|
||||
|
||||
@@ -16,6 +16,14 @@
|
||||
public static readonly string AuthLogin = $"{Auth}/login";
|
||||
public static readonly string AuthLogout = $"{Auth}/logout";
|
||||
|
||||
// /api/channels
|
||||
public static readonly string Channels = $"{BaseApi}/channels";
|
||||
public static string Channel(string id) => $"{Channels}/{id}";
|
||||
public static string ChannelTyping(string id) => $"{Channels}/{id}/typing";
|
||||
public static string ChannelMessages(string id) => $"{Channels}/{id}/messages";
|
||||
public static string ChannelMessages(string id, int limit) => $"{Channels}/{id}/messages?limit={limit}";
|
||||
public static string ChannelInvites(string id) => $"{Channels}/{id}/invites";
|
||||
|
||||
// /api/guilds
|
||||
public static readonly string Servers = $"{BaseApi}/guilds";
|
||||
public static string Server(string id) => $"{Servers}/{id}";
|
||||
@@ -27,15 +35,11 @@
|
||||
public static readonly string Invites = $"{BaseApi}/invite";
|
||||
public static string Invite(string id) => $"{Invites}/{id}";
|
||||
|
||||
// /api/channels
|
||||
public static readonly string Channels = $"{BaseApi}/channels";
|
||||
public static string Channel(string id) => $"{Channels}/{id}";
|
||||
public static string ChannelTyping(string id) => $"{Channels}/{id}/typing";
|
||||
public static string ChannelMessages(string id) => $"{Channels}/{id}/messages";
|
||||
public static string ChannelMessages(string id, int limit) => $"{Channels}/{id}/messages?limit={limit}";
|
||||
public static string ChannelInvites(string id) => $"{Channels}/{id}/invites";
|
||||
// /api/users
|
||||
public static readonly string Users = $"{BaseApi}/users";
|
||||
public static string UserChannels(string id) => $"{Users}/{id}/channels";
|
||||
|
||||
// /api/voice
|
||||
// /api/voice
|
||||
public static readonly string Voice = $"{BaseApi}/voice";
|
||||
public static readonly string VoiceRegions = $"{Voice}/regions";
|
||||
public static readonly string VoiceIce = $"{Voice}/ice";
|
||||
|
||||
@@ -38,6 +38,11 @@ namespace Discord.API.Models
|
||||
[JsonProperty(PropertyName = "type")]
|
||||
public string Type;
|
||||
}
|
||||
public class CreatePMChannel
|
||||
{
|
||||
[JsonProperty(PropertyName = "recipient_id")]
|
||||
public string RecipientId;
|
||||
}
|
||||
|
||||
public class CreateInvite
|
||||
{
|
||||
|
||||
@@ -444,16 +444,15 @@ namespace Discord
|
||||
}
|
||||
public Task<Server> LeaveServer(Server server)
|
||||
=> LeaveServer(server.Id);
|
||||
public async Task<Server> LeaveServer(string id)
|
||||
public async Task<Server> LeaveServer(string serverId)
|
||||
{
|
||||
CheckReady();
|
||||
try
|
||||
{
|
||||
await DiscordAPI.LeaveServer(id, _httpOptions);
|
||||
await DiscordAPI.LeaveServer(serverId, _httpOptions);
|
||||
}
|
||||
//Happens if the room was destroyed as we try to leave it
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) {}
|
||||
return _servers.Remove(id);
|
||||
return _servers.Remove(serverId);
|
||||
}
|
||||
|
||||
//Channels
|
||||
@@ -465,13 +464,25 @@ namespace Discord
|
||||
var response = await DiscordAPI.CreateChannel(serverId, name, region, _httpOptions);
|
||||
return _channels.Update(response.Id, response);
|
||||
}
|
||||
public Task<Channel> CreatePMChannel(User user, string name, string region)
|
||||
=> CreateChannel(user.Id, name, region);
|
||||
public async Task<Channel> CreatePMChannel(string recipientId, string name, string region)
|
||||
{
|
||||
CheckReady();
|
||||
var response = await DiscordAPI.CreatePMChannel(UserId, recipientId, _httpOptions);
|
||||
return _channels.Update(response.Id, response);
|
||||
}
|
||||
public Task<Channel> DestroyChannel(Channel channel)
|
||||
=> DestroyChannel(channel.Id);
|
||||
public async Task<Channel> DestroyChannel(string channelId)
|
||||
{
|
||||
CheckReady();
|
||||
var response = await DiscordAPI.DestroyChannel(channelId, _httpOptions);
|
||||
return _channels.Remove(response.Id);
|
||||
try
|
||||
{
|
||||
var response = await DiscordAPI.DestroyChannel(channelId, _httpOptions);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
return _channels.Remove(channelId);
|
||||
}
|
||||
|
||||
//Bans
|
||||
@@ -492,10 +503,14 @@ namespace Discord
|
||||
=> Unban(server.Id, userId);
|
||||
public Task Unban(string server, User user)
|
||||
=> Unban(server, user.Id);
|
||||
public Task Unban(string serverId, string userId)
|
||||
public async Task Unban(string serverId, string userId)
|
||||
{
|
||||
CheckReady();
|
||||
return DiscordAPI.Unban(serverId, userId, _httpOptions);
|
||||
try
|
||||
{
|
||||
await DiscordAPI.Unban(serverId, userId, _httpOptions);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
|
||||
@@ -553,9 +568,13 @@ namespace Discord
|
||||
public async Task DeleteInvite(string id)
|
||||
{
|
||||
CheckReady();
|
||||
//Check if this is a human-readable link and get its ID
|
||||
var response = await DiscordAPI.GetInvite(id, _httpOptions);
|
||||
await DiscordAPI.DeleteInvite(response.Code, _httpOptions);
|
||||
try
|
||||
{
|
||||
//Check if this is a human-readable link and get its ID
|
||||
var response = await DiscordAPI.GetInvite(id, _httpOptions);
|
||||
await DiscordAPI.DeleteInvite(response.Code, _httpOptions);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
//Chat
|
||||
|
||||
Reference in New Issue
Block a user