Beispiel #1
0
        private void FindUnvotes(Post post)
        {
            string pattern = "<strong>unvote</strong>";

            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(
                post.Text,
                pattern,
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            if (match.Success)
            {
                //Is the poster already voting? If they are, remove their vote
                if (RawVoteCount.Contains(post.Poster))
                {
                    RawVoteCount.Remove(post.Poster);
                }
            }
        }
Beispiel #2
0
        private void FindVotes(Post post)
        {
            string pattern = "<strong>(?:unvote[,.]?)? ?vote:? (.+)</strong>";

            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(
                post.Text,
                pattern,
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            if (match.Success)
            {
                string vote  = match.Groups[1].Value;
                string voter = post.Poster;

                if (IsVoterValid(voter))
                {
                    if (IsVoteeValid(vote, out string votee))
                    {
                        //Is the poster already voting? If they are, remove their vote
                        if (RawVoteCount.Contains(voter))
                        {
                            RawVoteCount.Remove(voter);
                        }

                        //Add the vote to the votecount
                        RawVoteCount.Add(voter, votee);

                        logger.LogVote(post.PostNumber, voter, votee);
                    }
                    else
                    {
                        logger.LogInvalidTarget(post.PostNumber, voter, votee);
                    }
                }
                else
                {
                    logger.LogInvalidVoter(post.PostNumber, voter);
                }
            }
        }
Beispiel #3
0
        //Create a votecount where key is votee and value is list of players voting for that player
        public Dictionary <string, List <string> > CreateVotecount()
        {
            var voteCount = new Dictionary <string, List <string> >();

            foreach (DictionaryEntry kvp in RawVoteCount)
            {
                //If this is the first vote on the votee, add them to the dictionary
                if (!voteCount.ContainsKey((string)kvp.Value))
                {
                    voteCount.Add((string)kvp.Value, new List <string> {
                        (string)kvp.Key
                    });
                }
                //If we've seen them before, add this new vote against them
                else
                {
                    voteCount[(string)kvp.Value].Add((string)kvp.Key);
                }
            }
            //Sort the vote count by number of votes each votee has received
            voteCount = voteCount.OrderByDescending(x => x.Value.Count).ToDictionary(pair => pair.Key, pair => pair.Value);

            //List Not Voting at the bottom of the votecount
            List <string> notVoting = new List <string>();

            foreach (Player player in PlayerList)
            {
                if (!RawVoteCount.Contains(player.MainName))
                {
                    notVoting.Add(player.MainName);
                }
            }
            voteCount.Add("Not Voting", notVoting);

            return(voteCount);
        }