Added RPC Get/Set VoiceSettings
This commit is contained in:
@@ -319,14 +319,12 @@ namespace Discord.API
|
||||
public async Task<SubscriptionResponse> SendGlobalSubscribeAsync(string evt, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var msg = new object();
|
||||
return await SendRpcAsync<SubscriptionResponse>("SUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false);
|
||||
return await SendRpcAsync<SubscriptionResponse>("SUBSCRIBE", null, evt: evt, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<SubscriptionResponse> SendGlobalUnsubscribeAsync(string evt, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var msg = new object();
|
||||
return await SendRpcAsync<SubscriptionResponse>("UNSUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false);
|
||||
return await SendRpcAsync<SubscriptionResponse>("UNSUBSCRIBE", null, evt: evt, options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<SubscriptionResponse> SendGuildSubscribeAsync(string evt, ulong guildId, RequestOptions options = null)
|
||||
@@ -367,6 +365,17 @@ namespace Discord.API
|
||||
return await SendRpcAsync<SubscriptionResponse>("UNSUBSCRIBE", msg, evt: evt, options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<API.Rpc.VoiceSettings> GetVoiceSettingsAsync(RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
return await SendRpcAsync<API.Rpc.VoiceSettings>("GET_VOICE_SETTINGS", null, options: options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task<API.Rpc.VoiceSettings> SetVoiceSettingsAsync(API.Rpc.VoiceSettings settings, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
return await SendRpcAsync<API.Rpc.VoiceSettings>("SET_VOICE_SETTINGS", settings, options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private bool ProcessMessage(API.Rpc.RpcFrame msg)
|
||||
{
|
||||
RpcRequest requestTracker;
|
||||
|
||||
@@ -5,10 +5,10 @@ namespace Discord.API.Rpc
|
||||
public class VoiceDeviceSettings
|
||||
{
|
||||
[JsonProperty("device_id")]
|
||||
public string DeviceId { get; set; }
|
||||
public Optional<string> DeviceId { get; set; }
|
||||
[JsonProperty("volume")]
|
||||
public float Volume { get; set; }
|
||||
public Optional<float> Volume { get; set; }
|
||||
[JsonProperty("available_devices")]
|
||||
public VoiceDevice[] AvailableDevices { get; set; }
|
||||
public Optional<VoiceDevice[]> AvailableDevices { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,14 @@ namespace Discord.API.Rpc
|
||||
public class VoiceMode
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public string Type { get; set; }
|
||||
public Optional<string> Type { get; set; }
|
||||
[JsonProperty("auto_threshold")]
|
||||
public bool AutoThreshold { get; set; }
|
||||
public Optional<bool> AutoThreshold { get; set; }
|
||||
[JsonProperty("threshold")]
|
||||
public float Threshold { get; set; }
|
||||
public Optional<float> Threshold { get; set; }
|
||||
[JsonProperty("shortcut")]
|
||||
public VoiceShortcut[] Shortcut { get; set; }
|
||||
public Optional<VoiceShortcut[]> Shortcut { get; set; }
|
||||
[JsonProperty("delay")]
|
||||
public float Delay { get; set; }
|
||||
public Optional<float> Delay { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@ namespace Discord.API.Rpc
|
||||
[JsonProperty("mode")]
|
||||
public VoiceMode Mode { get; set; }
|
||||
[JsonProperty("automatic_gain_control")]
|
||||
public bool AutomaticGainControl { get; set; }
|
||||
public Optional<bool> AutomaticGainControl { get; set; }
|
||||
[JsonProperty("echo_cancellation")]
|
||||
public bool EchoCancellation { get; set; }
|
||||
public Optional<bool> EchoCancellation { get; set; }
|
||||
[JsonProperty("noise_suppression")]
|
||||
public bool NoiseSuppression { get; set; }
|
||||
public Optional<bool> NoiseSuppression { get; set; }
|
||||
[JsonProperty("qos")]
|
||||
public bool QualityOfService { get; set; }
|
||||
public Optional<bool> QualityOfService { get; set; }
|
||||
[JsonProperty("silence_warning")]
|
||||
public bool SilenceWarning { get; set; }
|
||||
public Optional<bool> SilenceWarning { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace Discord.API.Rpc
|
||||
public class VoiceShortcut
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
public VoiceShortcutType Type { get; set; }
|
||||
public Optional<VoiceShortcutType> Type { get; set; }
|
||||
[JsonProperty("code")]
|
||||
public int Code { get; set; }
|
||||
public Optional<int> Code { get; set; }
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
public Optional<string> Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,6 +265,21 @@ namespace Discord.Rpc
|
||||
await ApiClient.SendChannelUnsubscribeAsync(GetEventName(events[i]), channelId);
|
||||
}
|
||||
|
||||
public async Task<VoiceSettings> GetVoiceSettingsAsync()
|
||||
{
|
||||
var model = await ApiClient.GetVoiceSettingsAsync().ConfigureAwait(false);
|
||||
return VoiceSettings.Create(model);
|
||||
}
|
||||
public async Task SetVoiceSettingsAsync(Action<API.Rpc.VoiceSettings> func)
|
||||
{
|
||||
var settings = new API.Rpc.VoiceSettings();
|
||||
settings.Input = new VoiceDeviceSettings();
|
||||
settings.Output = new VoiceDeviceSettings();
|
||||
settings.Mode = new VoiceMode();
|
||||
func(settings);
|
||||
await ApiClient.SetVoiceSettingsAsync(settings).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static string GetEventName(RpcGlobalEvent rpcEvent)
|
||||
{
|
||||
switch (rpcEvent)
|
||||
|
||||
@@ -36,25 +36,41 @@ namespace Discord.Rpc
|
||||
}
|
||||
internal void Update(Model model)
|
||||
{
|
||||
AutomaticGainControl = model.AutomaticGainControl;
|
||||
EchoCancellation = model.EchoCancellation;
|
||||
NoiseSuppression = model.NoiseSuppression;
|
||||
QualityOfService = model.QualityOfService;
|
||||
SilenceWarning = model.SilenceWarning;
|
||||
if (model.AutomaticGainControl.IsSpecified)
|
||||
AutomaticGainControl = model.AutomaticGainControl.Value;
|
||||
if (model.EchoCancellation.IsSpecified)
|
||||
EchoCancellation = model.EchoCancellation.Value;
|
||||
if (model.NoiseSuppression.IsSpecified)
|
||||
NoiseSuppression = model.NoiseSuppression.Value;
|
||||
if (model.QualityOfService.IsSpecified)
|
||||
QualityOfService = model.QualityOfService.Value;
|
||||
if (model.SilenceWarning.IsSpecified)
|
||||
SilenceWarning = model.SilenceWarning.Value;
|
||||
|
||||
InputDeviceId = model.Input.DeviceId;
|
||||
InputVolume = model.Input.Volume;
|
||||
AvailableInputDevices = model.Input.AvailableDevices.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
|
||||
if (model.Input.DeviceId.IsSpecified)
|
||||
InputDeviceId = model.Input.DeviceId.Value;
|
||||
if (model.Input.Volume.IsSpecified)
|
||||
InputVolume = model.Input.Volume.Value;
|
||||
if (model.Input.AvailableDevices.IsSpecified)
|
||||
AvailableInputDevices = model.Input.AvailableDevices.Value.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
|
||||
|
||||
OutputDeviceId = model.Output.DeviceId;
|
||||
OutputVolume = model.Output.Volume;
|
||||
AvailableInputDevices = model.Output.AvailableDevices.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
|
||||
if (model.Output.DeviceId.IsSpecified)
|
||||
OutputDeviceId = model.Output.DeviceId.Value;
|
||||
if (model.Output.Volume.IsSpecified)
|
||||
OutputVolume = model.Output.Volume.Value;
|
||||
if (model.Output.AvailableDevices.IsSpecified)
|
||||
AvailableInputDevices = model.Output.AvailableDevices.Value.Select(x => VoiceDevice.Create(x)).ToImmutableArray();
|
||||
|
||||
ActivationMode = model.Mode.Type;
|
||||
AutoThreshold = model.Mode.AutoThreshold;
|
||||
Threshold = model.Mode.Threshold;
|
||||
Shortcuts = model.Mode.Shortcut.Select(x => VoiceShortcut.Create(x)).ToImmutableArray();
|
||||
Delay = model.Mode.Delay;
|
||||
if (model.Mode.Type.IsSpecified)
|
||||
ActivationMode = model.Mode.Type.Value;
|
||||
if (model.Mode.AutoThreshold.IsSpecified)
|
||||
AutoThreshold = model.Mode.AutoThreshold.Value;
|
||||
if (model.Mode.Threshold.IsSpecified)
|
||||
Threshold = model.Mode.Threshold.Value;
|
||||
if (model.Mode.Shortcut.IsSpecified)
|
||||
Shortcuts = model.Mode.Shortcut.Value.Select(x => VoiceShortcut.Create(x)).ToImmutableArray();
|
||||
if (model.Mode.Delay.IsSpecified)
|
||||
Delay = model.Mode.Delay.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Discord.Rpc
|
||||
}
|
||||
internal static VoiceShortcut Create(Model model)
|
||||
{
|
||||
return new VoiceShortcut(model.Type, model.Code, model.Name);
|
||||
return new VoiceShortcut(model.Type.Value, model.Code.Value, model.Name.Value);
|
||||
}
|
||||
|
||||
public override string ToString() => $"{Name}";
|
||||
|
||||
Reference in New Issue
Block a user