public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings) { var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString); var lastFinishedSession = da.GetLatestCompletedSession(incommingChatMessage.Author.ID); if (lastFinishedSession == null) { chatRoom.PostReplyOrThrow(incommingChatMessage, "You have no completed review sessions on record, so I can't give you any stats."); return; } var sessionEndedTimeAgo = (DateTimeOffset.Now - lastFinishedSession.SessionEnd.Value); var sessionLength = lastFinishedSession.SessionEnd.Value - lastFinishedSession.SessionStart; var statMessage = "Your last completed review session ended {0} ago and lasted {1}. "; if (lastFinishedSession.ItemsReviewed == null) { statMessage += "However, the number of reviewed items has not been set. Use the command `{0}` to set the new value." .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<LastSessionEditCount>()); statMessage = statMessage.FormatSafely( sessionEndedTimeAgo.ToUserFriendlyString(), sessionLength.ToUserFriendlyString()); } else { TimeSpan averageTimePerReview; var itemsReviewed = lastFinishedSession.ItemsReviewed.Value; if (itemsReviewed != 0) { averageTimePerReview = new TimeSpan(sessionLength.Ticks / (itemsReviewed)); } else { averageTimePerReview = new TimeSpan(0); } statMessage += "You reviewed {2} items, averaging a review every {3}."; statMessage = statMessage.FormatSafely( sessionEndedTimeAgo.ToUserFriendlyString(), sessionLength.ToUserFriendlyString(), lastFinishedSession.ItemsReviewed.Value, averageTimePerReview.ToUserFriendlyString()); } // Check if there is a on-going review session. var ongoingSessionStartTs = da.GetCurrentSessionStartTs(incommingChatMessage.Author.ID); if (ongoingSessionStartTs != null) { var deltaTime = DateTimeOffset.Now - ongoingSessionStartTs.Value; statMessage += " **Note: You still have a review session in progress.** It started {0} ago.".FormatInline(deltaTime.ToUserFriendlyString()); } chatRoom.PostReplyOrThrow(incommingChatMessage, statMessage); }
public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings) { var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString); var lastSession = da.GetLatestCompletedSession(incommingChatMessage.Author.ID); if (lastSession == null) { chatRoom.PostReplyOrThrow(incommingChatMessage, "You have no completed review sessions on record, so I can't edit any entries."); return; } var newReviewCount = GetRegexMatchingObject() .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage)) .Groups[1] .Value .Parse<int>(); if (newReviewCount < 0) { chatRoom.PostReplyOrThrow(incommingChatMessage, "New review count cannot be negative."); return; } var previousReviewCount = lastSession.ItemsReviewed; lastSession.ItemsReviewed = newReviewCount; var replyMessage = @" Review item count has been changed: User: {0} ({1}) Start Time: {2} End Time: {3} Items Reviewed: {4} -> {5} Use the command 'last session stats' to see more details." .FormatInline( incommingChatMessage.Author.Name, incommingChatMessage.Author.ID, lastSession.SessionStart.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss 'UTC'"), lastSession.SessionEnd.Value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss 'UTC'"), previousReviewCount.HasValue ? previousReviewCount.Value.ToString() : "[Not Set]", lastSession.ItemsReviewed.Value); da.EditLatestCompletedSessionItemsReviewedCount(lastSession.Id, newReviewCount); chatRoom.PostReplyOrThrow(incommingChatMessage, replyMessage); }