Browse Source

Merge pull request #39 from lhjt/Interactions

Add slash command delete operations
pull/1923/head
Quin Lynch GitHub 4 years ago
parent
commit
ea449dbf5c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 6 deletions
  1. +9
    -0
      src/Discord.Net.Rest/Discord.Net.Rest.xml
  2. +2
    -1
      src/Discord.Net.Rest/DiscordRestClient.cs
  3. +10
    -0
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  4. +13
    -3
      src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs
  5. +9
    -0
      src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml
  6. +12
    -2
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 9
- 0
src/Discord.Net.Rest/Discord.Net.Rest.xml View File

@@ -2740,6 +2740,15 @@
<member name="M:Discord.Rest.RestGuild.LeaveAsync(Discord.RequestOptions)">
<inheritdoc />
</member>
<member name="M:Discord.Rest.RestGuild.DeleteSlashCommandsAsync(Discord.RequestOptions)">
<summary>
Deletes all slash commands in the current guild.
</summary>
<param name="options">The options to be used when sending the request.</param>
<returns>
A task that represents the asynchronous delete operation.
</returns>
</member>
<member name="M:Discord.Rest.RestGuild.GetSlashCommandsAsync(Discord.RequestOptions)">
<summary>
Gets a collection of slash commands created by the current user in this guild.


+ 2
- 1
src/Discord.Net.Rest/DiscordRestClient.cs View File

@@ -125,7 +125,8 @@ namespace Discord.Rest
=> InteractionHelper.BulkOverwriteGuildCommands(this, guildId, commandProperties, options);
public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null)
=> InteractionHelper.BatchEditGuildCommandPermissionsAsync(this, guildId, permissions, options);

public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null)
=> InteractionHelper.DeleteAllGlobalCommandsAsync(this, options);

public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId)
=> ClientHelper.AddRoleAsync(this, guildId, userId, roleId);


+ 10
- 0
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -256,6 +256,16 @@ namespace Discord.Rest
=> GuildHelper.LeaveAsync(this, Discord, options);

//Interactions
/// <summary>
/// Deletes all slash commands in the current guild.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous delete operation.
/// </returns>
public Task DeleteSlashCommandsAsync(RequestOptions options = null)
=> InteractionHelper.DeleteAllGuildCommandsAsync(Discord, this.Id, options);

/// <summary>
/// Gets a collection of slash commands created by the current user in this guild.
/// </summary>


+ 13
- 3
src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs View File

@@ -11,6 +11,16 @@ namespace Discord.Rest
{
internal static class InteractionHelper
{
public static Task DeleteAllGuildCommandsAsync(BaseDiscordClient client, ulong guildId, RequestOptions options = null)
{
return client.ApiClient.BulkOverwriteGuildApplicationCommands(guildId, new CreateApplicationCommandParams[0], options);
}

public static Task DeleteAllGlobalCommandsAsync(BaseDiscordClient client, RequestOptions options = null)
{
return client.ApiClient.BulkOverwriteGlobalApplicationCommands(new CreateApplicationCommandParams[0], options);
}

public static Task SendInteractionResponse(BaseDiscordClient client, IMessageChannel channel, InteractionResponse response,
ulong interactionId, string interactionToken, RequestOptions options = null)
{
@@ -348,7 +358,7 @@ namespace Discord.Rest
return new GuildApplicationCommandPermission(model.Id, model.ApplicationId, guildId, model.Permissions.Select(
y => new ApplicationCommandPermission(y.Id, y.Type, y.Permission)).ToArray());
}
catch(HttpException x)
catch (HttpException x)
{
if (x.HttpCode == System.Net.HttpStatusCode.NotFound)
return null;
@@ -365,7 +375,7 @@ namespace Discord.Rest

List<ApplicationCommandPermissions> models = new List<ApplicationCommandPermissions>();

foreach(var arg in args)
foreach (var arg in args)
{
var model = new ApplicationCommandPermissions()
{
@@ -391,7 +401,7 @@ namespace Discord.Rest

List<ModifyGuildApplicationCommandPermissions> models = new List<ModifyGuildApplicationCommandPermissions>();

foreach(var arg in args)
foreach (var arg in args)
{
Preconditions.AtMost(arg.Value.Length, 10, nameof(args));



+ 9
- 0
src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml View File

@@ -2843,6 +2843,15 @@
voice regions the guild can access.
</returns>
</member>
<member name="M:Discord.WebSocket.SocketGuild.DeleteSlashCommandsAsync(Discord.RequestOptions)">
<summary>
Deletes all slash commands in the current guild.
</summary>
<param name="options">The options to be used when sending the request.</param>
<returns>
A task that represents the asynchronous delete operation.
</returns>
</member>
<member name="M:Discord.WebSocket.SocketGuild.GetSlashCommandsAsync(Discord.RequestOptions)">
<summary>
Gets a collection of slash commands created by the current user in this guild.


+ 12
- 2
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -724,6 +724,16 @@ namespace Discord.WebSocket
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);

//Interactions
/// <summary>
/// Deletes all slash commands in the current guild.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents the asynchronous delete operation.
/// </returns>
public Task DeleteSlashCommandsAsync(RequestOptions options = null)
=> InteractionHelper.DeleteAllGuildCommandsAsync(Discord, this.Id, options);

/// <summary>
/// Gets a collection of slash commands created by the current user in this guild.
/// </summary>
@@ -823,7 +833,7 @@ namespace Discord.WebSocket
if (_roles.TryGetValue(model.Id, out SocketRole role))
_roles[model.Id].Update(this.Discord.State, model);
else
role = AddRole(model);
role = AddRole(model);

return role;
}
@@ -1289,7 +1299,7 @@ namespace Discord.WebSocket
Task<IReadOnlyCollection<IVoiceChannel>> IGuild.GetVoiceChannelsAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IReadOnlyCollection<IVoiceChannel>>(VoiceChannels);
/// <inheritdoc />
Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode , RequestOptions options)
Task<IReadOnlyCollection<ICategoryChannel>> IGuild.GetCategoriesAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IReadOnlyCollection<ICategoryChannel>>(CategoryChannels);
/// <inheritdoc />
Task<IVoiceChannel> IGuild.GetVoiceChannelAsync(ulong id, CacheMode mode, RequestOptions options)


Loading…
Cancel
Save