Browse Source

Added channel type parameter to FindChannels

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
3861f067ed
2 changed files with 11 additions and 5 deletions
  1. +9
    -3
      src/Discord.Net/Collections/Channels.cs
  2. +2
    -2
      src/Discord.Net/DiscordClient.Cache.cs

+ 9
- 3
src/Discord.Net/Collections/Channels.cs View File

@@ -41,21 +41,27 @@ namespace Discord.Collections

internal Channel this[string id] => Get(id);
internal IEnumerable<Channel> Find(string serverId, string name)
internal IEnumerable<Channel> Find(string serverId, string name, string type = null)
{
if (serverId == null) throw new ArgumentNullException(nameof(serverId));

IEnumerable<Channel> result;
if (name.StartsWith("#"))
{
string name2 = name.Substring(1);
return this.Where(x => x.ServerId == serverId &&
result = this.Where(x => x.ServerId == serverId &&
string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase) || string.Equals(x.Name, name2, StringComparison.OrdinalIgnoreCase));
}
else
{
return this.Where(x => x.ServerId == serverId &&
result = this.Where(x => x.ServerId == serverId &&
string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));
}

if (type != null)
result = result.Where(x => x.Type == type);

return result;
}
}
}

+ 2
- 2
src/Discord.Net/DiscordClient.Cache.cs View File

@@ -8,10 +8,10 @@ namespace Discord
public Channel GetChannel(string id) => _channels[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) => _channels.Find(server?.Id, name);
public IEnumerable<Channel> FindChannels(Server server, string name, string type = null) => _channels.Find(server?.Id, name, type);
/// <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(string serverId, string name) => _channels.Find(serverId, name);
public IEnumerable<Channel> FindChannels(string serverId, string name, string type = null) => _channels.Find(serverId, name, type);

/// <summary> Returns the user with the specified id, along with their server-specific data, or null if none was found. </summary>
public Member GetMember(string serverId, User user) => _members[user?.Id, serverId];


Loading…
Cancel
Save