Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
Add busy system for command handler
Browse files Browse the repository at this point in the history
  • Loading branch information
acid-chicken committed Dec 19, 2017
1 parent 4c85d0f commit 8e7e477
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Samurai/Models/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace AcidChicken.Samurai.Models
[JsonObject]
public class Config
{
[JsonProperty("busy")]
public ulong Busy { get; set; } = ulong.MaxValue;

[JsonProperty("default_settings")]
public Dictionary<string, string> DefaultSettings { get; set; } = new Dictionary<string, string>();

Expand Down
30 changes: 26 additions & 4 deletions Samurai/Modules/ModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static class ModuleManager
{
public const string Prefix = "./";

public static ulong Busy;

static ModuleManager()
{
ServiceConfig = new CommandServiceConfig();
Expand Down Expand Up @@ -51,23 +53,43 @@ ref position
var context = new CommandContext(DiscordClient, message);
using (var typing = context.Channel.EnterTypingState())
{
var result = await Service.ExecuteAsync(context, position);
if (!result.IsSuccess)
if (++Busy > ApplicationConfig.Busy)
{
await context.Channel.SendMessageAsync
(
text: context.User.Mention,
embed:
new EmbedBuilder()
.WithTitle("コマンドエラー")
.WithDescription(result.ErrorReason)
.WithTitle("ビジー状態")
.WithDescription("現在Botが混み合っています。時間を空けてから再度お試し下さい。")
.WithCurrentTimestamp()
.WithColor(Colors.Orange)
.WithColor(Colors.Red)
.WithFooter(EmbedManager.CurrentFooter)
.WithAuthor(context.User)
);
}
else
{
var result = await Service.ExecuteAsync(context, position);
if (!result.IsSuccess)
{
await context.Channel.SendMessageAsync
(
text: context.User.Mention,
embed:
new EmbedBuilder()
.WithTitle("コマンドエラー")
.WithDescription(result.ErrorReason)
.WithCurrentTimestamp()
.WithColor(Colors.Red)
.WithFooter(EmbedManager.CurrentFooter)
.WithAuthor(context.User)
);
}
}
}
Busy--;
}
}
}

0 comments on commit 8e7e477

Please sign in to comment.