Added channel type parameter to FindChannels

This commit is contained in:
Brandon Smith
2015-09-20 16:22:18 -03:00
parent d0af90e595
commit 3861f067ed
2 changed files with 11 additions and 5 deletions

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;
}
}
}

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];