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.

RestChannel.cs 2.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Model = Discord.API.Channel;
  6. namespace Discord.Rest
  7. {
  8. public class RestChannel : RestEntity<ulong>, IChannel, IUpdateable
  9. {
  10. public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
  11. internal RestChannel(BaseDiscordClient discord, ulong id)
  12. : base(discord, id)
  13. {
  14. }
  15. internal static RestChannel Create(BaseDiscordClient discord, Model model)
  16. {
  17. switch (model.Type)
  18. {
  19. case ChannelType.Text:
  20. case ChannelType.Voice:
  21. return RestGuildChannel.Create(discord, new RestGuild(discord, model.GuildId.Value), model);
  22. case ChannelType.DM:
  23. case ChannelType.Group:
  24. return CreatePrivate(discord, model) as RestChannel;
  25. default:
  26. return new RestChannel(discord, model.Id);
  27. }
  28. }
  29. internal static IRestPrivateChannel CreatePrivate(BaseDiscordClient discord, Model model)
  30. {
  31. switch (model.Type)
  32. {
  33. case ChannelType.DM:
  34. return RestDMChannel.Create(discord, model);
  35. case ChannelType.Group:
  36. return RestGroupChannel.Create(discord, model);
  37. default:
  38. throw new InvalidOperationException($"Unexpected channel type: {model.Type}");
  39. }
  40. }
  41. internal virtual void Update(Model model) { }
  42. public virtual Task UpdateAsync(RequestOptions options = null) => Task.Delay(0);
  43. //IChannel
  44. string IChannel.Name => null;
  45. Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  46. => Task.FromResult<IUser>(null); //Overridden
  47. IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  48. => AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overridden
  49. }
  50. }