示例#1
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);

            var recipientChatProfileIds = da.GetPingReviewersRecipientList(incommingChatMessage.Author.ID, roomSettings.PingReviewersDaysBackThreshold);

            if (!recipientChatProfileIds.Any())
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "No one has a completed review session in the last {0} days"
                    .FormatInline(roomSettings.PingReviewersDaysBackThreshold));
                return;
            }

            var userNames = recipientChatProfileIds
                .Select(x => chatRoom.GetUser(x).Name)
                .Select(x => "@" + x.Replace(" ", ""));

            var combinedUserNames = userNames.ToCSV(" ");

            var messageFromIncommingChatMessage = GetRegexMatchingObject()
                .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                .Groups[1]
                .Value;

            var outboundMessage = "{0} {1}".FormatInline(messageFromIncommingChatMessage, combinedUserNames);
            chatRoom.PostMessageOrThrow(outboundMessage);
        }
示例#2
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);

            var latestSession = da.GetLatestSessionForUser(incommingChatMessage.Author.ID);

            if (latestSession == null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "I don't have any review session for you on record. Use the `{0}` command to tell me you are starting a review session."
                    .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<StartingSession>()));
                return;
            }

            if (latestSession.SessionEnd != null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "Your latest review session has already been completed. Use the command `{0}` to see more information."
                    .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<LastSessionStats>()));
                return;
            }

            // Else, lastestSession is open.

            da.SetSessionEndTs(latestSession.Id, DateTimeOffset.Now);

            chatRoom.PostReplyOrThrow(incommingChatMessage, "I have forcefully ended your last session. To see more details use the command `{0}`. "
                .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<LastSessionStats>()) +
                "In addition, the number of review items is most likely not set, use the command `{0}` to fix that."
                .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<LastSessionEditCount>()));
        }
        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);
        }
示例#4
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var chatUser = chatRoom.GetUser(incommingChatMessage.Author.ID);
            var tagName = GetRegexMatchingObject()
                    .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                    .Groups[1]
                    .Value;

            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);
            da.InsertCompletedAuditEntry(incommingChatMessage.Author.ID, tagName);
        }
示例#5
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var thresholdInCommand =  GetRegexMatchingObject()
                .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                .Groups[1]
                .Value
                .Parse<int?>();

            if (thresholdInCommand != null && thresholdInCommand <= 0)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "Minimum person threshold must be greater or equal to 1.");
                return;
            }

            var defaultThreshold = roomSettings.DefaultCompletedTagsPeopleThreshold;

            var peopleThreshold = thresholdInCommand ?? defaultThreshold; // Take the one in the command, or the default if the command one is not given.
            var usingDefault = thresholdInCommand == null;

            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);
            var completedTagsData = da.GetCompletedTags(peopleThreshold, 10); //10 is hard coded for now, could be changed later

            var headerMessage = "Showing the latest 10 tags that have been cleared by at least {0} {1}."
                .FormatInline(peopleThreshold, peopleThreshold != 1 ? "people" : "person");

            if (usingDefault)
            {
                headerMessage += " To give a different threshold number, use the command `{0}`."
                    .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<CompletedTags>());
            }

            string dataMessage;

            if (completedTagsData.Any())
            {
                dataMessage = completedTagsData
                    .ToStringTable(new[] { "Tag Name", "Count", "Latest Time Cleared" },
                        (x) => x.TagName,
                        (x) => x.PeopleWhoCompletedTag,
                        (x) => x.LastEntryTs.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss 'UTC'"));
            }
            else
            {
                dataMessage = "    There are no entries that match that request!";
            }

            chatRoom.PostReplyOrThrow(incommingChatMessage, headerMessage);
            chatRoom.PostMessageOrThrow(dataMessage);
        }
        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);
        }
示例#7
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);
            var currentSessionStartTs = da.GetCurrentSessionStartTs(incommingChatMessage.Author.ID);

            if (currentSessionStartTs == null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "You don't have an ongoing review session on record.");
            }
            else
            {
                var deltaTimeSpan = DateTimeOffset.Now - currentSessionStartTs.Value;
                var formattedStartTs = currentSessionStartTs.Value.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss 'UTC'");

                var message = "Your current review session started {0} ago at {1}"
                    .FormatInline(deltaTimeSpan.ToUserFriendlyString(), formattedStartTs);

                chatRoom.PostReplyOrThrow(incommingChatMessage, message);
            }
        }
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var chatUser = chatRoom.GetUser(incommingChatMessage.Author.ID);

            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);

            // first, check if the user has any open sessions, and close them
            int numberOfClosedSessions = da.EndAnyOpenSessions(incommingChatMessage.Author.ID);

            // now record the new session
            da.StartReviewSession(incommingChatMessage.Author.ID);

            var replyMessages = new List<string>()
            {
                "Good luck!",
                "Happy reviewing!",
                "Don't get lost in the queue!",
                "Watch out for audits!",
                "May the Vote be with you!",
                "May Shog9's Will be done.",
                "By the power of the Vote! Review!"
            };

            var outMessage = replyMessages.PickRandom();

            if (numberOfClosedSessions > 0) //if there was a closed session
            {
                //append a message saying how many there were

                outMessage += " **Note:** You had {0} open {1}. I have closed {2}.".FormatInline(
                    numberOfClosedSessions,
                    numberOfClosedSessions > 1
                        ? "sessions"
                        : "session",
                    numberOfClosedSessions > 1
                        ? "them"
                        : "it");
            }

            chatRoom.PostReplyOrThrow(incommingChatMessage, outMessage);
        }
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);
            var completedTags = da.GetUserCompletedTags(incommingChatMessage.Author.ID);

            if (!completedTags.Any())
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "I don't have any completed tags by you on record. When you run out of items in your filter paste the message into chat here and I'll record it.");
                return;
            }

            var headerMessage = "Showing all tags cleared by you that I have on record:";
            var dataMessage = completedTags
                .ToStringTable(new string[] { "Tag Name", "Times Cleared", "Last Cleared" },
                    x => x.TagName,
                    x => x.TimesCleared,
                    x => x.LastTimeCleared.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss 'UTC'"));

            chatRoom.PostReplyOrThrow(incommingChatMessage, headerMessage);
            chatRoom.PostMessageOrThrow(dataMessage);
        }
示例#10
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            // First, get the tags that were used.
            string tags = GetRegexMatchingObject()
                    .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                    .Groups[1]
                    .Value;

            // Split out tags.
            var tagMatchingPattern = new Regex(@"\[(\S+?)\] ?", RegexOptions.CultureInvariant);
            var parsedTagNames = tagMatchingPattern.Matches(incommingChatMessage.Content.ToLower())
                .Cast<Match>()
                .Select(x => x.Groups[1].Value)
                .ToList();

            var da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);

            // Save the tags to the database.
            foreach (var tagName in parsedTagNames)
            {
                da.InsertNoItemsInFilterRecord(incommingChatMessage.Author.ID, tagName);
            }
        }
示例#11
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var userIdToAdd = GetRegexMatchingObject()
                .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                .Groups[1]
                .Value
                .Parse<int>();

            DatabaseAccessor da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);

            var existingUser = da.GetRegisteredUserByChatProfileId(userIdToAdd);

            if (existingUser != null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "That user is already in the system!");
                return;
            }

            da.AddUserToRegisteredUsersList(userIdToAdd);

            var chatUser = chatRoom.GetUser(userIdToAdd);
            chatRoom.PostReplyOrThrow(incommingChatMessage, "Ok, I added {0} ({1}) to the tracked users list."
                .FormatInline(chatUser.Name, chatUser.ID));
        }
        /// <summary>
        /// Records the end of a review session for a user. Returns true if the session was successfully marked as finished.
        /// </summary>
        /// <param name="userMessage"></param>
        /// <param name="chatRoom"></param>
        /// <param name="itemsReviewed"></param>
        /// <returns></returns>
        protected bool EndSession(Message userMessage, Room chatRoom, int? itemsReviewed, InstallationSettings settings)
        {
            var da = new DatabaseAccessor(settings.DatabaseConnectionString);

            // Find the latest session by that user.
            var latestSession = da.GetLatestOpenSessionForUser(userMessage.Author.ID);

            // First, check if there is a session.
            if (latestSession == null)
            {
                chatRoom.PostReplyOrThrow(userMessage, "I don't seem to have the start of your review session on record. I might have not been running when you started, or some error happened.");
                return false;
            }

            // Check if session is greater than [MAX_REVIEW_TIME].
            var maxReviewTimeHours = settings.MaxReviewLengthHours;

            var timeThreshold = DateTimeOffset.Now.AddHours(-maxReviewTimeHours);

            if (latestSession.SessionStart < timeThreshold)
            {
                var timeDelta = DateTimeOffset.Now - latestSession.SessionStart;

                var message = "Your last uncompleted review session was {0} ago. Because it has exceeded my threshold ({1} hours), I can't mark that session with this information. "
                    .FormatInline(timeDelta.ToUserFriendlyString(), maxReviewTimeHours) +
                    "Use the command '{0}' to forcefully end that session."
                    .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<EndSession>());

                chatRoom.PostReplyOrThrow(userMessage, message);
                return false;
            }

            // It's all good, mark the info as done.
            da.EndReviewSession(latestSession.Id, itemsReviewed);
            return true;
        }
 public ChatMessageProcessor(InstallationSettings settings)
 {
     roomSettings = settings;
     da = new DatabaseAccessor(roomSettings.DatabaseConnectionString);
 }