diff --git a/src/Discord.Net.Net45/Discord.Net.csproj b/src/Discord.Net.Net45/Discord.Net.csproj
index d92fa3858..1d54ee4b0 100644
--- a/src/Discord.Net.Net45/Discord.Net.csproj
+++ b/src/Discord.Net.Net45/Discord.Net.csproj
@@ -154,17 +154,35 @@
DiscordAPIClientConfig.cs
-
- DiscordClient.API.cs
+
+ DiscordClient.Bans.cs
-
- DiscordClient.Cache.cs
+
+ DiscordClient.Channels.cs
DiscordClient.cs
-
- DiscordClient.Events.cs
+
+ DiscordClient.Invites.cs
+
+
+ DiscordClient.Members.cs
+
+
+ DiscordClient.Messages.cs
+
+
+ DiscordClient.Permissions.cs
+
+
+ DiscordClient.Roles.cs
+
+
+ DiscordClient.Servers.cs
+
+
+ DiscordClient.Users.cs
DiscordClientConfig.cs
diff --git a/src/Discord.Net/Collections/AsyncCollection.cs b/src/Discord.Net/Collections/AsyncCollection.cs
index 052988535..9d4a2d79b 100644
--- a/src/Discord.Net/Collections/AsyncCollection.cs
+++ b/src/Discord.Net/Collections/AsyncCollection.cs
@@ -127,8 +127,8 @@ namespace Discord.Collections
}
}
- protected abstract void OnCreated(TValue item);
- protected abstract void OnRemoved(TValue item);
+ protected virtual void OnCreated(TValue item) { }
+ protected virtual void OnRemoved(TValue item) { }
public IEnumerator GetEnumerator()
{
diff --git a/src/Discord.Net/Collections/Channels.cs b/src/Discord.Net/Collections/Channels.cs
index 4b9a88cff..a2fb81b24 100644
--- a/src/Discord.Net/Collections/Channels.cs
+++ b/src/Discord.Net/Collections/Channels.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
namespace Discord.Collections
{
@@ -46,29 +44,13 @@ namespace Discord.Collections
}
}
- internal Channel this[string id] => Get(id);
-
- internal IEnumerable Find(string serverId, string name, string type = null)
+ internal Channel this[string id]
{
- if (serverId == null) throw new ArgumentNullException(nameof(serverId));
-
- IEnumerable result;
- if (name.StartsWith("#"))
- {
- string name2 = name.Substring(1);
- result = this.Where(x => x.ServerId == serverId &&
- string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) || string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase));
- }
- else
+ get
{
- result = this.Where(x => x.ServerId == serverId &&
- string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));
+ if (id == null) throw new ArgumentNullException(nameof(id));
+ return Get(id);
}
-
- if (type != null)
- result = result.Where(x => x.Type == type);
-
- return result;
}
}
}
diff --git a/src/Discord.Net/Collections/Members.cs b/src/Discord.Net/Collections/Members.cs
index c8c4deae1..363a5d37c 100644
--- a/src/Discord.Net/Collections/Members.cs
+++ b/src/Discord.Net/Collections/Members.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
namespace Discord.Collections
{
@@ -45,52 +43,8 @@ namespace Discord.Collections
{
if (serverId == null) throw new ArgumentNullException(nameof(serverId));
if (userId == null) throw new ArgumentNullException(nameof(userId));
-
return Get(GetKey(userId, serverId));
}
}
-
- internal IEnumerable Find(Server server, string name)
- {
- if (server == null) throw new ArgumentNullException(nameof(server));
- if (name == null) throw new ArgumentNullException(nameof(name));
-
- if (name.StartsWith("@"))
- {
- string name2 = name.Substring(1);
- return server.Members.Where(x =>
- {
- var user = x.User;
- if (user == null)
- return false;
- return string.Equals(user.Name, name, StringComparison.OrdinalIgnoreCase) || string.Equals(user.Name, name2, StringComparison.OrdinalIgnoreCase);
- });
- }
- else
- {
- return server.Members.Where(x =>
- {
- var user = x.User;
- if (user == null)
- return false;
- return string.Equals(x.User.Name, name, StringComparison.OrdinalIgnoreCase);
- });
- }
- }
-
- internal Member Find(string username, string discriminator)
- {
- if (username == null) throw new ArgumentNullException(nameof(username));
- if (discriminator == null) throw new ArgumentNullException(nameof(discriminator));
-
- if (username.StartsWith("@"))
- username = username.Substring(1);
-
- return this.Where(x =>
- string.Equals(x.Name, username, StringComparison.OrdinalIgnoreCase) &&
- x.Discriminator == discriminator
- )
- .FirstOrDefault();
- }
}
}
diff --git a/src/Discord.Net/Collections/Messages.cs b/src/Discord.Net/Collections/Messages.cs
index 0943c8a9d..16b2d32a7 100644
--- a/src/Discord.Net/Collections/Messages.cs
+++ b/src/Discord.Net/Collections/Messages.cs
@@ -1,11 +1,11 @@
-namespace Discord.Collections
+using System;
+
+namespace Discord.Collections
{
public sealed class Messages : AsyncCollection
{
internal Messages(DiscordClient client, object writerLock)
- : base(client, writerLock)
- {
- }
+ : base(client, writerLock) { }
internal Message GetOrAdd(string id, string channelId, string userId) => GetOrAdd(id, () => new Message(_client, id, channelId, userId));
internal new Message TryRemove(string id) => base.TryRemove(id);
@@ -26,6 +26,13 @@
user.RemoveRef();
}
- internal Message this[string id] => Get(id);
+ internal Message this[string id]
+ {
+ get
+ {
+ if (id == null) throw new ArgumentNullException(nameof(id));
+ return Get(id);
+ }
+ }
}
}
diff --git a/src/Discord.Net/Collections/Roles.cs b/src/Discord.Net/Collections/Roles.cs
index 502c9b8d7..fd83a7c1e 100644
--- a/src/Discord.Net/Collections/Roles.cs
+++ b/src/Discord.Net/Collections/Roles.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
namespace Discord.Collections
{
@@ -23,23 +21,12 @@ namespace Discord.Collections
item.Server.RemoveRole(item.Id);
}
- internal Role this[string id] => Get(id);
-
- internal IEnumerable Find(string serverId, string name)
+ internal Role this[string id]
{
- if (serverId == null) throw new ArgumentNullException(nameof(serverId));
- if (name == null) throw new ArgumentNullException(nameof(name));
-
- if (name.StartsWith("@"))
- {
- string name2 = name.Substring(1);
- return this.Where(x => x.ServerId == serverId &&
- string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) || string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase));
- }
- else
+ get
{
- return this.Where(x => x.ServerId == serverId &&
- string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));
+ if (id == null) throw new ArgumentNullException(nameof(id));
+ return Get(id);
}
}
}
diff --git a/src/Discord.Net/Collections/Servers.cs b/src/Discord.Net/Collections/Servers.cs
index d1f6b9245..ddd44071a 100644
--- a/src/Discord.Net/Collections/Servers.cs
+++ b/src/Discord.Net/Collections/Servers.cs
@@ -11,8 +11,7 @@ namespace Discord.Collections
internal Server GetOrAdd(string id) => base.GetOrAdd(id, () => new Server(_client, id));
internal new Server TryRemove(string id) => base.TryRemove(id);
-
- protected override void OnCreated(Server item) { }
+
protected override void OnRemoved(Server item)
{
var channels = _client.Channels;
@@ -29,12 +28,5 @@ namespace Discord.Collections
}
internal Server this[string id] => Get(id);
-
- internal IEnumerable Find(string name)
- {
- if (name == null) throw new ArgumentNullException(nameof(name));
-
- return this.Where(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));
- }
}
}
diff --git a/src/Discord.Net/Collections/Users.cs b/src/Discord.Net/Collections/Users.cs
index 11f301aaf..90317b65b 100644
--- a/src/Discord.Net/Collections/Users.cs
+++ b/src/Discord.Net/Collections/Users.cs
@@ -1,6 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
namespace Discord.Collections
{
@@ -15,22 +13,12 @@ namespace Discord.Collections
protected override void OnCreated(User item) { }
protected override void OnRemoved(User item) { }
- internal User this[string id] => Get(id);
-
- internal IEnumerable Find(string name)
+ internal User this[string id]
{
- if (name == null) throw new ArgumentNullException(nameof(name));
-
- if (name.StartsWith("@"))
- {
- string name2 = name.Substring(1);
- return this.Where(x =>
- string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) || string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase));
- }
- else
+ get
{
- return this.Where(x =>
- string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));
+ if (id == null) throw new ArgumentNullException(nameof(id));
+ return Get(id);
}
}
}
diff --git a/src/Discord.Net/DiscordClient.API.cs b/src/Discord.Net/DiscordClient.API.cs
deleted file mode 100644
index e99561ebd..000000000
--- a/src/Discord.Net/DiscordClient.API.cs
+++ /dev/null
@@ -1,756 +0,0 @@
-using Discord.API;
-using Discord.Net;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Threading.Tasks;
-
-namespace Discord
-{
- public partial class DiscordClient
- {
- public const int MaxMessageSize = 2000;
-
- //Bans
- /// Bans a user from the provided server.
- public Task Ban(Member member)
- => Ban(member?.ServerId, member?.UserId);
- /// Bans a user from the provided server.
- public Task Ban(Server server, User user)
- => Ban(server?.Id, user?.Id);
- /// Bans a user from the provided server.
- public Task Ban(Server server, string userId)
- => Ban(server?.Id, userId);
- /// Bans a user from the provided server.
- public Task Ban(string server, User user)
- => Ban(server, user?.Id);
- /// Bans a user from the provided server.
- public Task Ban(string serverId, string userId)
- {
- CheckReady();
- if (serverId == null) throw new ArgumentNullException(nameof(serverId));
- if (userId == null) throw new ArgumentNullException(nameof(userId));
-
- return _api.Ban(serverId, userId);
- }
-
- /// Unbans a user from the provided server.
- public Task Unban(Member member)
- => Unban(member?.ServerId, member?.UserId);
- /// Unbans a user from the provided server.
- public Task Unban(Server server, User user)
- => Unban(server?.Id, user?.Id);
- /// Unbans a user from the provided server.
- public Task Unban(Server server, string userId)
- => Unban(server?.Id, userId);
- /// Unbans a user from the provided server.
- public Task Unban(string server, User user)
- => Unban(server, user?.Id);
- /// Unbans a user from the provided server.
- public async Task Unban(string serverId, string userId)
- {
- CheckReady();
- if (serverId == null) throw new ArgumentNullException(nameof(serverId));
- if (userId == null) throw new ArgumentNullException(nameof(userId));
-
- try { await _api.Unban(serverId, userId).ConfigureAwait(false); }
- catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
- }
-
- //Channels
- /// Creates a new channel with the provided name and type (see ChannelTypes).
- public Task CreateChannel(Server server, string name, string type = ChannelTypes.Text)
- => CreateChannel(server?.Id, name, type);
- /// Creates a new channel with the provided name and type (see ChannelTypes).
- public async Task CreateChannel(string serverId, string name, string type = ChannelTypes.Text)
- {
- CheckReady();
- if (serverId == null) throw new ArgumentNullException(nameof(serverId));
- if (name == null) throw new ArgumentNullException(nameof(name));
- if (type == null) throw new ArgumentNullException(nameof(type));
-
- var response = await _api.CreateChannel(serverId, name, type).ConfigureAwait(false);
- var channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient?.Id);
- channel.Update(response);
- return channel;
- }
-
- /// Returns the private channel with the provided user, creating one if it does not currently exist.
- public Task CreatePMChannel(string userId) => CreatePMChannel(_users[userId], userId);
- /// Returns the private channel with the provided user, creating one if it does not currently exist.
- public Task CreatePMChannel(User user) => CreatePMChannel(user, user?.Id);
- /// Returns the private channel with the provided user, creating one if it does not currently exist.
- public Task CreatePMChannel(Member member) => CreatePMChannel(member.User, member.UserId);
- private async Task CreatePMChannel(User user, string userId)
- {
- CheckReady();
- if (userId == null) throw new ArgumentNullException(nameof(userId));
-
- Channel channel = null;
- if (user != null)
- channel = user.PrivateChannel;
- if (channel == null)
- {
- var response = await _api.CreatePMChannel(CurrentUserId, userId).ConfigureAwait(false);
- user = _users.GetOrAdd(response.Recipient?.Id);
- user.Update(response.Recipient);
- channel = _channels.GetOrAdd(response.Id, response.GuildId, response.Recipient?.Id);
- channel.Update(response);
- }
- return channel;
- }
-
- /// Edits the provided channel, changing only non-null attributes.
- public Task EditChannel(string channelId, string name = null, string topic = null, int? position = null)
- => EditChannel(_channels[channelId], name: name, topic: topic, position: position);
- /// Edits the provided channel, changing only non-null attributes.
- public async Task EditChannel(Channel channel, string name = null, string topic = null, int? position = null)
- {
- CheckReady();
- if (channel == null) throw new ArgumentNullException(nameof(channel));
-
- await _api.EditChannel(channel.Id, name: name, topic: topic);
-
- if (position != null)
- {
- int oldPos = channel.Position;
- int newPos = position.Value;
- int minPos;
- Channel[] channels = channel.Server.Channels.OrderBy(x => x.Position).ToArray();
-
- if (oldPos < newPos) //Moving Down
- {
- minPos = oldPos;
- for (int i = oldPos; i < newPos; i++)
- channels[i] = channels[i + 1];
- channels[newPos] = channel;
- }
- else //(oldPos > newPos) Moving Up
- {
- minPos = newPos;
- for (int i = oldPos; i > newPos; i--)
- channels[i] = channels[i - 1];
- channels[newPos] = channel;
- }
- await _api.ReorderChannels(channel.ServerId, channels.Skip(minPos).Select(x => x.Id), minPos);
- }
- }
-
- public Task ReorderChannels(Server server, IEnumerable