Skip to content

Commit

Permalink
Added supports for disconnecting users
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Dec 21, 2022
1 parent d6c362f commit 27cf492
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Kook.Net.Experimental/Rest/API/Rest/DisconnectUserParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Kook.API.Rest;

internal class DisconnectUserParams
{
[JsonPropertyName("channel_id")]
public ulong ChannelId { get; set; }

[JsonPropertyName("user_id")]
public ulong UserId { get; set; }
}
23 changes: 23 additions & 0 deletions src/Kook.Net.Experimental/Rest/ExperimentalClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Kook.Rest;

internal static class ExperimentalClientHelper
{
#region Guild

public static async Task<RestGuild> CreateGuildAsync(BaseKookClient client,
string name, IVoiceRegion region = null, Stream icon = null, int? templateId = null, RequestOptions options = null)
{
Expand All @@ -21,6 +23,11 @@ public static async Task<RestGuild> CreateGuildAsync(BaseKookClient client,
var model = await client.ApiClient.CreateGuildAsync(args, options).ConfigureAwait(false);
return RestGuild.Create(client, model);
}

#endregion

#region Voice Region

public static async Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(BaseKookClient client, RequestOptions options)
{
var models = await client.ApiClient.GetVoiceRegionsAsync(options: options).FlattenAsync().ConfigureAwait(false);
Expand All @@ -31,4 +38,20 @@ public static async Task<RestVoiceRegion> GetVoiceRegionAsync(BaseKookClient cli
var models = await client.ApiClient.GetVoiceRegionsAsync(options: options).FlattenAsync().ConfigureAwait(false);
return models.Select(x => RestVoiceRegion.Create(client, x)).FirstOrDefault(x => x.Id == id);
}

#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 @@ -61,4 +61,19 @@ public static IAsyncEnumerable<IReadOnlyCollection<VoiceRegion>> GetVoiceRegions

#endregion

#region Voice

public static async Task DisconnectUserAsync(this KookRestApiClient client, DisconnectUserParams args, RequestOptions options = null)
{
Preconditions.NotNull(args, nameof(args));
Preconditions.NotEqual(args.ChannelId, 0, nameof(args.ChannelId));
Preconditions.NotEqual(args.UserId, 0, nameof(args.UserId));
options = RequestOptions.CreateOrClone(options);

var ids = new KookRestApiClient.BucketIds(channelId: args.ChannelId);
await client.SendJsonAsync(HttpMethod.Post, () => $"channel/kickout", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
}

#endregion

}

0 comments on commit 27cf492

Please sign in to comment.