[Feature] Voice channel status support (#2777)

* initial commit

* MOCKED CHANNELS AGRHHHHHHHH

* fix for sharded

* yup
This commit is contained in:
Mihail Gribkov
2023-11-18 23:42:14 +03:00
committed by GitHub
parent 8e4d449615
commit 8060dcf4ae
30 changed files with 323 additions and 17 deletions

View File

@@ -36,4 +36,7 @@ internal class AuditLogOptions
[JsonProperty("auto_moderation_rule_trigger_type")]
public AutoModTriggerType? AutoModRuleTriggerType { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
}

View File

@@ -46,6 +46,9 @@ namespace Discord.API
[JsonProperty("video_quality_mode")]
public Optional<VideoQualityMode> VideoQualityMode { get; set; }
[JsonProperty("status")]
public Optional<string> Status { get; set; }
//PrivateChannel
[JsonProperty("recipients")]
public Optional<User[]> Recipients { get; set; }

View File

@@ -0,0 +1,9 @@
using Newtonsoft.Json;
namespace Discord.API.Rest;
internal class ModifyVoiceStatusParams
{
[JsonProperty("status")]
public string Status { get; set; }
}

View File

@@ -467,6 +467,17 @@ namespace Discord.API
break;
}
}
public async Task ModifyVoiceChannelStatusAsync(ulong channelId, string status, RequestOptions options = null)
{
Preconditions.NotEqual(channelId, 0, nameof(channelId));
var payload = new ModifyVoiceStatusParams { Status = status };
var ids = new BucketIds();
await SendJsonAsync("PUT", () => $"channels/{channelId}/voice-status", payload, ids, options: options);
}
#endregion
#region Threads

View File

@@ -86,6 +86,9 @@ internal static class AuditLogHelper
[ActionType.OnboardingQuestionCreated] = OnboardingPromptCreatedAuditLogData.Create,
[ActionType.OnboardingQuestionUpdated] = OnboardingPromptUpdatedAuditLogData.Create,
[ActionType.OnboardingUpdated] = OnboardingUpdatedAuditLogData.Create,
[ActionType.VoiceChannelStatusUpdated] = VoiceChannelStatusUpdateAuditLogData.Create,
[ActionType.VoiceChannelStatusDeleted] = VoiceChannelStatusDeletedAuditLogData.Create
};
public static IAuditLogData CreateData(BaseDiscordClient discord, EntryModel entry, Model log = null)

View File

@@ -0,0 +1,25 @@
using EntryModel = Discord.API.AuditLogEntry;
using Model = Discord.API.AuditLog;
namespace Discord.Rest;
/// <summary>
/// Contains a piece of audit log data related to a voice channel status delete.
/// </summary>
public class VoiceChannelStatusDeletedAuditLogData : IAuditLogData
{
private VoiceChannelStatusDeletedAuditLogData(ulong channelId)
{
ChannelId = channelId;
}
internal static VoiceChannelStatusDeletedAuditLogData Create(BaseDiscordClient discord, EntryModel entry, Model log = null)
{
return new (entry.TargetId!.Value);
}
/// <summary>
/// Get the id of the channel status was removed in.
/// </summary>
public ulong ChannelId { get; }
}

View File

@@ -0,0 +1,31 @@
using EntryModel = Discord.API.AuditLogEntry;
using Model = Discord.API.AuditLog;
namespace Discord.Rest;
/// <summary>
/// Contains a piece of audit log data related to a voice channel status update.
/// </summary>
public class VoiceChannelStatusUpdateAuditLogData : IAuditLogData
{
private VoiceChannelStatusUpdateAuditLogData(string status, ulong channelId)
{
Status = status;
ChannelId = channelId;
}
internal static VoiceChannelStatusUpdateAuditLogData Create(BaseDiscordClient discord, EntryModel entry, Model log = null)
{
return new (entry.Options.Status, entry.TargetId!.Value);
}
/// <summary>
/// Gets the status that was set in the voice channel.
/// </summary>
public string Status { get; }
/// <summary>
/// Get the id of the channel status was updated in.
/// </summary>
public ulong ChannelId { get; }
}

View File

@@ -636,5 +636,16 @@ namespace Discord.Rest
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
}
#endregion
#region Voice
public static async Task ModifyVoiceChannelStatusAsync(IVoiceChannel channel, string status, BaseDiscordClient client, RequestOptions options)
{
Preconditions.AtMost(status.Length, DiscordConfig.MaxVoiceChannelStatusLength, $"Voice channel status length must be less than {DiscordConfig.MaxVoiceChannelStatusLength}.");
await client.ApiClient.ModifyVoiceChannelStatusAsync(channel.Id, status, options).ConfigureAwait(false);
}
#endregion
}
}

View File

@@ -150,5 +150,13 @@ namespace Discord.Rest
return Discord.ApiClient.ModifyUserVoiceState(Guild.Id, user.Id, args);
}
/// <inheritdoc />
/// <remarks>
/// Setting voice channel status is not supported in stage channels.
/// </remarks>
/// <exception cref="NotSupportedException">Setting voice channel status is not supported in stage channels.</exception>
public override Task SetStatusAsync(string status, RequestOptions options = null)
=> throw new NotSupportedException("Setting voice channel status is not supported in stage channels.");
}
}

View File

@@ -69,6 +69,10 @@ namespace Discord.Rest
public override Task<RestThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null)
=> throw new InvalidOperationException("Cannot create a thread within a voice channel");
/// <inheritdoc />
public virtual Task SetStatusAsync(string status, RequestOptions options = null)
=> ChannelHelper.ModifyVoiceChannelStatusAsync(this, status, Discord, options);
#endregion
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";