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.

VoiceSettings.cs 3.4 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. using System.Collections.Immutable;
  3. using System.Linq;
  4. using Model = Discord.API.Rpc.VoiceSettings;
  5. namespace Discord.Rpc
  6. {
  7. public class VoiceSettings
  8. {
  9. public string InputDeviceId { get; private set; }
  10. public float InputVolume { get; private set; }
  11. public IReadOnlyCollection<VoiceDevice> AvailableInputDevices { get; private set; }
  12. public string OutputDeviceId { get; private set; }
  13. public float OutputVolume { get; private set; }
  14. public IReadOnlyCollection<VoiceDevice> AvailableOutputDevices { get; private set; }
  15. public bool AutomaticGainControl { get; private set; }
  16. public bool EchoCancellation { get; private set; }
  17. public bool NoiseSuppression { get; private set; }
  18. public bool QualityOfService { get; private set; }
  19. public bool SilenceWarning { get; private set; }
  20. public string ActivationMode { get; private set; }
  21. public bool AutoThreshold { get; private set; }
  22. public float Threshold { get; private set; }
  23. public IReadOnlyCollection<VoiceShortcut> Shortcuts { get; private set; }
  24. public float Delay { get; private set; }
  25. internal VoiceSettings() { }
  26. internal static VoiceSettings Create(Model model)
  27. {
  28. var entity = new VoiceSettings();
  29. entity.Update(model);
  30. return entity;
  31. }
  32. internal void Update(Model model)
  33. {
  34. if (model.AutomaticGainControl.IsSpecified)
  35. AutomaticGainControl = model.AutomaticGainControl.Value;
  36. if (model.EchoCancellation.IsSpecified)
  37. EchoCancellation = model.EchoCancellation.Value;
  38. if (model.NoiseSuppression.IsSpecified)
  39. NoiseSuppression = model.NoiseSuppression.Value;
  40. if (model.QualityOfService.IsSpecified)
  41. QualityOfService = model.QualityOfService.Value;
  42. if (model.SilenceWarning.IsSpecified)
  43. SilenceWarning = model.SilenceWarning.Value;
  44. if (model.Input.DeviceId.IsSpecified)
  45. InputDeviceId = model.Input.DeviceId.Value;
  46. if (model.Input.Volume.IsSpecified)
  47. InputVolume = model.Input.Volume.Value;
  48. if (model.Input.AvailableDevices.IsSpecified)
  49. AvailableInputDevices = model.Input.AvailableDevices.Value.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
  50. if (model.Output.DeviceId.IsSpecified)
  51. OutputDeviceId = model.Output.DeviceId.Value;
  52. if (model.Output.Volume.IsSpecified)
  53. OutputVolume = model.Output.Volume.Value;
  54. if (model.Output.AvailableDevices.IsSpecified)
  55. AvailableInputDevices = model.Output.AvailableDevices.Value.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
  56. if (model.Mode.Type.IsSpecified)
  57. ActivationMode = model.Mode.Type.Value;
  58. if (model.Mode.AutoThreshold.IsSpecified)
  59. AutoThreshold = model.Mode.AutoThreshold.Value;
  60. if (model.Mode.Threshold.IsSpecified)
  61. Threshold = model.Mode.Threshold.Value;
  62. if (model.Mode.Shortcut.IsSpecified)
  63. Shortcuts = model.Mode.Shortcut.Value.Select(x => VoiceShortcut.Create(x)).ToImmutableArray();
  64. if (model.Mode.Delay.IsSpecified)
  65. Delay = model.Mode.Delay.Value;
  66. }
  67. }
  68. }