-
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 #2 from approvers/feature/rinia/interact/001
Interact: メンションされたら返信する機能を実装
- Loading branch information
Showing
4 changed files
with
46 additions
and
16 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,17 @@ | ||
using Approvers.King.Common; | ||
using Discord; | ||
|
||
namespace Approvers.King.Events; | ||
|
||
public class InteractReplyPresenter : DiscordMessagePresenterBase | ||
{ | ||
protected override async Task MainAsync() | ||
{ | ||
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(MessageUtility.PickRandomMessage()); | ||
} | ||
} | ||
} |
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,21 @@ | ||
using Approvers.King.Common; | ||
|
||
namespace Approvers.King.Events; | ||
|
||
public static class MessageUtility | ||
{ | ||
public 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; | ||
} | ||
} |