Exemple #1
0
        /// <summary>
        /// Add a line containing a reference to a voter's post.
        /// Handles rank, plan, and normal voters.
        /// </summary>
        /// <param name="voterName">The name of the voter.</param>
        /// <param name="voteType">The type of vote this is for.</param>
        /// <param name="marker">The marker to use for rank votes.</param>
        private void AddVoter(string voterName, VoteType voteType = VoteType.Vote, string marker = null)
        {
            bool closeBold = false;

            if (voteType == VoteType.Rank && marker != null)
            {
                sb.Append("[");
                sb.Append(marker);
                sb.Append("] ");
            }
            else if (VoteCounter.Instance.PlanNames.Contains(voterName))
            {
                sb.Append("[b]Plan: ");
                closeBold = true;
            }

            sb.Append("[url=\"");
            sb.Append(VoteInfo.GetVoterUrl(voterName, voteType));
            sb.Append("\"]");
            sb.Append(voterName);
            sb.Append("[/url]");

            if (closeBold)
            {
                sb.Append("[/b]");
            }

            sb.AppendLine();
        }
Exemple #2
0
        /// <summary>
        /// Add the provided vote to the output in compact format.
        /// </summary>
        /// <param name="vote">The vote to add.</param>
        private void AddCompactVote(KeyValuePair <string, HashSet <string> > vote)
        {
            List <string> voteLines = vote.Key.GetStringLines();

            if (voteLines.Count == 0)
            {
                return;
            }

            int    userCount       = VoteInfo.CountVote(vote);
            string userCountMarker = userCount.ToString();

            // Single-line votes are always shown.
            if (voteLines.Count == 1)
            {
                sb.AppendLine(VoteString.ModifyVoteLine(voteLines.First(), marker: userCountMarker));
                return;
            }

            // Two-line votes can be shown if the second line is a sub-vote.
            if (voteLines.Count == 2 && !string.IsNullOrEmpty(VoteString.GetVotePrefix(voteLines.Last())))
            {
                sb.AppendLine(VoteString.ModifyVoteLine(voteLines.First(), marker: userCountMarker));
                sb.AppendLine(VoteString.ModifyVoteLine(voteLines.Last(), marker: userCountMarker));
                return;
            }


            // Longer votes get condensed down to a link to the original post (and named after the first voter)
            string firstVoter = VoteInfo.GetFirstVoter(vote.Value);

            string task = VoteString.GetVoteTask(vote.Key);

            sb.Append($"[{userCountMarker}]");
            if (!string.IsNullOrEmpty(task))
            {
                sb.Append($"[{task}]");
            }

            string link;

            if (firstVoter.StartsWith(StringUtility.PlanNameMarker, StringComparison.Ordinal))
            {
                link = VoteInfo.GetVoterUrl(firstVoter, VoteType.Plan);
            }
            else
            {
                link = VoteInfo.GetVoterUrl(firstVoter, VoteType.Vote);
            }

            sb.Append($" Plan: {firstVoter} — {link}\r\n");
        }
Exemple #3
0
        /// <summary>
        /// Function to get a line for one of the compact mode displays,
        /// based on whether this is a parent or child node.
        /// </summary>
        /// <param name="displayMode">The display mode currently being used.</param>
        /// <returns>Returns a string representation of the current vote node.</returns>
        public string GetLine(DisplayMode displayMode)
        {
            var lines = Text.GetStringLines();

            if (lines.Count == 0)
            {
                return(string.Empty);
            }

            string results = string.Empty;

            if (HasChildren || (!HasParent && lines.Count == 1))
            {
                // Parent node, or solitary node with 1 line.
                results = VoteString.ModifyVoteLine(lines[0], marker: VoterCount.ToString());
            }
            else if (HasParent && lines.Count == 1)
            {
                // Child node with 1 line
                if (displayMode == DisplayMode.Compact)
                {
                    results = VoteString.ModifyVoteLine(lines[0], prefix: "", marker: VoterCount.ToString());
                }
                else
                {
                    results = VoteString.ModifyVoteLine(lines[0], prefix: "-", marker: VoterCount.ToString());
                }
            }
            else if (!HasChildren)
            {
                // Other nodes without children (typically child nodes).

                StringBuilder sb = new StringBuilder();

                if (HasParent && displayMode == DisplayMode.CompactNoVoters)
                {
                    sb.Append("-");
                }

                sb.Append("[");
                sb.Append(VoterCount);
                sb.Append("]");

                // Only explicitly add tasks to parent nodes
                if (!HasParent)
                {
                    string task = VoteString.GetVoteTask(lines[0]);
                    if (!string.IsNullOrEmpty(task))
                    {
                        sb.Append($"[{task}]");
                    }
                }


                sb.Append(" Plan: ");
                string firstVoter = VoteInfo.GetFirstVoter(Voters);
                sb.Append(firstVoter);

                // Only add the link if we're not showing the voters
                if (displayMode == DisplayMode.CompactNoVoters)
                {
                    string link;

                    VoteType voteType = firstVoter.IsPlanName() ? VoteType.Plan : VoteType.Vote;
                    link = VoteInfo.GetVoterUrl(firstVoter, voteType);

                    sb.Append(" — ");
                    sb.Append(link);
                }

                results = sb.ToString();
            }

            // Child nodes in compact mode will be put in spoilers.  Remove BBCode.
            if (HasParent && displayMode == DisplayMode.Compact)
            {
                results = VoteString.RemoveBBCode(results);
            }

            return(results);
        }