コード例 #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>
        /// Handles the automatic vote deletion.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the vote deletion was successful, otherwise <c>false</c>.</returns>
        private async Task <bool> HandleAutoVoteDeletion(Cmd c)
        {
            int voteNum;

            if (!int.TryParse(Helpers.GetArgVal(c, 3), out voteNum))
            {
                await DisplayNotNumError(c);

                Log.Write(string.Format(
                              "{0} attempted to delete a vote but specified a non-numeric vote value from {1}. Ignoring.",
                              c.FromUser, (c.FromIrc ? "IRC." : "in-game.")), _logClassType, _logPrefix);

                return(false);
            }
            if (AutoVotes.ElementAtOrDefault(voteNum) == null)
            {
                await DisplayVoteDoesntExistError(c);

                Log.Write(string.Format(
                              "{0} attempted to delete a vote that does not exist from {1}. Ignoring.",
                              c.FromUser, (c.FromIrc ? "IRC." : "in-game.")), _logClassType, _logPrefix);

                return(false);
            }
            await RemoveAutoVote(c, voteNum);

            // Disable if there are no rules specified
            var disable = AutoVotes.Count == 0;

            Log.Write("All remaining auto-votes removed. Disabling auto voter module.",
                      _logClassType, _logPrefix);

            UpdateConfig(disable);
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Executes the specified module command asynchronously.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the command evaluation was successful, otherwise <c>false</c>.</returns>
        public async Task <bool> EvalModuleCmdAsync(Cmd c)
        {
            if (c.Args.Length < (c.FromIrc ? IrcMinModuleArgs : _qlMinModuleArgs))
            {
                await DisplayArgLengthError(c);

                return(false);
            }
            if (c.Args.Length == ((c.FromIrc) ? 4 : 3))
            {
                if (Helpers.GetArgVal(c, 2).Equals("off"))
                {
                    await DisableAutoVoter(c);

                    return(true);
                }
                if (Helpers.GetArgVal(c, 2).Equals("clear"))
                {
                    AutoVotes.Clear();
                    StatusMessage =
                        "^2[SUCCESS]^7 Cleared list of votes to automatically pass or reject. Disabling auto voter.";
                    await SendServerSay(c, StatusMessage);

                    UpdateConfig(false);

                    Log.Write(string.Format(
                                  "{0} cleared the auto-voter list from {1}. Auto voter module will now be disabled..",
                                  c.FromUser, (c.FromIrc ? "IRC." : "in-game.")), _logClassType, _logPrefix);

                    return(true);
                }
                if (Helpers.GetArgVal(c, 2).Equals("list"))
                {
                    await ListAutoVotes(c);

                    return(true);
                }
                await DisplayArgLengthError(c);

                return(false);
            }
            if (c.Args.Length >= ((c.FromIrc) ? 5 : 4))
            {
                if (Helpers.GetArgVal(c, 2).Equals("del"))
                {
                    return(await HandleAutoVoteDeletion(c));
                }
                if (Helpers.GetArgVal(c, 2).Equals("yes") || Helpers.GetArgVal(c, 2).Equals("no"))
                {
                    return(await HandleAutoVoteAddition(c));
                }

                await DisplayArgLengthError(c);

                return(false);
            }
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Removes the automatic vote.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <param name="voteNum">The vote number.</param>
        /// <returns></returns>
        private async Task RemoveAutoVote(Cmd c, int voteNum)
        {
            Log.Write(string.Format("{0} removed auto-{1} vote: {2} from {3}",
                                    c.FromUser, (AutoVotes[voteNum].IntendedResult == IntendedVoteResult.Yes
                    ? "YES"
                    : "NO"), AutoVotes[voteNum].VoteText,
                                    (c.FromIrc ? "IRC." : "in-game.")), _logClassType, _logPrefix);

            StatusMessage = string.Format("^2[SUCCESS]^7 AUTO {0} vote (^3{1}^7) was removed.",
                                          (AutoVotes[voteNum].IntendedResult == IntendedVoteResult.Yes ? "YES" : "NO"),
                                          AutoVotes[voteNum].VoteText);

            AutoVotes.RemoveAt(voteNum);
            await SendServerSay(c, StatusMessage);
        }
コード例 #5
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);
            }
        }