Browse Source

added deafult permission option to context commands (#155)

pull/1923/head
Cenk Ergen GitHub 3 years ago
parent
commit
d6c62335ed
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 31 deletions
  1. +5
    -0
      src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs
  2. +18
    -1
      src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs
  3. +18
    -1
      src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs
  4. +0
    -5
      src/Discord.Net.Core/Entities/Interactions/SlashCommandProperties.cs
  5. +18
    -24
      src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs

+ 5
- 0
src/Discord.Net.Core/Entities/Interactions/ApplicationCommandProperties.cs View File

@@ -18,6 +18,11 @@ namespace Discord
/// </summary> /// </summary>
public Optional<string> Name { get; set; } public Optional<string> Name { get; set; }


/// <summary>
/// Whether the command is enabled by default when the app is added to a guild. Default is <see langword="true"/>
/// </summary>
public Optional<bool> DefaultPermission { get; set; }

internal ApplicationCommandProperties() { } internal ApplicationCommandProperties() { }
} }
} }

+ 18
- 1
src/Discord.Net.Core/Entities/Interactions/Context Menus/MessageCommandBuilder.cs View File

@@ -36,6 +36,11 @@ namespace Discord
} }
} }


/// <summary>
/// Whether the command is enabled by default when the app is added to a guild
/// </summary>
public bool DefaultPermission { get; set; } = true;

private string _name { get; set; } private string _name { get; set; }


/// <summary> /// <summary>
@@ -49,6 +54,7 @@ namespace Discord
MessageCommandProperties props = new MessageCommandProperties() MessageCommandProperties props = new MessageCommandProperties()
{ {
Name = this.Name, Name = this.Name,
DefaultPermission = this.DefaultPermission
}; };


return props; return props;
@@ -66,6 +72,17 @@ namespace Discord
{ {
this.Name = name; this.Name = name;
return this; return this;
}
}

/// <summary>
/// Sets the default permission of the current command.
/// </summary>
/// <param name="value">The default permission value to set.</param>
/// <returns>The current builder.</returns>
public MessageCommandBuilder WithDefaultPermission (bool value)
{
this.DefaultPermission = value;
return this;
}
} }
} }

+ 18
- 1
src/Discord.Net.Core/Entities/Interactions/Context Menus/UserCommandBuilder.cs View File

@@ -36,6 +36,11 @@ namespace Discord
} }
} }


/// <summary>
/// Whether the command is enabled by default when the app is added to a guild
/// </summary>
public bool DefaultPermission { get; set; } = true;

private string _name { get; set; } private string _name { get; set; }


/// <summary> /// <summary>
@@ -47,6 +52,7 @@ namespace Discord
UserCommandProperties props = new UserCommandProperties() UserCommandProperties props = new UserCommandProperties()
{ {
Name = this.Name, Name = this.Name,
DefaultPermission = this.DefaultPermission
}; };


return props; return props;
@@ -64,6 +70,17 @@ namespace Discord
{ {
this.Name = name; this.Name = name;
return this; return this;
}
}

/// <summary>
/// Sets the default permission of the current command.
/// </summary>
/// <param name="value">The default permission value to set.</param>
/// <returns>The current builder.</returns>
public UserCommandBuilder WithDefaultPermission (bool value)
{
this.DefaultPermission = value;
return this;
}
} }
} }

+ 0
- 5
src/Discord.Net.Core/Entities/Interactions/SlashCommandProperties.cs View File

@@ -22,11 +22,6 @@ namespace Discord
/// </summary> /// </summary>
public Optional<List<ApplicationCommandOptionProperties>> Options { get; set; } public Optional<List<ApplicationCommandOptionProperties>> Options { get; set; }


/// <summary>
/// Whether the command is enabled by default when the app is added to a guild. Default is <see langword="true"/>
/// </summary>
public Optional<bool> DefaultPermission { get; set; }

internal SlashCommandProperties() { } internal SlashCommandProperties() { }
} }
} }

+ 18
- 24
src/Discord.Net.Rest/Entities/Interactions/InteractionHelper.cs View File

@@ -68,6 +68,9 @@ namespace Discord.Rest
{ {
Name = arg.Name.Value, Name = arg.Name.Value,
Type = arg.Type, Type = arg.Type,
DefaultPermission = arg.DefaultPermission.IsSpecified
? arg.DefaultPermission.Value
: Optional<bool>.Unspecified
}; };


if (arg is SlashCommandProperties slashProps) if (arg is SlashCommandProperties slashProps)
@@ -79,10 +82,6 @@ namespace Discord.Rest
model.Options = slashProps.Options.IsSpecified model.Options = slashProps.Options.IsSpecified
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified;

model.DefaultPermission = slashProps.DefaultPermission.IsSpecified
? slashProps.DefaultPermission.Value
: Optional<bool>.Unspecified;
} }


return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false); return await client.ApiClient.CreateGlobalApplicationCommandAsync(model, options).ConfigureAwait(false);
@@ -103,6 +102,9 @@ namespace Discord.Rest
{ {
Name = arg.Name.Value, Name = arg.Name.Value,
Type = arg.Type, Type = arg.Type,
DefaultPermission = arg.DefaultPermission.IsSpecified
? arg.DefaultPermission.Value
: Optional<bool>.Unspecified
}; };


if (arg is SlashCommandProperties slashProps) if (arg is SlashCommandProperties slashProps)
@@ -114,10 +116,6 @@ namespace Discord.Rest
model.Options = slashProps.Options.IsSpecified model.Options = slashProps.Options.IsSpecified
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified;

model.DefaultPermission = slashProps.DefaultPermission.IsSpecified
? slashProps.DefaultPermission.Value
: Optional<bool>.Unspecified;
} }


models.Add(model); models.Add(model);
@@ -141,6 +139,9 @@ namespace Discord.Rest
{ {
Name = arg.Name.Value, Name = arg.Name.Value,
Type = arg.Type, Type = arg.Type,
DefaultPermission = arg.DefaultPermission.IsSpecified
? arg.DefaultPermission.Value
: Optional<bool>.Unspecified
}; };


if (arg is SlashCommandProperties slashProps) if (arg is SlashCommandProperties slashProps)
@@ -152,10 +153,6 @@ namespace Discord.Rest
model.Options = slashProps.Options.IsSpecified model.Options = slashProps.Options.IsSpecified
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified;

model.DefaultPermission = slashProps.DefaultPermission.IsSpecified
? slashProps.DefaultPermission.Value
: Optional<bool>.Unspecified;
} }


models.Add(model); models.Add(model);
@@ -202,6 +199,9 @@ namespace Discord.Rest
var model = new Discord.API.Rest.ModifyApplicationCommandParams() var model = new Discord.API.Rest.ModifyApplicationCommandParams()
{ {
Name = args.Name, Name = args.Name,
DefaultPermission = args.DefaultPermission.IsSpecified
? args.DefaultPermission.Value
: Optional<bool>.Unspecified
}; };


if(args is SlashCommandProperties slashProps) if(args is SlashCommandProperties slashProps)
@@ -223,10 +223,6 @@ namespace Discord.Rest
model.Options = slashProps.Options.IsSpecified model.Options = slashProps.Options.IsSpecified
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified;

model.DefaultPermission = slashProps.DefaultPermission.IsSpecified
? slashProps.DefaultPermission.Value
: Optional<bool>.Unspecified;
} }


return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false); return await client.ApiClient.ModifyGlobalApplicationCommandAsync(model, command.Id, options).ConfigureAwait(false);
@@ -257,6 +253,9 @@ namespace Discord.Rest
{ {
Name = arg.Name.Value, Name = arg.Name.Value,
Type = arg.Type, Type = arg.Type,
DefaultPermission = arg.DefaultPermission.IsSpecified
? arg.DefaultPermission.Value
: Optional<bool>.Unspecified
}; };


if (arg is SlashCommandProperties slashProps) if (arg is SlashCommandProperties slashProps)
@@ -268,10 +267,6 @@ namespace Discord.Rest
model.Options = slashProps.Options.IsSpecified model.Options = slashProps.Options.IsSpecified
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified;

model.DefaultPermission = slashProps.DefaultPermission.IsSpecified
? slashProps.DefaultPermission.Value
: Optional<bool>.Unspecified;
} }


return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false); return await client.ApiClient.CreateGuildApplicationCommandAsync(model, guildId, options).ConfigureAwait(false);
@@ -291,6 +286,9 @@ namespace Discord.Rest
var model = new ModifyApplicationCommandParams() var model = new ModifyApplicationCommandParams()
{ {
Name = arg.Name, Name = arg.Name,
DefaultPermission = arg.DefaultPermission.IsSpecified
? arg.DefaultPermission.Value
: Optional<bool>.Unspecified
}; };


if (arg is SlashCommandProperties slashProps) if (arg is SlashCommandProperties slashProps)
@@ -302,10 +300,6 @@ namespace Discord.Rest
model.Options = slashProps.Options.IsSpecified model.Options = slashProps.Options.IsSpecified
? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray() ? slashProps.Options.Value.Select(x => new Discord.API.ApplicationCommandOption(x)).ToArray()
: Optional<Discord.API.ApplicationCommandOption[]>.Unspecified; : Optional<Discord.API.ApplicationCommandOption[]>.Unspecified;

model.DefaultPermission = slashProps.DefaultPermission.IsSpecified
? slashProps.DefaultPermission.Value
: Optional<bool>.Unspecified;
} }


return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false); return await client.ApiClient.ModifyGuildApplicationCommandAsync(model, guildId, command.Id, options).ConfigureAwait(false);


Loading…
Cancel
Save