-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from MariBotOfficial/redesign
[ WIP ] Redesign
- Loading branch information
Showing
134 changed files
with
3,868 additions
and
1,277 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
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
using System; | ||
using MariCommands.Parsers; | ||
using MariCommands.Utils; | ||
|
||
namespace MariCommands | ||
{ | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using MariCommands.Utils; | ||
|
||
namespace MariCommands | ||
{ | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using MariCommands.Utils; | ||
|
||
namespace MariCommands | ||
{ | ||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
using System; | ||
using MariCommands.Utils; | ||
|
||
namespace MariCommands | ||
{ | ||
|
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using MariCommands.Extensions; | ||
using MariCommands.Middlewares; | ||
using MariCommands.Utils; | ||
using MariGlobals.Extensions; | ||
|
||
namespace MariCommands.Builder | ||
{ | ||
/// <inheritdoc /> | ||
public class CommandApplicationBuilder : ICommandApplicationBuilder | ||
{ | ||
private readonly List<Func<CommandDelegate, CommandDelegate>> _components; | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="CommandApplicationBuilder" />. | ||
/// </summary> | ||
/// <param name="properties">The properties of this builder.</param> | ||
/// <param name="applicationServices">The service container for this application.</param> | ||
public CommandApplicationBuilder(IDictionary<string, object> properties, IServiceProvider applicationServices) | ||
{ | ||
_components = new List<Func<CommandDelegate, CommandDelegate>>(); | ||
Properties = properties; | ||
ApplicationServices = applicationServices; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="CommandApplicationBuilder" />. | ||
/// </summary> | ||
/// <param name="applicationServices">The service container for this application.</param> | ||
public CommandApplicationBuilder(IServiceProvider applicationServices) | ||
: this(new Dictionary<string, object>(), applicationServices) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IDictionary<string, object> Properties { get; } | ||
|
||
/// <inheritdoc /> | ||
public IServiceProvider ApplicationServices { get; } | ||
|
||
/// <inheritdoc /> | ||
public ICommandApplicationBuilder Use(Func<CommandDelegate, CommandDelegate> component) | ||
{ | ||
_components.Add(component); | ||
return this; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public CommandDelegate Build() | ||
{ | ||
CommandDelegate app = context => | ||
{ | ||
context.NotNull(nameof(context)); | ||
|
||
if (context.Command.HasNoContent()) | ||
{ | ||
var message = | ||
$"The request reached the end of the pipeline without a command defined." + | ||
$"Please register the {nameof(CommandParserMiddleware)} using '{nameof(ICommandApplicationBuilder)}'.{nameof(MariCommandsApplicationBuilderExtensions.UseParser)}()."; | ||
|
||
throw new InvalidOperationException(message); | ||
} | ||
|
||
if (context.Result.HasNoContent()) | ||
{ | ||
var message = | ||
$"The request reached the end of the pipeline without executing the command: '{context.Command.Name}'." + | ||
$"Please register the {nameof(CommandExecutorMiddleware)} using '{nameof(ICommandApplicationBuilder)}.{nameof(MariCommandsApplicationBuilderExtensions.UseCommandExecutor)}().'"; | ||
|
||
throw new InvalidOperationException(message); | ||
} | ||
|
||
return Task.CompletedTask; | ||
}; | ||
|
||
_components.Reverse(); | ||
|
||
foreach (var component in _components) | ||
app = component(app); | ||
|
||
return app; | ||
} | ||
} | ||
} |
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,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace MariCommands.Builder | ||
{ | ||
/// <summary> | ||
/// Represents a builder that will build the command pipeline request. | ||
/// </summary> | ||
public interface ICommandApplicationBuilder | ||
{ | ||
/// <summary> | ||
/// Properties to be used across middlewares. | ||
/// </summary> | ||
IDictionary<string, object> Properties { get; } | ||
|
||
/// <summary> | ||
/// The general service container for this application. | ||
/// </summary> | ||
IServiceProvider ApplicationServices { get; } | ||
|
||
/// <summary> | ||
/// Add a middleware to the command execution pipeline. | ||
/// </summary> | ||
/// <param name="component">The middleware function to execute the current command request.</param> | ||
/// <returns>The current command application builder.</returns> | ||
ICommandApplicationBuilder Use(Func<CommandDelegate, CommandDelegate> component); | ||
|
||
/// <summary> | ||
/// Build the command execution pipeline. | ||
/// </summary> | ||
/// <returns></returns> | ||
CommandDelegate Build(); | ||
} | ||
} |
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,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace MariCommands.Builder | ||
{ | ||
/// <summary> | ||
/// A configurer for Add Modules. | ||
/// </summary> | ||
public interface IModuleConfigurer | ||
{ | ||
/// <summary> | ||
/// General config for <see cref="ICommandService" /> | ||
/// </summary> | ||
ICommandServiceOptions Options { get; } | ||
|
||
/// <summary> | ||
/// Search all modules in your project and add them to the module cache. | ||
/// </summary> | ||
/// <param name="assembly">The assembly.</param> | ||
IReadOnlyCollection<IModule> AddModules(Assembly assembly); | ||
|
||
/// <summary> | ||
/// Add this module to the module cache. | ||
/// </summary> | ||
/// <param name="module">Any module.</param> | ||
IModule AddModule(IModule module); | ||
|
||
/// <summary> | ||
/// Add this module to the module cache. | ||
/// </summary> | ||
/// <param name="builder">Any module builder.</param> | ||
IModule AddModule(IModuleBuilder builder) | ||
=> AddModule(builder.Build(null)); | ||
|
||
/// <summary> | ||
/// Add this module type to the module cache. | ||
/// </summary> | ||
/// <typeparam ref="T">Any module type.</typeparam> | ||
IModule AddModule<T>() | ||
where T : class | ||
{ | ||
return AddModule(typeof(T)); | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Add this module type to the module cache. | ||
/// </summary> | ||
/// <param name="type">Any module type.</param> | ||
IModule AddModule(Type type); | ||
|
||
/// <summary> | ||
/// Remove this module from the module cache. | ||
/// </summary> | ||
/// <param name="module">The module to be removed.</param> | ||
void RemoveModule(IModule module); | ||
} | ||
} |
Oops, something went wrong.