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.8 kB

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