예제 #1
0
        /// <summary>
        /// Adds the automatic vote with arguments
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns>
        /// <c>true</c> if the argumented automatic vote was successfully added; otherwise <c>false</c>.
        /// </returns>
        /// <remarks>
        /// This method is for auto-votes where a second parameter is specified in addition to the
        /// generic type of vote. Example: 'map campgrounds'
        /// </remarks>
        private async Task <bool> AddAutoVoteWithArgs(Cmd c)
        {
            var fullVote = string.Format("{0} {1}", Helpers.GetArgVal(c, 3), Helpers.GetArgVal(c, 4));

            foreach (var av in AutoVotes.Where(av => av.VoteText.Equals(fullVote,
                                                                        StringComparison.InvariantCultureIgnoreCase)))
            {
                StatusMessage =
                    string.Format("^1[ERROR]^3 AUTO {0} vote for ^1{1}^3 was already added by ^1{2}",
                                  (av.IntendedResult == IntendedVoteResult.Yes ? "YES" : "NO"), fullVote, av.AddedBy);
                await SendServerTell(c, StatusMessage);

                Log.Write(string.Format(
                              "{0} attempted to add auto-{1} vote: {2} from {3} but auto-{1} vote was already added by {4}. Ignoring.",
                              c.FromUser, Helpers.GetArgVal(c, 2).ToUpper(),
                              fullVote, (c.FromIrc ? "IRC." : "in-game."), av.AddedBy), _logClassType, _logPrefix);

                return(false);
            }

            AutoVotes.Add(new AutoVote(fullVote, true, (Helpers.GetArgVal(c, 2).Equals("yes")
                ? IntendedVoteResult.Yes
                : IntendedVoteResult.No), c.FromUser));

            UpdateConfig(true);

            StatusMessage = string.Format("^2[SUCCESS]^7 Any vote matching: ^2{0}^7 will automatically {1}",
                                          fullVote, (Helpers.GetArgVal(c, 2).Equals("yes") ? "^2pass." : "^1fail."));
            await SendServerSay(c, StatusMessage);

            Log.Write(string.Format("{0} added auto-{1} vote: {2} from {3}",
                                    c.FromUser, Helpers.GetArgVal(c, 2).ToUpper(),
                                    fullVote, (c.FromIrc ? "IRC." : "in-game.")), _logClassType, _logPrefix);
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Lists the automatic votes.
        /// </summary>
        private async Task ListAutoVotes(Cmd c)
        {
            if (AutoVotes.Count == 0)
            {
                StatusMessage = string.Format("^7No automatic pass/reject votes are set. Use ^2{0}{1} {2}" +
                                              " yes vote ^7OR^1 no vote^7 to add.",
                                              CommandList.GameCommandPrefix, c.CmdName,
                                              ((c.FromIrc)
                        ? (string.Format("{0} {1}", c.Args[1],
                                         NameModule))
                        : NameModule));
                await SendServerSay(c, StatusMessage);

                return;
            }
            var yes = new StringBuilder();
            var no  = new StringBuilder();

            if (AutoVotes.Any(av => av.IntendedResult == IntendedVoteResult.Yes))
            {
                foreach (var a in AutoVotes.Where(a => a.IntendedResult == IntendedVoteResult.Yes))
                {
                    yes.Append(string.Format("^7#{0}:^2 {1}^7 ({2}), ", AutoVotes.IndexOf(a), a.VoteText,
                                             a.AddedBy));
                }
                StatusMessage = string.Format("^2[AUTO YES]^7 " + yes.ToString().TrimEnd(',', ' '));
                await SendServerSay(c, StatusMessage);
            }
            if (AutoVotes.Any(av => av.IntendedResult == IntendedVoteResult.No))
            {
                foreach (var a in AutoVotes.Where(a => a.IntendedResult == IntendedVoteResult.No))
                {
                    no.Append(string.Format("^7#{0}:^1 {1}^7 ({2}), ", AutoVotes.IndexOf(a), a.VoteText,
                                            a.AddedBy));
                }
                StatusMessage = string.Format("^1[AUTO NO]^7 " + no.ToString().TrimEnd(',', ' '));
                await SendServerSay(c, StatusMessage);
            }
        }