Added GetUsers extensions to WebSocket->Channel
Cached Channels keep a local cache of the members of that channel. This commit adds a synchronus method to access the cached user stores. It also fixes a bug where the GetUser extension would return an IGroupUser by soft-casting to IGroupUser, which would always return null. ISocketUser does not share an inheritance with IGroupUser, so I now return IUser instead.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Discord.WebSocket.Extensions
|
||||
{
|
||||
@@ -7,15 +8,27 @@ namespace Discord.WebSocket.Extensions
|
||||
public static IUser GetUser(this IDMChannel channel, ulong id)
|
||||
=> GetSocketDMChannel(channel).GetUser(id);
|
||||
|
||||
public static IGroupUser GetUser(this IGroupChannel channel, ulong id)
|
||||
=> GetSocketGroupChannel(channel).GetUser(id) as IGroupUser;
|
||||
public static IEnumerable<IUser> GetUsers(this IDMChannel channel)
|
||||
=> GetSocketDMChannel(channel).Users;
|
||||
|
||||
public static IUser GetUser(this IGroupChannel channel, ulong id)
|
||||
=> GetSocketGroupChannel(channel).GetUser(id);
|
||||
|
||||
public static IEnumerable<IUser> GetUsers(this IGroupChannel channel)
|
||||
=> GetSocketGroupChannel(channel).Users;
|
||||
|
||||
public static IGuildUser GetUser(this ITextChannel channel, ulong id)
|
||||
=> GetSocketTextChannel(channel).GetUser(id);
|
||||
|
||||
public static IEnumerable<IGuildUser> GetUsers(this ITextChannel channel)
|
||||
=> GetSocketTextChannel(channel).Members;
|
||||
|
||||
public static IGuildUser GetUser(this IVoiceChannel channel, ulong id)
|
||||
=> GetSocketVoiceChannel(channel).GetUser(id);
|
||||
|
||||
public static IEnumerable<IGuildUser> GetUsers(this IVoiceChannel channel)
|
||||
=> GetSocketVoiceChannel(channel).Members;
|
||||
|
||||
internal static SocketDMChannel GetSocketDMChannel(IDMChannel channel)
|
||||
{
|
||||
var socketChannel = channel as SocketDMChannel;
|
||||
|
||||
Reference in New Issue
Block a user