Browse Source

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.
tags/1.0-rc
Christopher F 8 years ago
parent
commit
3c5788bbfc
1 changed files with 15 additions and 2 deletions
  1. +15
    -2
      src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs

+ 15
- 2
src/Discord.Net/WebSocket/Extensions/ChannelExtensions.cs View File

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


Loading…
Cancel
Save