Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BrammyS committed Aug 17, 2021
2 parents dac647d + 4469860 commit 5f445a8
Show file tree
Hide file tree
Showing 52 changed files with 195 additions and 186 deletions.
4 changes: 2 additions & 2 deletions samples/HelloWorldButton/Commands/HelloWorldButtonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public async Task<Result<IDiscordInteractionResponse>> InitButtonAsync()
var actionRowBuilder = new ActionRowComponentBuilder()
.WithButton("Hello world", DiscordButtonStyle.Primary, HelloWorldComponent.HelloWorldComponentId);

var responseBuilder = new SlashCommandResponseBuilder()
var responseBuilder = new InteractionResponseBuilder()
.WithContent("hello world button")
.WithComponent(actionRowBuilder.Build());

// Return the response to Discord.
return FromSuccess(responseBuilder.Build());
}
Expand Down
4 changes: 2 additions & 2 deletions samples/HelloWorldButton/Components/HelloWorldComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class HelloWorldComponent : ComponentInteractionModule
public const string HelloWorldComponentId = "hello_world";

/// <summary>
/// Edits a message with a component with the id of <see cref="HelloWorldComponentId"/>.
/// Edits a message with a component with the id of <see cref="HelloWorldComponentId" />.
/// </summary>
[Component(HelloWorldComponentId, DiscordComponentType.Button)]
public async Task<Result<IDiscordInteractionResponse>> HelloWorldButtonAsync()
{
var response = new SlashCommandResponseBuilder()
var response = new InteractionResponseBuilder()
.WithContent("Hello world!")
.EmptyComponents()
.Build(DiscordInteractionResponseType.UpdateMessage);
Expand Down
2 changes: 1 addition & 1 deletion samples/HelloWorldButton/HelloWorldButton.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Color-Chan.Discord\Color-Chan.Discord.csproj" />
<ProjectReference Include="..\..\src\Color-Chan.Discord\Color-Chan.Discord.csproj"/>
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions samples/HelloWorldButton/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public void ConfigureServices(IServiceCollection services)
slashOptions.EnableAutoSync = true;
slashOptions.SendDefaultErrorMessage = true;
},
ComponentInteractionConfig = componentOptions =>
{
componentOptions.SendDefaultErrorMessage = true;
}
ComponentInteractionConfig = componentOptions => { componentOptions.SendDefaultErrorMessage = true; }
};

// Replace the arguments with the data of your bot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class ComponentAttribute : Attribute
/// from turning inactive after 3 seconds.
/// </param>
/// <param name="editOriginalMessage">
/// Whether or not the original message of the component should be edited with the returned response. Ignored if <paramref name="acknowledge"/> is set to false.
/// Whether or not the original message of the component should be edited with the returned response. Ignored if
/// <paramref name="acknowledge" /> is set to false.
/// </param>
public ComponentAttribute(string customId, DiscordComponentType type, bool acknowledge = false, bool editOriginalMessage = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override Task<Result> CheckRequirementAsync(IInteractionContext context,
return Task.FromResult(Result.FromSuccess());
}

return Task.FromResult(Result.FromError(new SlashCommandRequireDmErrorResult("Interaction can not be executed in a guild")));
return Task.FromResult(Result.FromError(new RequireDmErrorResult("Interaction can not be executed in a guild")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace Color_Chan.Discord.Commands.Attributes.ProvidedRequirements
/// This requirement will limit the amount of time a user can request interactions during a time period.
/// </remarks>
/// <example>
/// This example limits all the interaction commands in the PongCommands interaction command module to 2 requests every 10 seconds
/// This example limits all the interaction commands in the PongCommands interaction command module to 2 requests every
/// 10 seconds
/// and 4 requests every 30 seconds per user. You can also put the <see cref="UserRateLimitAttribute" /> on
/// a method if
/// you only want to rate limit a specific interaction.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Color-Chan.Discord.Caching\Color-Chan.Discord.Caching.csproj" />
<ProjectReference Include="..\Color-Chan.Discord.Core\Color-Chan.Discord.Core.csproj" />
<ProjectReference Include="..\Color-Chan.Discord.Rest\Color-Chan.Discord.Rest.csproj" />
<ProjectReference Include="..\Color-Chan.Discord.Caching\Color-Chan.Discord.Caching.csproj"/>
<ProjectReference Include="..\Color-Chan.Discord.Core\Color-Chan.Discord.Core.csproj"/>
<ProjectReference Include="..\Color-Chan.Discord.Rest\Color-Chan.Discord.Rest.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Sodium.Core" Version="1.2.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Sodium.Core" Version="1.2.3"/>
</ItemGroup>

<PropertyGroup>
Expand Down Expand Up @@ -53,7 +53,7 @@
</PropertyGroup>

<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
<SourceRoot Include="$(MSBuildThisFileDirectory)/"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ComponentInteractionConfiguration
/// unsuccessfully. Default: false.
/// </summary>
public bool SendDefaultErrorMessage { get; set; }

/// <summary>
/// Whether or not <see cref="IInteractionContext.Guild" /> should be auto loaded on command requests. Default: false.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class SlashCommandConfiguration
/// Whether or not the slash commands auto sync feature is enabled. Default: true.
/// </summary>
public bool EnableAutoSync { get; set; } = true;


/// <summary>
/// Whether or not <see cref="IInteractionContext.Guild" /> should be auto loaded on command requests. Default: false.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Color_Chan.Discord.Commands.Exceptions
{
/// <summary>
/// An exception that should be thrown when a component interaction failed to execute and has not properly been handled.
/// An exception that should be thrown when a component interaction failed to execute and has not properly been
/// handled.
/// </summary>
public class ComponentInteractionResultException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static IServiceCollection AddColorChanDiscordCommand(this IServiceCollect
services.TryAddTransient<ISlashCommandAutoSyncService, SlashCommandAutoSyncService>();
services.TryAddTransient<ISlashCommandBuildService, SlashCommandBuildService>();
services.TryAddTransient<IDiscordSlashCommandHandler, DiscordSlashCommandHandler>();

services.TryAddTransient<IComponentInteractionHandler, ComponentInteractionHandler>();
services.TryAddTransient<IComponentBuildService, ComponentBuildService>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Color_Chan.Discord.Commands.MessageBuilders
/// <summary>
/// Represents a builder class for creating <see cref="IDiscordInteractionResponse" />s.
/// </summary>
public class SlashCommandResponseBuilder
public class InteractionResponseBuilder
{
private const int MaxEmbeds = 10;

Expand Down Expand Up @@ -50,9 +50,9 @@ public class SlashCommandResponseBuilder
/// Enables Text To Speech for the response.
/// </summary>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
public SlashCommandResponseBuilder EnableTts()
public InteractionResponseBuilder EnableTts()
{
_isTts = true;
return this;
Expand All @@ -62,7 +62,7 @@ public SlashCommandResponseBuilder EnableTts()
/// Makes the response only visible to the person that has used the slash command.
/// </summary>
/// <returns></returns>
public SlashCommandResponseBuilder MakePrivate()
public InteractionResponseBuilder MakePrivate()
{
_flags = DiscordInteractionCallbackFlags.Ephemeral;
return this;
Expand All @@ -73,9 +73,9 @@ public SlashCommandResponseBuilder MakePrivate()
/// </summary>
/// <param name="content">The content.</param>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
public SlashCommandResponseBuilder WithContent(string content)
public InteractionResponseBuilder WithContent(string content)
{
_content = content;
return this;
Expand All @@ -86,10 +86,10 @@ public SlashCommandResponseBuilder WithContent(string content)
/// </summary>
/// <param name="embed">The embed that will be added.</param>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the max embed limit of 10 has been reached.</exception>
public SlashCommandResponseBuilder WithEmbed(IDiscordEmbed embed)
public InteractionResponseBuilder WithEmbed(IDiscordEmbed embed)
{
_embeds ??= new List<IDiscordEmbed>();

Expand All @@ -104,9 +104,9 @@ public SlashCommandResponseBuilder WithEmbed(IDiscordEmbed embed)
/// </summary>
/// <param name="allowedMentions">The allowed mentions.</param>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
public SlashCommandResponseBuilder WithAllowedMentions(IDiscordAllowedMentions allowedMentions)
public InteractionResponseBuilder WithAllowedMentions(IDiscordAllowedMentions allowedMentions)
{
_allowedMentions = allowedMentions;
return this;
Expand All @@ -117,10 +117,10 @@ public SlashCommandResponseBuilder WithAllowedMentions(IDiscordAllowedMentions a
/// </summary>
/// <param name="component">The new component.</param>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown when the max component limit of 5 has been reached.</exception>
public SlashCommandResponseBuilder WithComponent(IDiscordComponent component)
public InteractionResponseBuilder WithComponent(IDiscordComponent component)
{
_components ??= new List<IDiscordComponent>();

Expand All @@ -129,26 +129,26 @@ public SlashCommandResponseBuilder WithComponent(IDiscordComponent component)
_components.Add(component);
return this;
}

/// <summary>
/// Sets the <see cref="_components"/> to an empty list of <see cref="IDiscordComponent"/>s.
/// Sets the <see cref="_components" /> to an empty list of <see cref="IDiscordComponent" />s.
/// </summary>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
public SlashCommandResponseBuilder EmptyComponents()
public InteractionResponseBuilder EmptyComponents()
{
_components = new List<IDiscordComponent>();
return this;
}

/// <summary>
/// Sets the <see cref="_embeds"/> to an empty list of <see cref="IDiscordEmbed"/>s.
/// Sets the <see cref="_embeds" /> to an empty list of <see cref="IDiscordEmbed" />s.
/// </summary>
/// <returns>
/// The updated <see cref="SlashCommandResponseBuilder" />.
/// The updated <see cref="InteractionResponseBuilder" />.
/// </returns>
public SlashCommandResponseBuilder EmptyEmbeds()
public InteractionResponseBuilder EmptyEmbeds()
{
_embeds = new List<IDiscordEmbed>();
return this;
Expand Down Expand Up @@ -191,7 +191,7 @@ internal IDiscordInteractionResponse DefaultErrorMessage()
.WithTimeStamp();

// Build the response with the embed.
var errorResponse = new SlashCommandResponseBuilder()
var errorResponse = new InteractionResponseBuilder()
.WithEmbed(errorEmbedBuilder.Build())
.MakePrivate()
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public interface IInteractionContext
/// The interaction id.
/// </summary>
ulong InteractionId { get; init; }

/// <summary>
/// The method name of the method that will handle the interaction request.
/// </summary>
/// <remarks>
/// Used to create a unique string for rate limiting.
/// </remarks>
string? MethodName { get; set; }

/// <summary>
/// The guild the interaction was used in.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class InteractionContext : IInteractionContext

/// <inheritdoc />
public string? MethodName { get; set; }

/// <inheritdoc />
public IDiscordGuild? Guild { get; init; }

Expand Down
11 changes: 7 additions & 4 deletions src/Color-Chan.Discord.Commands/Models/Info/ComponentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public class ComponentInfo : IComponentInfo
/// Whether or not the component interaction should be automatically acknowledge to prevent the token
/// from turning inactive after 3 seconds.
/// </param>
/// <param name="editOriginalMessage">Whether or not the original message of the component should be edited with the returned response.</param>
/// <param name="editOriginalMessage">
/// Whether or not the original message of the component should be edited with the
/// returned response.
/// </param>
public ComponentInfo(string customId, DiscordComponentType type, MethodInfo componentMethod, TypeInfo parentModule, bool acknowledge, bool editOriginalMessage)
{
CustomId = customId;
Expand All @@ -41,13 +44,13 @@ public ComponentInfo(string customId, DiscordComponentType type, MethodInfo comp

/// <inheritdoc />
public TypeInfo ParentModule { get; set; }

/// <inheritdoc />
public IEnumerable<InteractionRequirementAttribute>? Requirements { get; set; }

/// <inheritdoc />
public bool Acknowledge { get; }

/// <inheritdoc />
public bool EditOriginalMessage { get; }
}
Expand Down
6 changes: 3 additions & 3 deletions src/Color-Chan.Discord.Commands/Models/Info/IComponentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public interface IComponentInfo
/// The component module containing the <see cref="ComponentMethod" />.
/// </summary>
public TypeInfo ParentModule { get; set; }

/// <summary>
/// A <see cref="IEnumerable{T}" /> of <see cref="InteractionRequirementAttribute" />s containing all the requirements
/// to execute the component.
/// </summary>
public IEnumerable<InteractionRequirementAttribute>? Requirements { get; set; }

/// <summary>
/// Whether or not the component interaction should be automatically acknowledge to prevent the token
/// from turning inactive after 3 seconds.
/// </summary>
public bool Acknowledge { get; }

/// <summary>
/// Whether or not the original message of the component should be edited with the returned response.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface ISlashCommandInfo
/// from turning inactive after 3 seconds.
/// </summary>
public bool Acknowledge { get; }

/// <summary>
/// A <see cref="IEnumerable{T}" /> of <see cref="SlashCommandGuildAttribute" /> containing the IDs of the guilds that
/// will get access to this slash command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public interface ISlashCommandOptionInfo
/// from turning inactive after 3 seconds.
/// </summary>
public bool Acknowledge { get; }

/// <summary>
/// A <see cref="IEnumerable{T}" /> of <see cref="SlashCommandGuildAttribute" /> containing the IDs of the guilds that
/// will get access to this slash command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public SlashCommandOptionInfo(string name, string description, bool acknowledge,

/// <inheritdoc />
public bool Acknowledge { get; }

/// <inheritdoc />
public IEnumerable<SlashCommandGuildAttribute>? Guilds { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Color_Chan.Discord.Commands.Models.Results
/// <summary>
/// An error result describing a slash command rate limit.
/// </summary>
public record BaseRateLimitErrorResult : SlashCommandRequirementErrorResult
public record BaseRateLimitErrorResult : InteractionRequirementErrorResult
{
/// <summary>
/// Initializes a new instance of <see cref="BaseRateLimitErrorResult" />.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ namespace Color_Chan.Discord.Commands.Models.Results
/// <summary>
/// An error result describing an error thrown by a <see cref="InteractionRequirementAttribute" />.
/// </summary>
public record SlashCommandRequirementErrorResult : ErrorResult
public record InteractionRequirementErrorResult : ErrorResult
{
/// <summary>
/// Initializes a new instance of <see cref="SlashCommandRequirementErrorResult" />.
/// Initializes a new instance of <see cref="InteractionRequirementErrorResult" />.
/// </summary>
/// <param name="errorMessage">The message of the error.</param>
public SlashCommandRequirementErrorResult(string errorMessage) : base(errorMessage)
public InteractionRequirementErrorResult(string errorMessage) : base(errorMessage)
{
}
}
Expand Down
Loading

0 comments on commit 5f445a8

Please sign in to comment.