diff --git a/Common/MasterManager.cs b/Common/MasterManager.cs index 88e2efe..ef8e629 100644 --- a/Common/MasterManager.cs +++ b/Common/MasterManager.cs @@ -43,4 +43,11 @@ public static class MasterManager }; public static TimeSpan SilentTimeSpan => TimeSpan.FromMinutes(5); + + public static IReadOnlyList GachaTriggerMessages => new List + { + "10連", + "ガチャ", + "おみくじ", + }; } \ No newline at end of file diff --git a/Common/RandomUtility.cs b/Common/RandomUtility.cs index 60264d3..1cd8f0d 100644 --- a/Common/RandomUtility.cs +++ b/Common/RandomUtility.cs @@ -13,4 +13,9 @@ public static float GetRandomFloat(float min, float max) { return (float)(min + (max - min) * Random.NextDouble()); } + + public static bool IsHit(float probability) + { + return GetRandomFloat(1f) <= probability; + } } \ No newline at end of file diff --git a/Events/GachaCommandPresenter.cs b/Events/GachaCommandPresenter.cs new file mode 100644 index 0000000..5a46600 --- /dev/null +++ b/Events/GachaCommandPresenter.cs @@ -0,0 +1,30 @@ +using System.Text; +using Approvers.King.Common; +using Discord; + +namespace Approvers.King.Events; + +public class GachaCommandPresenter : DiscordMessagePresenterBase +{ + private const int PickCount = 10; + + protected override async Task MainAsync() + { + var results = Enumerable.Range(0, PickCount).Select(_ => Pick()); + + var builder = new StringBuilder(); + builder.AppendLine($"↓↓↓ いっそう{PickCount}連おみくじ ↓↓↓"); + foreach (var result in results) + { + builder.AppendLine(result != null ? Discord.Format.Bold($"・{result}") : Discord.Format.Code("x")); + } + + await Message.ReplyAsync(builder.ToString()); + } + + private static string? Pick() + { + if (RandomUtility.IsHit(MasterManager.ReplyRate) == false) return null; + return MessageUtility.PickRandomMessage(); + } +} \ No newline at end of file diff --git a/Events/RareReplyPresenter.cs b/Events/RareReplyPresenter.cs index 8713cfd..32e86ed 100644 --- a/Events/RareReplyPresenter.cs +++ b/Events/RareReplyPresenter.cs @@ -8,7 +8,7 @@ public class RareReplyPresenter : DiscordMessagePresenterBase protected override async Task MainAsync() { if (SilentManager.IsSilent(Message.Author.Id) || - RandomUtility.GetRandomFloat(1f) > MasterManager.ReplyRate) return; + RandomUtility.IsHit(MasterManager.ReplyRate) == false) return; await Task.Delay(TimeSpan.FromSeconds(RandomUtility.GetRandomFloat(MasterManager.ReplyMaxDelay))); using (Message.Channel.EnterTypingState()) diff --git a/Triggers/DiscordTrigger.cs b/Triggers/DiscordTrigger.cs index 157821f..e641020 100644 --- a/Triggers/DiscordTrigger.cs +++ b/Triggers/DiscordTrigger.cs @@ -25,6 +25,13 @@ private static async Task OnMessageReceived(SocketMessage message) return; } + if (MasterManager.GachaTriggerMessages.Any(userMessage.Content.Contains)) + { + // 10連ガチャ + await DiscordManager.ExecuteAsync(userMessage); + return; + } + // 返信 await DiscordManager.ExecuteAsync(userMessage); return;