Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add voice channel statuses #312

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// IVoiceChannelStatusUpdate.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using Remora.Rest.Core;

namespace Remora.Discord.API.Abstractions.Gateway.Events;

/// <summary>
/// Represents an update to the respective voice channel.
/// </summary>
public interface IVoiceChannelStatusUpdate : IGatewayEvent
{
/// <summary>
/// Gets the ID of the channel being updated.
/// </summary>
Snowflake ID { get; }

Check notice

Code scanning / InspectCode

Type member is never used: Non-private accessibility Note

Property 'ID' is never used

/// <summary>
/// Gets the ID of the guild.
/// </summary>
Snowflake GuildID { get; }

Check notice

Code scanning / InspectCode

Type member is never used: Non-private accessibility Note

Property 'GuildID' is never used

/// <summary>
/// Gets the new status of the voice channel.
/// </summary>
Optional<string> Status { get; }

Check notice

Code scanning / InspectCode

Type member is never used: Non-private accessibility Note

Property 'Status' is never used
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ public interface IChannel : IPartialChannel
/// </summary>
new Optional<ForumLayout> DefaultForumLayout { get; }

/// <summary>
/// Gets the status of the channel.
/// </summary>
new Optional<string?> Status { get; }

/// <inheritdoc/>
Optional<Snowflake> IPartialChannel.ID => this.ID;

Expand Down Expand Up @@ -316,4 +321,7 @@ public interface IChannel : IPartialChannel

/// <inheritdoc/>
Optional<ForumLayout> IPartialChannel.DefaultForumLayout => this.DefaultForumLayout;

/// <inheritdoc/>
Optional<string?> IPartialChannel.Status => this.Status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,7 @@ public interface IPartialChannel

/// <inheritdoc cref="IChannel.DefaultForumLayout" />
Optional<ForumLayout> DefaultForumLayout { get; }

/// <inheritdoc cref="IChannel.Status"/>
Optional<string?> Status { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ public interface IDiscordRestChannelAPI
/// <returns>A retrieval result which may or may not have succeeded.</returns>
Task<Result<IChannel>> GetChannelAsync(Snowflake channelID, CancellationToken ct = default);

/// <summary>
/// Sets the status of a given voice channel.
/// </summary>
/// <param name="channelID">The ID of the channel.</param>
/// <param name="status">The status to set.</param>
/// <param name="reason">The reason to mark the action in the audit log with.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A modification result that may or not have succeeded.</returns>
Task<Result> SetVoiceChannelStatusAsync
(
Snowflake channelID,
Optional<string> status,
Optional<string> reason = default,
CancellationToken ct = default
);

/// <summary>
/// Modifies the given channel.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public record ChannelCreate
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IChannelCreate;
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public record ChannelDelete
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IChannelDelete;
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public record ChannelUpdate
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IChannelUpdate;
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ public record ThreadCreate
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IThreadCreate;
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public record ThreadDelete
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IThreadDelete;
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ public record ThreadUpdate
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IThreadUpdate;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// VoiceChannelStatusUpdate.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Rest.Core;

namespace Remora.Discord.API.Gateway.Events.Channels;

/// <inheritdoc cref="Remora.Discord.API.Abstractions.Gateway.Events.IVoiceChannelStatusUpdate"/>
public record VoiceChannelStatusUpdate

Check notice

Code scanning / InspectCode

Type is never used: Non-private accessibility Note

Record 'VoiceChannelStatusUpdate' is never used
(
Snowflake ID,
Snowflake GuildID,
Optional<string> Status
) : IVoiceChannelStatusUpdate;
3 changes: 2 additions & 1 deletion Backend/Remora.Discord.API/API/Objects/Channels/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ public record Channel
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IChannel;
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ public record PartialChannel
Optional<IDefaultReaction?> DefaultReactionEmoji = default,
Optional<TimeSpan> DefaultThreadRateLimitPerUser = default,
Optional<SortOrder?> DefaultSortOrder = default,
Optional<ForumLayout> DefaultForumLayout = default
Optional<ForumLayout> DefaultForumLayout = default,
Optional<string?> Status = default
) : IPartialChannel;
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ namespace Remora.Discord.Caching.API;

public partial class CachingDiscordRestChannelAPI
{
/// <inheritdoc />
public Task<Result> SetVoiceChannelStatusAsync
(
Snowflake channelID,
Optional<string> status,
Optional<string> reason = default,
CancellationToken ct = default
)
{
return _actual.SetVoiceChannelStatusAsync(channelID, status, reason, ct);
}

/// <inheritdoc />
public Task<Result<IChannel>> ModifyGroupDMChannelAsync
(
Expand Down
22 changes: 22 additions & 0 deletions Backend/Remora.Discord.Rest/API/Channels/DiscordRestChannelAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@
);
}

/// <inheritdoc />
public virtual Task<Result> SetVoiceChannelStatusAsync
(
Snowflake channelID,
Optional<string> status,
Optional<string> reason = default,
CancellationToken ct = default
)
{
if (status is { HasValue: true, Value: { Length: > 500 } })

Check notice

Code scanning / InspectCode

Merge nested property patterns Note

Merge nested property patterns
{
return Task.FromResult<Result>(new ArgumentOutOfRangeError(nameof(status), "The status must between 0 and 500 characters."));
}

return this.RestHttpClient.PatchAsync
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing AddAuditReason call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist on the non-generic methods it seems. cc @Nihlus

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the check about status length here

(
$"channels/{channelID}/voice-status",
b => b.WithJson(b => b.Write("status", status, this.JsonOptions)).WithRateLimitContext(this.RateLimitCache),

Check warning

Code scanning / InspectCode

Variable in local function hides variable from outer scope Warning

Parameter 'b' hides outer parameter with the same name
ct: ct
);
}

/// <inheritdoc />
public virtual async Task<Result<IChannel>> ModifyChannelAsync
(
Expand Down
Loading