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 2.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  11. public class RestVoiceChannel : RestGuildChannel, IVoiceChannel, IRestAudioChannel
  12. {
  13. public int Bitrate { get; private set; }
  14. public int? UserLimit { get; private set; }
  15. public ulong? CategoryId { get; private set; }
  16. internal RestVoiceChannel(BaseDiscordClient discord, IGuild guild, ulong id)
  17. : base(discord, guild, id)
  18. {
  19. }
  20. internal new static RestVoiceChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
  21. {
  22. var entity = new RestVoiceChannel(discord, guild, model.Id);
  23. entity.Update(model);
  24. return entity;
  25. }
  26. internal override void Update(Model model)
  27. {
  28. base.Update(model);
  29. CategoryId = model.CategoryId;
  30. Bitrate = model.Bitrate.Value;
  31. UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
  32. }
  33. public async Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
  34. {
  35. var model = await ChannelHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
  36. Update(model);
  37. }
  38. public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
  39. => ChannelHelper.GetCategoryAsync(this, Discord, options);
  40. private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
  41. //IAudioChannel
  42. Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
  43. //IGuildChannel
  44. Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
  45. => Task.FromResult<IGuildUser>(null);
  46. IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
  47. => AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
  48. // INestedChannel
  49. async Task<ICategoryChannel> INestedChannel.GetCategoryAsync(CacheMode mode, RequestOptions options)
  50. {
  51. if (CategoryId.HasValue && mode == CacheMode.AllowDownload)
  52. return (await Guild.GetChannelAsync(CategoryId.Value, mode, options).ConfigureAwait(false)) as ICategoryChannel;
  53. return null;
  54. }
  55. }
  56. }