Esempio n. 1
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>()));
        }
Esempio n. 2
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            SedeAccessor.InvalidateCache();
            var dataData = SedeAccessor.GetTags(chatRoom, roomSettings.Email, roomSettings.Password);

            if (dataData == null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "My attempt to get tag data returned no information. This could be due to the site being down or blocked for me, or a programming error. Try again in a few minutes, or tell the developer if this happens often.");
                return;
            }

            chatRoom.PostReplyOrThrow(incommingChatMessage, "Tag data has been refreshed.");
        }
Esempio n. 3
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            // First, get the number in the command
            var tagsToFetchArgument = GetRegexMatchingObject()
                .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                .Groups[1]
                .Value
                .Parse<int?>();

            int tagsToFetch;

            if (tagsToFetchArgument != null)
            {
                if (tagsToFetchArgument <= 0)
                {
                    chatRoom.PostReplyOrThrow(incommingChatMessage, "I can't fetch zero tags or a negative number of tags! Please use a number between 1 and {0}."
                        .FormatInline(roomSettings.MaxTagsToFetch));
                    return;
                }

                if (tagsToFetchArgument > roomSettings.MaxTagsToFetch)
                {
                    chatRoom.PostReplyOrThrow(incommingChatMessage, "Sorry, that's too many tags for me. Please choose a number between 1 and {0}"
                        .FormatInline(roomSettings.MaxTagsToFetch));
                    return;
                }

                tagsToFetch = tagsToFetchArgument.Value;
            }
            else
            {
                tagsToFetch = roomSettings.DefaultNextTagCount;
            }

            var tags = SedeAccessor.GetTags(chatRoom, roomSettings.Email, roomSettings.Password);

            if (tags == null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "My attempt to get tag data returned no information. This could be due to the site being down or blocked for me, or a programming error. Try again in a few minutes, or tell the developer if this happens often.");
                return;
            }

            var tagString = tags
                .Take(tagsToFetch)
                .Select(x => "[tag:{0}] `{1}`".FormatInline(x.Key, x.Value))
                .ToCSV(", ");

            var message = "The next {0} tags are: {1}".FormatInline(tagsToFetch, tagString);
            chatRoom.PostReplyOrThrow(incommingChatMessage, message);
        }
Esempio n. 4
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            // Get the stats
            var sa = new CloseQueueStatsAccessor();
            var statsMessage = sa.GetOverallQueueStats();

            // Get the next 3 tags
            var tags = SedeAccessor.GetTags(chatRoom, roomSettings.Email, roomSettings.Password);

            if (tags == null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "My attempt to get tag data returned no information. This could be due to the site being down or blocked for me, or a programming error. Try again in a few minutes, or tell the developer if this happens often.");
                return;
            }

            var topTags = tags
                .Take(3)
                .Select(x => "[tag:{0}]".FormatInline(x.Key));

            var combinedTags = topTags.ToCSV(", ");

            var tagsMessage = "The tags to work on are: {0}.".FormatInline(combinedTags);

            chatRoom.PostMessageOrThrow(statsMessage);
            chatRoom.PostMessageOrThrow(tagsMessage);
        }
Esempio n. 5
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);
        }
        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);
        }
        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);
        }
Esempio n. 8
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var success = EndSession(incommingChatMessage, chatRoom, null, roomSettings);

            if (success)
            {
                var message = "The review session has been marked as completed. To set the number of items you reviewed use the command `{0}`"
                    .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<LastSessionEditCount>());
                chatRoom.PostReplyOrThrow(incommingChatMessage, message);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        /// <summary>
        /// Outputs the tag.
        /// </summary>
        /// <param name="incommingChatMessage"></param>
        /// <param name="chatRoom"></param>
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var tags = SedeAccessor.GetTags(chatRoom, roomSettings.Email, roomSettings.Password);

            if (tags == null)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "My attempt to get tag data returned no information. This could be due to the site being down or blocked for me, or a programming error. Try again in a few minutes, or tell the developer if this happens often.");
                return;
            }

            string dataMessage;
            if (tags != null)
            {
                dataMessage = "The current tag is [tag:{0}] with {1} known review items.".FormatInline(tags.First().Key, tags.First().Value);
            }
            else
            {
                dataMessage = "I couldn't find any tags! Either the query is empty or something bad happened.";
            }

            chatRoom.PostReplyOrThrow(incommingChatMessage, dataMessage);
        }
Esempio n. 12
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);
        }
Esempio n. 13
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));
        }
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var itemsReviewed = GetRegexMatchingObject()
                .Match(GetMessageContentsReadyForRegexParsing(incommingChatMessage))
                .Groups[1]
                .Value
                .Parse<int>();

            var sucessful = EndSession(incommingChatMessage, chatRoom, itemsReviewed, roomSettings);

            if (sucessful)
            {
                chatRoom.PostReplyOrThrow(incommingChatMessage, "Thanks for reviewing! To see more information use the command `{0}`."
                    .FormatInline(ChatbotActionRegister.GetChatBotActionUsage<LastSessionStats>()));
            }
        }
Esempio n. 15
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var responsePhrases = new List<string>()
            {
                "I'm alive and kicking!",
                "Still here you guys!",
                "I'm not dead yet!",
                "I feel... happy!",
                "I think I'll go for a walk...",
                "I don't want to go on the cart!",
                "I feel fine.",
            };

            var phrase = responsePhrases.PickRandom();

            chatRoom.PostReplyOrThrow(incommingChatMessage, phrase);
        }
Esempio n. 16
0
        public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
        {
            var runningCommands = RunningChatbotActionsManager.GetRunningChatbotActions();
            var now = DateTimeOffset.Now;

            var tableMessage = runningCommands
                .Select(x => new
                {
                    Command = x.ChatbotActionName,
                    ForUser = "******".FormatInline(x.RunningForUserName, x.RunningForUserId),
                    Started = (now - x.StartTs).ToUserFriendlyString() + " ago",
                })
                .ToStringTable(new[] { "Command", "For User", "Started" },
                    x => x.Command,
                    x => x.ForUser,
                    x => x.Started);

            chatRoom.PostReplyOrThrow(incommingChatMessage, "The following is a list of commands that I'm currently running:");
            chatRoom.PostMessageOrThrow(tableMessage);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
 public override void RunAction(ChatExchangeDotNet.Message incommingChatMessage, ChatExchangeDotNet.Room chatRoom, InstallationSettings roomSettings)
 {
     chatRoom.PostReplyOrThrow(incommingChatMessage, "I'm shutting down...");
 }