From 33a4847a9cc580f84d4d5f9aefd1955015efbcc9 Mon Sep 17 00:00:00 2001 From: watano1168 Date: Mon, 15 Jan 2024 01:17:42 +0900 Subject: [PATCH] =?UTF-8?q?Gacha:=2010=E9=80=A3=E3=82=AC=E3=83=81=E3=83=A3?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/MasterManager.cs | 7 +++++++ Common/RandomUtility.cs | 5 +++++ Events/GachaCommandPresenter.cs | 30 ++++++++++++++++++++++++++++++ Events/RareReplyPresenter.cs | 2 +- Triggers/DiscordTrigger.cs | 7 +++++++ 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Events/GachaCommandPresenter.cs 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;