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.

RpcChannel.cs 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Discord.Rest;
  2. using System;
  3. using Model = Discord.API.Rpc.Channel;
  4. namespace Discord.Rpc
  5. {
  6. public class RpcChannel : RpcEntity<ulong>
  7. {
  8. public string Name { get; private set; }
  9. public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
  10. internal RpcChannel(DiscordRpcClient discord, ulong id)
  11. : base(discord, id)
  12. {
  13. }
  14. internal static RpcChannel Create(DiscordRpcClient discord, Model model)
  15. {
  16. if (model.GuildId.IsSpecified)
  17. return RpcGuildChannel.Create(discord, model);
  18. else
  19. return CreatePrivate(discord, model);
  20. }
  21. internal static RpcChannel CreatePrivate(DiscordRpcClient discord, Model model)
  22. {
  23. switch (model.Type)
  24. {
  25. case ChannelType.DM:
  26. return RpcDMChannel.Create(discord, model);
  27. case ChannelType.Group:
  28. return RpcGroupChannel.Create(discord, model);
  29. default:
  30. throw new InvalidOperationException($"Unexpected channel type: {model.Type}");
  31. }
  32. }
  33. internal virtual void Update(Model model)
  34. {
  35. if (model.Name.IsSpecified)
  36. Name = model.Name.Value;
  37. }
  38. }
  39. }