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.

RpcVoiceChannel.cs 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Discord.Audio;
  2. using Discord.Rest;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.Immutable;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using Model = Discord.API.Rpc.Channel;
  10. namespace Discord.Rpc
  11. {
  12. [DebuggerDisplay(@"{DebuggerDisplay,nq}")]
  13. public class RpcVoiceChannel : RpcGuildChannel, IRpcAudioChannel, IVoiceChannel
  14. {
  15. public int Bitrate { get; private set; }
  16. public int? UserLimit { get; private set; }
  17. public IReadOnlyCollection<RpcVoiceState> VoiceStates { get; private set; }
  18. internal RpcVoiceChannel(DiscordRpcClient discord, ulong id, ulong guildId)
  19. : base(discord, id, guildId)
  20. {
  21. }
  22. internal new static RpcVoiceChannel Create(DiscordRpcClient discord, Model model)
  23. {
  24. var entity = new RpcVoiceChannel(discord, model.Id, model.GuildId.Value);
  25. entity.Update(model);
  26. return entity;
  27. }
  28. internal override void Update(Model model)
  29. {
  30. base.Update(model);
  31. if (model.UserLimit.IsSpecified)
  32. UserLimit = model.UserLimit.Value != 0 ? model.UserLimit.Value : (int?)null;
  33. if (model.Bitrate.IsSpecified)
  34. Bitrate = model.Bitrate.Value;
  35. VoiceStates = model.VoiceStates.Select(x => RpcVoiceState.Create(Discord, x)).ToImmutableArray();
  36. }
  37. public Task ModifyAsync(Action<VoiceChannelProperties> func, RequestOptions options = null)
  38. => ChannelHelper.ModifyAsync(this, Discord, func, options);
  39. private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
  40. //IAudioChannel
  41. Task<IAudioClient> IAudioChannel.ConnectAsync(Action<IAudioClient> configAction) { throw new NotSupportedException(); }
  42. }
  43. }