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.9 KiB

Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
Add support for channel categories (#907) commit a85c5814a74e473e95fe172f0379cbc7f9f951d8 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:25:48 2018 -0500 Code cleanup commit 4b243fd3dd99152b4ebc7ee01d704bd8e57eeee1 Author: Christopher F <computerizedtaco@gmail.com> Date: Sat Jan 6 22:08:28 2018 -0500 Add support for channel categories (#907) commit 41ed9106f2b05530acbf06b245c9aa618011d815 Author: mrspits4ever <spits.lucas@gmail.com> Date: Thu Dec 14 20:02:57 2017 +0100 removed mentioning support for RestCategoryChannel, added channels property to SocketCategoryChannel commit 71142c310847886dff80c49e9357dd0786d67a1b Merge: 4589d731 678a7238 Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:53 2017 +0100 Merge branch 'dev' of https://github.com/RogueException/Discord.Net into feature/channel-categories commit 4589d73187871c98485ed25c6d223706927af7ec Author: mrspits4ever <spits.lucas@gmail.com> Date: Wed Dec 13 21:17:46 2017 +0100 adressed requested changes commit d59b038efa048b2279602e2015ddd2c185e58d63 Author: pegasy <pegasy@users.noreply.github.com> Date: Mon Sep 25 18:53:23 2017 +0200 Renamed classes / properties / methods to use CategoryChannel instead of ChannelCategory to be consistant with how text / voice channels are named. commit 5c4777dc8cc443108f2e7e4afae98824c9a32b1f Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 19:08:25 2017 +0200 removed Guild from class name for ChannelCategory Renamed all properties to use Category instead of Parent Throw exception on GetUsers / GetInvites etc for categories commit e18bd8c799d2327270021c05866cb2e97ad4671b Author: pegasy <pegasy@users.noreply.github.com> Date: Sun Sep 24 15:49:51 2017 +0200 Add support for channel categories (as its own channel type)
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. public ulong? CategoryId { 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<GuildChannelProperties> 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 = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
  51. => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
  52. public override string ToString() => Name;
  53. //IGuildChannel
  54. public Task<ICategoryChannel> GetCategoryAsync()
  55. {
  56. //Always fails
  57. throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
  58. }
  59. IGuild IGuildChannel.Guild
  60. {
  61. get
  62. {
  63. //Always fails
  64. throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
  65. }
  66. }
  67. async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
  68. => await GetInvitesAsync(options).ConfigureAwait(false);
  69. async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
  70. => await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);
  71. IReadOnlyCollection<Overwrite> IGuildChannel.PermissionOverwrites { get { throw new NotSupportedException(); } }
  72. OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
  73. {
  74. throw new NotSupportedException();
  75. }
  76. OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
  77. {
  78. throw new NotSupportedException();
  79. }
  80. IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  81. {
  82. throw new NotSupportedException();
  83. }
  84. Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  85. {
  86. throw new NotSupportedException();
  87. }
  88. //IChannel
  89. IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  90. {
  91. throw new NotSupportedException();
  92. }
  93. Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  94. {
  95. throw new NotSupportedException();
  96. }
  97. }
  98. }