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.

RestVoiceChannel.cs 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using Discord.Audio;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using Model = Discord.API.Channel;
  8. namespace Discord.Rest
  9. {
  10. /// <summary>
  11. /// Represents a REST-based voice channel in a guild.
  12. /// </summary>
  13. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  14. public class RestVoiceChannel : RestGuildChannel, IVoiceChannel, IRestAudioChannel
  15. {
  16. /// <inheritdoc />
  17. public int Bitrate { get; private set; }
  18. /// <inheritdoc />
  19. public int? UserLimit { get; private set; }
  20. /// <inheritdoc />
  21. public ulong? CategoryId { get; private set; }
  22. internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id)
  23. : base(discord, guild, id)
  24. {
  25. }
  26. internal new static RestVoiceChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
  27. {
  28. var entity = new RestVoiceChannel(discord, guild, model.Id);
  29. entity.Update(model);
  30. return entity;
  31. }
  32. /// <inheritdoc />
  33. internal override void Update(Model model)
  34. {
  35. base.Update(model);
  36. CategoryId = model.CategoryId;
  37. Bitrate = model.Bitrate.Value;
  38. UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
  39. }
  40. /// <inheritdoc />
  41. public async Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
  42. {
  43. var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
  44. Update(model);
  45. }
  46. /// <summary>
  47. /// Gets the parent category of this channel.
  48. /// </summary>
  49. /// <param name="options">The options to be used when sending the request.</param>
  50. /// <returns>
  51. /// An awaitable <see cref="Task"/> containing an <see cref="ICategoryChannel"/>.
  52. /// </returns>
  53. public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
  54. => ChannelHelper.GetCategoryAsync(this, Discord, options);
  55. private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
  56. //IAudioChannel
  57. /// <inheritdoc />
  58. /// <exception cref="NotSupportedException">Connecting to a REST-based channel is not supported.</exception>
  59. Task<IAudioClient> IAudioChannel.ConnectAsync(bool selfDeaf, bool selfMute, bool external) { throw new NotSupportedException(); }
  60. Task IAudioChannel.DisconnectAsync() { throw new NotSupportedException(); }
  61. //IGuildChannel
  62. /// <inheritdoc />
  63. Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  64. => Task.FromResult<IGuildUser>(null);
  65. /// <inheritdoc />
  66. IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  67. => AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
  68. // INestedChannel
  69. async Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
  70. {
  71. if (CategoryId.HasValue && mode == CacheMode.AllowDownload)
  72. return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel;
  73. return null;
  74. }
  75. }
  76. }