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.

RpcGuildChannel.cs 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Discord.API.Rest;
  5. using Model = Discord.API.Rpc.Channel;
  6. using Discord.Rest;
  7. namespace Discord.Rpc
  8. {
  9. public class RpcGuildChannel : RpcChannel, IGuildChannel
  10. {
  11. public ulong GuildId { get; }
  12. public int Position { get; private set; }
  13. internal RpcGuildChannel(DiscordRpcClient discord, ulong id, ulong guildId)
  14. : base(discord, id)
  15. {
  16. GuildId = guildId;
  17. }
  18. internal new static RpcGuildChannel Create(DiscordRpcClient discord, Model model)
  19. {
  20. switch (model.Type)
  21. {
  22. case ChannelType.Text:
  23. return RpcTextChannel.Create(discord, model);
  24. case ChannelType.Voice:
  25. return RpcVoiceChannel.Create(discord, model);
  26. default:
  27. throw new InvalidOperationException("Unknown guild channel type");
  28. }
  29. }
  30. internal override void Update(Model model)
  31. {
  32. base.Update(model);
  33. if (model.Position.IsSpecified)
  34. Position = model.Position.Value;
  35. }
  36. public Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null)
  37. => ChannelHelper.ModifyAsync(this, Discord, func, options);
  38. public Task DeleteAsync(RequestOptions options = null)
  39. => ChannelHelper.DeleteAsync(this, Discord, options);
  40. public Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
  41. => ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options);
  42. public Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
  43. => ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options);
  44. public Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
  45. => ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options);
  46. public Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
  47. => ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options);
  48. public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
  49. => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);
  50. public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null)
  51. => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options).ConfigureAwait(false);
  52. public override string ToString() => Name;
  53. //IGuildChannel
  54. IGuild IGuildChannel.Guild
  55. {
  56. get
  57. {
  58. //Always fails
  59. throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
  60. }
  61. }
  62. async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
  63. => await GetInvitesAsync(options).ConfigureAwait(false);
  64. async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options)
  65. => await CreateInviteAsync(maxAge, maxUses, isTemporary, options).ConfigureAwait(false);
  66. IReadOnlyCollection<Overwrite> IGuildChannel.PermissionOverwrites { get { throw new NotSupportedException(); } }
  67. OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
  68. {
  69. throw new NotSupportedException();
  70. }
  71. OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
  72. {
  73. throw new NotSupportedException();
  74. }
  75. IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  76. {
  77. throw new NotSupportedException();
  78. }
  79. Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  80. {
  81. throw new NotSupportedException();
  82. }
  83. //IChannel
  84. IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  85. {
  86. throw new NotSupportedException();
  87. }
  88. Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  89. {
  90. throw new NotSupportedException();
  91. }
  92. }
  93. }