Skip to content

Commit

Permalink
Implemented disconnecting users
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Dec 24, 2022
1 parent 27cf492 commit 9c6c384
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ Individual components of the main package can be installed separately.

### Experimental Packages

Experimental packages provide implementations of non-official released APIs, which are unlisted on official documentation,
not guaranteed to be stable, and may be changed or removed in the future.
Experimental packages provide implementations of non-official released APIs, which are not listed on official documentation,
may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.

- Kook.Net.Experimental: [NuGet](https://www.nuget.org/packages/Kook.Net.Experimental/), [Github Packages](https://github.com/gehongyan/Kook.Net/pkgs/nuget/Kook.Net.Experimental)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ namespace Kook;
/// <summary>
/// Provides properties that are used to modify an <see cref="IGuild" /> with the specified changes.
/// </summary>
/// <remarks>
/// <note type="warning">
/// This entity is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public class GuildProperties
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
namespace Kook;

/// <summary>
/// Represents a region of which the user connects to when using voice.
/// </summary>
/// <remarks>
/// <note type="warning">
/// This entity is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public interface IVoiceRegion
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Kook.Rest;

internal static class ExperimentalChannelHelper
{
#region Permissions

/// <exception cref="InvalidOperationException">This channel does not have a parent channel.</exception>
public static async Task SyncPermissionsAsync(INestedChannel channel, BaseKookClient client,
RequestOptions options)
Expand All @@ -17,4 +19,20 @@ public static async Task SyncPermissionsAsync(INestedChannel channel, BaseKookCl
await client.ApiClient.SyncChannelPermissionsAsync(args, options).ConfigureAwait(false);
}

#endregion

#region Voice

public static async Task DisconnectUserAsync(IVoiceChannel channel, BaseKookClient client, IGuildUser user, RequestOptions options)
{
var args = new DisconnectUserParams
{
UserId = user.Id,
ChannelId = channel.Id
};
await client.ApiClient.DisconnectUserAsync(args, options).ConfigureAwait(false);
}

#endregion

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ namespace Kook.Rest;

public static class RestTextChannelExperimentalExtensions
{
/// <summary>
/// Syncs the permissions of this nested channel with its parent's.
/// </summary>
/// <param name="channel">The nested channel whose permissions will be synced.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for syncing channel permissions with its parent's.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task SyncPermissionsAsync(this RestTextChannel channel, RequestOptions options = null)
=> ExperimentalChannelHelper.SyncPermissionsAsync(channel, channel.Kook, options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@ namespace Kook.Rest;

public static class RestVoiceChannelExperimentalExtensions
{
/// <summary>
/// Syncs the permissions of this nested channel with its parent's.
/// </summary>
/// <param name="channel">The nested channel whose permissions will be synced.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for syncing channel permissions with its parent's.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task SyncPermissionsAsync(this RestVoiceChannel channel, RequestOptions options = null)
=> ExperimentalChannelHelper.SyncPermissionsAsync(channel, channel.Kook, options);
/// <summary>
/// Disconnects the specified user from the voice channel.
/// </summary>
/// <param name="channel">The voice channel where the use is connected to.</param>
/// <param name="user">The user to disconnect.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for disconnecting the user from the voice channel.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task DisconnectUserAsync(this RestVoiceChannel channel, IGuildUser user, RequestOptions options = null)
=> ExperimentalChannelHelper.DisconnectUserAsync(channel, channel.Kook, user, options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public static class RestGuildExperimentalExtensions
/// <param name="guild">The guild to delete.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>A task that represents the asynchronous deletion operation.</returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task DeleteAsync(this RestGuild guild, RequestOptions options = null)
=> ExperimentalGuildHelper.DeleteAsync(guild, guild.Kook, options);
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace Kook.Rest;
/// <summary>
/// Represents a REST-based voice region.
/// </summary>
/// <remarks>
/// <note type="warning">
/// This entity is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RestVoiceRegion : RestEntity<string>, IVoiceRegion
{
Expand Down
14 changes: 0 additions & 14 deletions src/Kook.Net.Experimental/Rest/ExperimentalClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,4 @@ public static async Task<RestVoiceRegion> GetVoiceRegionAsync(BaseKookClient cli
}

#endregion

#region Voice

public static async Task DisconnectUserAsync(BaseKookClient client, IGuildUser user, IVoiceChannel channel, RequestOptions options)
{
var args = new DisconnectUserParams
{
UserId = user.Id,
ChannelId = channel.Id
};
await client.ApiClient.DisconnectUserAsync(args, options).ConfigureAwait(false);
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,61 @@ namespace Kook.Rest;

public static class KookRestClientExperimentalExtensions
{
/// <summary>
/// Gets a collection of the available voice regions.
/// </summary>
/// <param name="client">The KOOK rest client instance.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous get operation. The task result contains a read-only collection
/// with all of the available voice regions in this session.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(this KookRestClient client, RequestOptions options = null)
=> ExperimentalClientHelper.GetVoiceRegionsAsync(client, options);
/// <summary>
/// Gets a voice region.
/// </summary>
/// <param name="client">The KOOK rest client instance.</param>
/// <param name="id">The identifier of the voice region (e.g. <c>eu-central</c> ).</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous get operation. The task result contains the voice region
/// associated with the identifier; <c>null</c> if the voice region is not found.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task<RestVoiceRegion> GetVoiceRegionAsync(this KookRestClient client, string id, RequestOptions options = null)
=> ExperimentalClientHelper.GetVoiceRegionAsync(client, id, options);

/// <summary>
/// Creates a guild for the logged-in user who is in less than 10 active guilds.
/// </summary>
/// <remarks>
/// This method creates a new guild on behalf of the logged-in user.
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
/// <param name="client">The KOOK rest client instance.</param>
/// <param name="name">The name of the new guild.</param>
/// <param name="region">The voice region to create the guild with.</param>
/// <param name="icon">The icon of the new guild.</param>
/// <param name="templateId">The identifier of the guild template to be used to create the new guild.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the created guild.
/// </returns>
public static Task<RestGuild> CreateGuildAsync(this KookRestClient client,
string name, IVoiceRegion region = null, Stream icon = null, int? templateId = null, RequestOptions options = null)
=> ExperimentalClientHelper.CreateGuildAsync(client, name, region, icon, templateId, options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ namespace Kook.WebSocket;

public static class BaseSocketClientExperimentalExtensions
{
/// <summary>
/// Creates a guild for the logged-in user who is in less than 10 active guilds.
/// </summary>
/// <remarks>
/// This method creates a new guild on behalf of the logged-in user.
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable,and may be changed or removed in the future.
/// </note>
/// </remarks>
/// <param name="client">The KOOK rest client instance.</param>
/// <param name="name">The name of the new guild.</param>
/// <param name="region">The voice region to create the guild with.</param>
/// <param name="icon">The icon of the new guild.</param>
/// <param name="templateId">The identifier of the guild template to be used to create the new guild.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the created guild.
/// </returns>
public static Task<RestGuild> CreateGuildAsync(this BaseSocketClient client,
string name, IVoiceRegion region = null, Stream icon = null, int? templateId = null, RequestOptions options = null)
=> ExperimentalClientHelper.CreateGuildAsync(client, name, region, icon, templateId, options ?? RequestOptions.Default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ namespace Kook.WebSocket;

public static class SocketTextChannelExperimentalExtensions
{
/// <summary>
/// Syncs the permissions of this nested channel with its parent's.
/// </summary>
/// <param name="channel">The nested channel whose permissions will be synced.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for syncing channel permissions with its parent's.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task SyncPermissionsAsync(this SocketTextChannel channel, RequestOptions options = null)
=> ExperimentalChannelHelper.SyncPermissionsAsync(channel, channel.Kook, options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,38 @@ namespace Kook.WebSocket;

public static class SocketVoiceChannelExperimentalExtensions
{
/// <summary>
/// Syncs the permissions of this nested channel with its parent's.
/// </summary>
/// <param name="channel">The nested channel whose permissions will be synced.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for syncing channel permissions with its parent's.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task SyncPermissionsAsync(this SocketVoiceChannel channel, RequestOptions options = null)
=> ExperimentalChannelHelper.SyncPermissionsAsync(channel, channel.Kook, options);

/// <summary>
/// Disconnects the specified user from the voice channel.
/// </summary>
/// <param name="channel">The voice channel where the use is connected to.</param>
/// <param name="user">The user to disconnect.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous operation for disconnecting the user from the voice channel.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task DisconnectUserAsync(this SocketVoiceChannel channel, IGuildUser user, RequestOptions options = null)
=> ExperimentalChannelHelper.DisconnectUserAsync(channel, channel.Kook, user, options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ public static class SocketGuildExperimentalExtensions
/// <param name="guild">The guild to delete.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>A task that represents the asynchronous deletion operation.</returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
public static Task DeleteAsync(this SocketGuild guild, RequestOptions options = null)
=> ExperimentalGuildHelper.DeleteAsync(guild, guild.Kook, options);
/// <summary>
Expand All @@ -21,6 +27,12 @@ public static Task DeleteAsync(this SocketGuild guild, RequestOptions options =
/// <returns>
/// A task that represents the asynchronous modification operation.
/// </returns>
/// <remarks>
/// <note type="warning">
/// This method is still in experimental state, which means that it is not for official API implementation
/// usage, may violate the developer rules or policies, not guaranteed to be stable, and may be changed or removed in the future.
/// </note>
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
public static Task ModifyAsync(this SocketGuild guild, Action<GuildProperties> func, RequestOptions options = null)
=> ExperimentalGuildHelper.ModifyAsync(guild, guild.Kook, func, options);
Expand Down
6 changes: 3 additions & 3 deletions src/Kook.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ internal override void Update(ClientState state, Model model)
public virtual Task ModifyAsync(Action<ModifyTextChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Kook, func, options);

private string DebuggerDisplay => $"{Name} ({Id}, Text)";
internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel;

#endregion

#region Messages
Expand Down Expand Up @@ -214,9 +217,6 @@ public async Task<IInvite> CreateInviteAsync(InviteMaxAge maxAge = InviteMaxAge.
=> await ChannelHelper.CreateInviteAsync(this, Kook, maxAge, maxUses, options).ConfigureAwait(false);

#endregion

private string DebuggerDisplay => $"{Name} ({Id}, Text)";
internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel;

#region Users
/// <inheritdoc />
Expand Down

0 comments on commit 9c6c384

Please sign in to comment.