| @@ -29,7 +29,7 @@ namespace Discord.Net.Tests | |||||
| Task.WaitAll(_bot1.Servers.Select(x => _bot1.LeaveServer(x)).ToArray()); | Task.WaitAll(_bot1.Servers.Select(x => _bot1.LeaveServer(x)).ToArray()); | ||||
| Task.WaitAll(_bot2.Servers.Select(x => _bot2.LeaveServer(x)).ToArray()); | Task.WaitAll(_bot2.Servers.Select(x => _bot2.LeaveServer(x)).ToArray()); | ||||
| _testServer = _bot1.CreateServer("Discord.Net Testbed", Region.US_East).Result; | |||||
| _testServer = _bot1.CreateServer("Discord.Net Testbed", Regions.US_East).Result; | |||||
| _testServerChannel = _testServer.DefaultChannel; | _testServerChannel = _testServer.DefaultChannel; | ||||
| Invite invite = _bot1.CreateInvite(_testServer, 60, 1, false, false).Result; | Invite invite = _bot1.CreateInvite(_testServer, 60, 1, false, false).Result; | ||||
| _bot2.AcceptInvite(invite).Wait(); | _bot2.AcceptInvite(invite).Wait(); | ||||
| @@ -48,17 +48,22 @@ namespace Discord.Net.Tests | |||||
| } | } | ||||
| [TestMethod] | [TestMethod] | ||||
| public void TestCreateRoom() | |||||
| public void TestCreateTextRoom() | |||||
| => TestCreateRoom(ChannelTypes.Text); | |||||
| [TestMethod] | |||||
| public void TestCreateVoiceRoom() | |||||
| => TestCreateRoom(ChannelTypes.Voice); | |||||
| private void TestCreateRoom(string type) | |||||
| { | { | ||||
| Channel channel; | |||||
| Channel channel = null; | |||||
| string name = $"test_{_random.Next()}"; | string name = $"test_{_random.Next()}"; | ||||
| AssertEvent<DiscordClient.ChannelEventArgs>( | AssertEvent<DiscordClient.ChannelEventArgs>( | ||||
| "ChannelCreated event never received", | "ChannelCreated event never received", | ||||
| () => channel = _bot1.CreateChannel(_testServerChannel, name), | |||||
| () => channel = _bot1.CreateChannel(_testServer, name, type).Result, | |||||
| x => _bot2.ChannelCreated += x, | x => _bot2.ChannelCreated += x, | ||||
| x => _bot2.ChannelCreated -= x, | x => _bot2.ChannelCreated -= x, | ||||
| (s, e) => e.Channel.Name == name); | (s, e) => e.Channel.Name == name); | ||||
| AssertEvent<DiscordClient.ChannelEventArgs>( | AssertEvent<DiscordClient.ChannelEventArgs>( | ||||
| "ChannelDestroyed event never received", | "ChannelDestroyed event never received", | ||||
| () => _bot1.DestroyChannel(channel), | () => _bot1.DestroyChannel(channel), | ||||
| @@ -24,9 +24,7 @@ namespace Discord.API | |||||
| return response; | return response; | ||||
| } | } | ||||
| public static Task Logout(HttpOptions options) | public static Task Logout(HttpOptions options) | ||||
| { | |||||
| return Http.Post(Endpoints.AuthLogout, options); | |||||
| } | |||||
| => Http.Post(Endpoints.AuthLogout, options); | |||||
| //Servers | //Servers | ||||
| public static Task<APIResponses.CreateServer> CreateServer(string name, string region, HttpOptions options) | public static Task<APIResponses.CreateServer> CreateServer(string name, string region, HttpOptions options) | ||||
| @@ -35,29 +33,26 @@ namespace Discord.API | |||||
| return Http.Post<APIResponses.CreateServer>(Endpoints.Servers, request, options); | return Http.Post<APIResponses.CreateServer>(Endpoints.Servers, request, options); | ||||
| } | } | ||||
| public static Task LeaveServer(string id, HttpOptions options) | public static Task LeaveServer(string id, HttpOptions options) | ||||
| { | |||||
| return Http.Delete<APIResponses.DeleteServer>(Endpoints.Server(id), options); | |||||
| } | |||||
| => Http.Delete<APIResponses.DeleteServer>(Endpoints.Server(id), options); | |||||
| //Channels | //Channels | ||||
| public static Task<APIResponses.GetMessages[]> GetMessages(string channelId, HttpOptions options) | |||||
| public static Task<APIResponses.CreateChannel> CreateChannel(string serverId, string name, string channelType, HttpOptions options) | |||||
| { | { | ||||
| return Http.Get<APIResponses.GetMessages[]>(Endpoints.ChannelMessages(channelId, 50), options); | |||||
| var request = new APIRequests.CreateChannel { Name = name, Type = channelType }; | |||||
| return Http.Post<APIResponses.CreateChannel>(Endpoints.ServerChannels(serverId), 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) | |||||
| => Http.Get<APIResponses.GetMessages[]>(Endpoints.ChannelMessages(channelId, 50), options); | |||||
| //Members | //Members | ||||
| public static Task Kick(string serverId, string memberId, HttpOptions options) | public static Task Kick(string serverId, string memberId, HttpOptions options) | ||||
| { | |||||
| return Http.Delete(Endpoints.ServerMember(serverId, memberId), options); | |||||
| } | |||||
| => Http.Delete(Endpoints.ServerMember(serverId, memberId), options); | |||||
| public static Task Ban(string serverId, string memberId, HttpOptions options) | public static Task Ban(string serverId, string memberId, HttpOptions options) | ||||
| { | |||||
| return Http.Put(Endpoints.ServerBan(serverId, memberId), options); | |||||
| } | |||||
| => Http.Put(Endpoints.ServerBan(serverId, memberId), options); | |||||
| public static Task Unban(string serverId, string memberId, HttpOptions options) | public static Task Unban(string serverId, string memberId, HttpOptions options) | ||||
| { | |||||
| return Http.Delete(Endpoints.ServerBan(serverId, memberId), options); | |||||
| } | |||||
| => Http.Delete(Endpoints.ServerBan(serverId, memberId), options); | |||||
| //Invites | //Invites | ||||
| public static Task<APIResponses.CreateInvite> CreateInvite(string channelId, int maxAge, int maxUses, bool isTemporary, bool hasXkcdPass, HttpOptions options) | public static Task<APIResponses.CreateInvite> CreateInvite(string channelId, int maxAge, int maxUses, bool isTemporary, bool hasXkcdPass, HttpOptions options) | ||||
| @@ -66,17 +61,11 @@ namespace Discord.API | |||||
| return Http.Post<APIResponses.CreateInvite>(Endpoints.ChannelInvites(channelId), request, options); | return Http.Post<APIResponses.CreateInvite>(Endpoints.ChannelInvites(channelId), request, options); | ||||
| } | } | ||||
| public static Task<APIResponses.GetInvite> GetInvite(string id, HttpOptions options) | public static Task<APIResponses.GetInvite> GetInvite(string id, HttpOptions options) | ||||
| { | |||||
| return Http.Get<APIResponses.GetInvite>(Endpoints.Invite(id), options); | |||||
| } | |||||
| => Http.Get<APIResponses.GetInvite>(Endpoints.Invite(id), options); | |||||
| public static Task AcceptInvite(string id, HttpOptions options) | public static Task AcceptInvite(string id, HttpOptions options) | ||||
| { | |||||
| return Http.Post<APIResponses.AcceptInvite>(Endpoints.Invite(id), options); | |||||
| } | |||||
| => Http.Post<APIResponses.AcceptInvite>(Endpoints.Invite(id), options); | |||||
| public static Task DeleteInvite(string id, HttpOptions options) | public static Task DeleteInvite(string id, HttpOptions options) | ||||
| { | |||||
| return Http.Delete(Endpoints.Invite(id), options); | |||||
| } | |||||
| => Http.Delete(Endpoints.Invite(id), options); | |||||
| //Chat | //Chat | ||||
| public static Task<APIResponses.SendMessage> SendMessage(string channelId, string message, string[] mentions, HttpOptions options) | public static Task<APIResponses.SendMessage> SendMessage(string channelId, string message, string[] mentions, HttpOptions options) | ||||
| @@ -85,19 +74,13 @@ namespace Discord.API | |||||
| return Http.Post<APIResponses.SendMessage>(Endpoints.ChannelMessages(channelId), request, options); | return Http.Post<APIResponses.SendMessage>(Endpoints.ChannelMessages(channelId), request, options); | ||||
| } | } | ||||
| public static Task SendIsTyping(string channelId, HttpOptions options) | public static Task SendIsTyping(string channelId, HttpOptions options) | ||||
| { | |||||
| return Http.Post(Endpoints.ChannelTyping(channelId), options); | |||||
| } | |||||
| => Http.Post(Endpoints.ChannelTyping(channelId), options); | |||||
| //Voice | //Voice | ||||
| public static Task<APIResponses.GetRegions[]> GetVoiceRegions(HttpOptions options) | public static Task<APIResponses.GetRegions[]> GetVoiceRegions(HttpOptions options) | ||||
| { | |||||
| return Http.Get<APIResponses.GetRegions[]>(Endpoints.VoiceRegions, options); | |||||
| } | |||||
| => Http.Get<APIResponses.GetRegions[]>(Endpoints.VoiceRegions, options); | |||||
| public static Task<APIResponses.GetIce> GetVoiceIce(HttpOptions options) | public static Task<APIResponses.GetIce> GetVoiceIce(HttpOptions options) | ||||
| { | |||||
| return Http.Get<APIResponses.GetIce>(Endpoints.VoiceIce, options); | |||||
| } | |||||
| => Http.Get<APIResponses.GetIce>(Endpoints.VoiceIce, options); | |||||
| public static Task Mute(string serverId, string memberId, HttpOptions options) | public static Task Mute(string serverId, string memberId, HttpOptions options) | ||||
| { | { | ||||
| var request = new APIRequests.SetMemberMute { Mute = true }; | var request = new APIRequests.SetMemberMute { Mute = true }; | ||||
| @@ -19,6 +19,7 @@ | |||||
| // /api/guilds | // /api/guilds | ||||
| public static readonly string Servers = $"{BaseApi}/guilds"; | public static readonly string Servers = $"{BaseApi}/guilds"; | ||||
| public static string Server(string id) => $"{Servers}/{id}"; | public static string Server(string id) => $"{Servers}/{id}"; | ||||
| public static string ServerChannels(string serverId) => $"{Servers}/{serverId}/channels"; | |||||
| public static string ServerMember(string serverId, string userId) => $"{Servers}/{serverId}/members/{userId}"; | public static string ServerMember(string serverId, string userId) => $"{Servers}/{serverId}/members/{userId}"; | ||||
| public static string ServerBan(string serverId, string userId) => $"{Servers}/{serverId}/bans/{userId}"; | public static string ServerBan(string serverId, string userId) => $"{Servers}/{serverId}/bans/{userId}"; | ||||
| @@ -24,6 +24,9 @@ namespace Discord.API.Models | |||||
| public class CreateServer : ServerInfo { } | public class CreateServer : ServerInfo { } | ||||
| public class DeleteServer : ServerInfo { } | public class DeleteServer : ServerInfo { } | ||||
| public class CreateChannel : ChannelInfo { } | |||||
| public class DestroyChannel : ChannelInfo { } | |||||
| public class CreateInvite : GetInvite | public class CreateInvite : GetInvite | ||||
| { | { | ||||
| [JsonProperty(PropertyName = "max_age")] | [JsonProperty(PropertyName = "max_age")] | ||||
| @@ -31,6 +31,14 @@ namespace Discord.API.Models | |||||
| public string Region; | public string Region; | ||||
| } | } | ||||
| public class CreateChannel | |||||
| { | |||||
| [JsonProperty(PropertyName = "name")] | |||||
| public string Name; | |||||
| [JsonProperty(PropertyName = "type")] | |||||
| public string Type; | |||||
| } | |||||
| public class CreateInvite | public class CreateInvite | ||||
| { | { | ||||
| [JsonProperty(PropertyName = "max_age")] | [JsonProperty(PropertyName = "max_age")] | ||||
| @@ -0,0 +1,8 @@ | |||||
| namespace Discord | |||||
| { | |||||
| public static class ChannelTypes | |||||
| { | |||||
| public const string Text = "text"; | |||||
| public const string Voice = "voice"; | |||||
| } | |||||
| } | |||||
| @@ -50,6 +50,7 @@ | |||||
| <Compile Include="API\Endpoints.cs" /> | <Compile Include="API\Endpoints.cs" /> | ||||
| <Compile Include="API\Models\APIResponses.cs" /> | <Compile Include="API\Models\APIResponses.cs" /> | ||||
| <Compile Include="API\Models\WebSocketCommands.cs" /> | <Compile Include="API\Models\WebSocketCommands.cs" /> | ||||
| <Compile Include="ChannelTypes.cs" /> | |||||
| <Compile Include="Helpers\AsyncCache.cs" /> | <Compile Include="Helpers\AsyncCache.cs" /> | ||||
| <Compile Include="Invite.cs" /> | <Compile Include="Invite.cs" /> | ||||
| <Compile Include="Role.cs" /> | <Compile Include="Role.cs" /> | ||||
| @@ -60,7 +61,7 @@ | |||||
| <Compile Include="API\DiscordAPI.cs" /> | <Compile Include="API\DiscordAPI.cs" /> | ||||
| <Compile Include="API\Models\WebSocketEvents.cs" /> | <Compile Include="API\Models\WebSocketEvents.cs" /> | ||||
| <Compile Include="DiscordClient.cs" /> | <Compile Include="DiscordClient.cs" /> | ||||
| <Compile Include="Region.cs" /> | |||||
| <Compile Include="Regions.cs" /> | |||||
| <Compile Include="DiscordClient.Events.cs" /> | <Compile Include="DiscordClient.Events.cs" /> | ||||
| <Compile Include="Properties\AssemblyInfo.cs" /> | <Compile Include="Properties\AssemblyInfo.cs" /> | ||||
| <Compile Include="DiscordWebSocket.cs" /> | <Compile Include="DiscordWebSocket.cs" /> | ||||
| @@ -73,7 +73,7 @@ namespace Discord | |||||
| foreach (var channel in extendedModel.Channels) | foreach (var channel in extendedModel.Channels) | ||||
| { | { | ||||
| _channels.Update(channel.Id, model.Id, channel); | _channels.Update(channel.Id, model.Id, channel); | ||||
| if (channel.Type == "text") | |||||
| if (channel.Type == ChannelTypes.Text) | |||||
| { | { | ||||
| try | try | ||||
| { | { | ||||
| @@ -437,6 +437,24 @@ namespace Discord | |||||
| return _servers.Remove(id); | return _servers.Remove(id); | ||||
| } | } | ||||
| //Channels | |||||
| public Task<Channel> CreateChannel(Server server, string name, string region) | |||||
| => CreateChannel(server.Id, name, region); | |||||
| public async Task<Channel> CreateChannel(string serverId, string name, string region) | |||||
| { | |||||
| CheckReady(); | |||||
| var response = await DiscordAPI.CreateChannel(serverId, name, region, _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); | |||||
| } | |||||
| //Bans | //Bans | ||||
| public Task Ban(Server server, User user) | public Task Ban(Server server, User user) | ||||
| => Ban(server.Id, user.Id); | => Ban(server.Id, user.Id); | ||||
| @@ -1,6 +1,6 @@ | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| public static class Region | |||||
| public static class Regions | |||||
| { | { | ||||
| public const string US_West = "us-west"; | public const string US_West = "us-west"; | ||||
| public const string US_East = "us-east"; | public const string US_East = "us-east"; | ||||