You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

SocketChannel.cs 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Discord.Rest;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Model = Discord.API.Channel;
  8. namespace Discord.WebSocket
  9. {
  10. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  11. public abstract class SocketChannel : SocketEntity<ulong>, IChannel
  12. {
  13. public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
  14. public IReadOnlyCollection<SocketUser> Users => GetUsersInternal();
  15. internal SocketChannel(DiscordSocketClient discord, ulong id)
  16. : base(discord, id)
  17. {
  18. }
  19. internal static ISocketPrivateChannel CreatePrivate(DiscordSocketClient discord, ClientState state, Model model)
  20. {
  21. switch (model.Type)
  22. {
  23. case ChannelType.DM:
  24. return SocketDMChannel.Create(discord, state, model);
  25. case ChannelType.Group:
  26. return SocketGroupChannel.Create(discord, state, model);
  27. default:
  28. throw new InvalidOperationException($"Unexpected channel type: {model.Type}");
  29. }
  30. }
  31. internal abstract void Update(ClientState state, Model model);
  32. //User
  33. public SocketUser GetUser(ulong id) => GetUserInternal(id);
  34. internal abstract SocketUser GetUserInternal(ulong id);
  35. internal abstract IReadOnlyCollection<SocketUser> GetUsersInternal();
  36. internal SocketChannel Clone() => MemberwiseClone() as SocketChannel;
  37. //IChannel
  38. string IChannel.Name => null;
  39. Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  40. => Task.FromResult<IUser>(null); //Overridden
  41. IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  42. => AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overridden
  43. }
  44. }