-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
93 changed files
with
1,043 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using Color_Chan.Discord.Commands; | ||
using Color_Chan.Discord.Commands.Models.Contexts; | ||
using Color_Chan.Discord.Core.Common.Models.Interaction; | ||
using Color_Chan.Discord.Core.Results; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace RoleManager.Pipelines | ||
{ | ||
/// <summary> | ||
/// A pipeline that will measure the performance of the slash commands. | ||
/// </summary> | ||
public class PerformancePipeline : ISlashCommandPipeline | ||
{ | ||
private readonly ILogger<PerformancePipeline> _logger; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="PerformancePipeline" />. | ||
/// </summary> | ||
/// <param name="logger">The logger that will log the performance of the slash commands to the console.</param> | ||
public PerformancePipeline(ILogger<PerformancePipeline> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public async Task<Result<IDiscordInteractionResponse>> HandleAsync(ISlashCommandContext context, SlashCommandHandlerDelegate next) | ||
{ | ||
var sw = new Stopwatch(); | ||
|
||
sw.Start(); | ||
|
||
// Run the command | ||
var result = await next().ConfigureAwait(false); | ||
|
||
sw.Stop(); | ||
|
||
_logger.Log(sw.ElapsedMilliseconds > 500 ? LogLevel.Warning : LogLevel.Information ,"Command {Name} ran for {Time}ms.", context.MethodName, sw.ElapsedMilliseconds.ToString()); | ||
return result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...r-Chan.Discord.Commands/Attributes/ProvidedRequirements/SlashCommandRateLimitAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.