-
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 #1 from approvers/feature/rinia/rare_reply/001_delay
RareReply: 人間味を持たせる
- Loading branch information
Showing
5 changed files
with
54 additions
and
35 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,16 @@ | ||
namespace Approvers.King.Common; | ||
|
||
public static class RandomUtility | ||
{ | ||
private static readonly Random Random = new(); | ||
|
||
public static float GetRandomFloat(float max) | ||
{ | ||
return GetRandomFloat(0f, max); | ||
} | ||
|
||
public static float GetRandomFloat(float min, float max) | ||
{ | ||
return (float)(min + (max - min) * Random.NextDouble()); | ||
} | ||
} |
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,34 @@ | ||
using Approvers.King.Common; | ||
using Discord; | ||
|
||
namespace Approvers.King.Events; | ||
|
||
public class RareReplyPresenter : DiscordMessagePresenterBase | ||
{ | ||
protected override async Task MainAsync() | ||
{ | ||
if (RandomUtility.GetRandomFloat(1f) > MasterManager.ReplyRate) return; | ||
|
||
await Task.Delay(TimeSpan.FromSeconds(RandomUtility.GetRandomFloat(MasterManager.ReplyMaxDelay))); | ||
using (Message.Channel.EnterTypingState()) | ||
{ | ||
await Task.Delay(TimeSpan.FromSeconds(RandomUtility.GetRandomFloat(MasterManager.TypingMaxDelay))); | ||
await Message.ReplyAsync(PickRandomMessage()); | ||
} | ||
} | ||
|
||
private static string PickRandomMessage() | ||
{ | ||
var totalRate = MasterManager.ReplyMessages.Sum(x => x.rate); | ||
var value = RandomUtility.GetRandomFloat(totalRate); | ||
|
||
foreach (var (rate, message) in MasterManager.ReplyMessages) | ||
{ | ||
if (value < rate) return message; | ||
|
||
value -= rate; | ||
} | ||
|
||
return MasterManager.ReplyMessages[^1].message; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.