-
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 #3 from approvers/feature/rinia/silent/001
Silent: 一定時間黙らせるコマンドの実装
- Loading branch information
Showing
9 changed files
with
120 additions
and
4 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
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,23 @@ | ||
namespace Approvers.King.Common; | ||
|
||
public static class SilentManager | ||
{ | ||
private static readonly Dictionary<ulong, DateTime> SilentUsers = new(); | ||
|
||
/// <summary> | ||
/// 一定時間黙らせる | ||
/// </summary> | ||
public static void SetSilent(ulong userId, TimeSpan timeSpan) | ||
{ | ||
var expireTime = TimeManager.GetNow() + timeSpan; | ||
SilentUsers[userId] = expireTime; | ||
} | ||
|
||
/// <summary> | ||
/// 黙っている最中か | ||
/// </summary> | ||
public static bool IsSilent(ulong userId) | ||
{ | ||
return SilentUsers.TryGetValue(userId, out var expireTime) && !TimeManager.IsExpired(expireTime); | ||
} | ||
} |
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 @@ | ||
namespace Approvers.King.Common; | ||
|
||
public static class TimeManager | ||
{ | ||
/// <summary> | ||
/// アプリ内の現在時刻を取得する | ||
/// デバッグ機能により操作されることがある | ||
/// </summary> | ||
public static DateTime GetNow() | ||
{ | ||
return DateTime.Now.ToLocalTime(); | ||
} | ||
|
||
/// <summary> | ||
/// 過ぎていればtrue | ||
/// </summary> | ||
public static bool IsExpired(DateTime time) | ||
{ | ||
return GetNow() > time; | ||
} | ||
} |
File renamed without changes.
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 @@ | ||
using Approvers.King.Common; | ||
using Discord; | ||
|
||
namespace Approvers.King.Events; | ||
|
||
public class SilentCommandPresenter : DiscordMessagePresenterBase | ||
{ | ||
protected override async Task MainAsync() | ||
{ | ||
SilentManager.SetSilent(Message.Author.Id, MasterManager.SilentTimeSpan); | ||
var message = string.Format( | ||
MasterManager.SilentCommandReplyMessage, | ||
MentionUtils.MentionUser(Message.Author.Id)); | ||
await Message.ReplyAsync(message); | ||
} | ||
} |
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