예제 #1
0
        public MessageResult ProcessMessage(Message message)
        {
            string noteText;
            string ignored;
            string noteId;

            if (m_CommandParser.TryGetCommand(message, "note", out noteText))
            {
                if (String.IsNullOrWhiteSpace(noteText))
                {
                    return(Usage(message));
                }
                var note = m_NoteApi.AddNote(message.User, noteText);
                return(Response.ToMessage(message, FormatNoteStoredResponse(note)));
            }
            if (m_CommandParser.TryGetCommand(message, "notes", out ignored))
            {
                var notes = m_NoteApi.GetNotes(message.User);
                return(Response.ToMessage(message, FormateNoteListResponse(notes.ToList())));
            }
            if (m_CommandParser.TryGetCommand(message, "delete note", out noteId))
            {
                m_NoteApi.RemoveNote(message.User, noteId);
                return(Response.ToMessage(message, "note " + noteId + " deleted"));
            }
            return(MessageResult.Empty);
        }
예제 #2
0
        public MessageResult ProcessMessage(Message message)
        {
            string toTrack, toUntrack;
            Match  idMatch;

            if (m_CommandParser.TryGetCommand(message, "track", out toTrack) && s_ZendeskIdRegex.TryMatch(toTrack, out idMatch))
            {
                var ticket = m_ZendeskApi.FromId(idMatch.Group("id")).Result;
                m_Persistence.AddToList(new Tracked <ZendeskTicket>(ticket, message.Channel));
                return(Response.ToMessage(message, FormatNowTrackingMessage(idMatch.Group("id"))));
            }
            if (m_CommandParser.TryGetCommand(message, "untrack", out toUntrack) && s_ZendeskIdRegex.TryMatch(toUntrack, out idMatch))
            {
                m_Persistence.RemoveFromList(x => x.Value.Id == idMatch.Group("id"));
                return(Response.ToMessage(message, FormatNowNotTrackingMessage(idMatch.Group("id"))));
            }
            return(MessageResult.Empty);
        }
예제 #3
0
        public MessageResult ProcessMessage(Message message)
        {
            string command;

            if (m_CommandParser.TryGetCommand(message, out command))
            {
                return(m_Underlying.ProcessCommand(new Command(message.Channel, message.User, command)));
            }
            return(MessageResult.Empty);
        }
예제 #4
0
        public MessageResult ProcessMessage(Message message)
        {
            string toTrack;
            Match  trackMatch;

            if (m_CommandParser.TryGetCommand(message, "track", out toTrack) && s_TrackRegex.TryMatch(toTrack, out trackMatch))
            {
                return(ProcessMessage(message, trackMatch));
            }
            return(MessageResult.Empty);
        }
예제 #5
0
        public MessageResult ProcessMessage(Message message)
        {
            string toSuggest;

            if (m_CommandParser.TryGetCommand(message, "suggest labels for", out toSuggest))
            {
                var bug = m_JiraApi.FromId(toSuggest).Result;
                if (bug == null)
                {
                    return(Response.ToMessage(message, "Couldn't find bug " + toSuggest));
                }
                return(Response.ToMessage(message, String.Join(" ", SuggestionsFor(bug).Distinct())));
            }
            return(MessageResult.Empty);
        }
예제 #6
0
        public MessageResult ProcessMessage(Message message)
        {
            string toTrack;

            if (m_CommandParser.TryGetCommand(message, "track", out toTrack) && s_TeamcityBuildRegex.IsMatch(toTrack))
            {
                var build = m_TeamcityBuildApi.GetBuild(toTrack.Substring(6)).Result;
                if (build.Equals(TeamcityBuildStatus.Unknown))
                {
                    return(Response.ToMessage(message, FormatNotFoundMessage(toTrack)));
                }
                m_Persistence.AddToList(new Tracked <TeamcityBuildStatus>(build, message.Channel));
                return(Response.ToMessage(message, FormatNowTrackingMessage(toTrack)));
            }
            return(MessageResult.Empty);
        }
예제 #7
0
        public static bool TryGetCommand(this ICommandParser parser, Message message, string expectedCommand, out string args)
        {
            args = null;
            string command;

            if (!parser.TryGetCommand(message, out command))
            {
                return(false);
            }
            if (!(command.StartsWith(expectedCommand + " ") || command.EndsWith(expectedCommand)))
            {
                return(false);
            }

            args = command.Substring(expectedCommand.Length).Trim();
            return(true);
        }
        public MessageResult ProcessMessage(Message message)
        {
            string toReview;

            if (m_CommandParser.TryGetCommand(message, "review", out toReview))
            {
                var reference = GithubReferenceParser.Parse(toReview);
                if (reference == null)
                {
                    return(MessageResult.Empty);
                }
                var user = reference.User ?? m_DefaultUser;
                var repo = reference.Repo ?? m_DefaultRepo;
                IEnumerable <DiffComment> comments = null;
                if (reference.Commit != null)
                {
                    comments = m_ReviewApi.ReviewForCommit(user, repo, reference.Commit).Result;
                }
                if (reference.BaseBranch != null)
                {
                    comments = m_ReviewApi.ReviewForComparison(user, repo, reference.BaseBranch + "..." + reference.Branch).Result;
                }
                if (reference.Branch == "master")
                {
                    comments = m_ReviewApi.ReviewForComparison(user, repo, "master@{1day}..." + reference.Branch).Result;
                }
                if (reference.Branch != null)
                {
                    comments = m_ReviewApi.ReviewForComparison(user, repo, "master..." + reference.Branch).Result;
                }
                if (reference.Issue > 0)
                {
                    comments = m_ReviewApi.ReviewForPullRequest(user, repo, reference.Issue).Result;
                }

                if (comments != null)
                {
                    return(FormatComments(message, comments));
                }
            }
            return(MessageResult.Empty);
        }
예제 #9
0
        public MessageResult ProcessMessage(Message message)
        {
            string command;

            if (m_CommandParser.TryGetCommand(message, "help", out command))
            {
                if (!String.IsNullOrWhiteSpace(command))
                {
                    command = command.ToLowerInvariant();
                    if (m_Features.ContainsKey(command))
                    {
                        var feature = m_Features[command];
                        return(Response.ToMessage(message, String.Format("{0}\n{1}", FormatFeature(feature), feature.HelpText)));
                    }
                    else
                    {
                        return(Response.ToMessage(message, String.Format("Sorry, I don't know about '{0}'.", command)));
                    }
                }

                return(Response.ToMessage(message, String.Join("\n", m_Features.Values.Select(FormatFeature)) + "\n\nuse `help <feature>` for help on a specific feature"));
            }
            return(m_MessageProcessor.ProcessMessage(message));
        }