예제 #1
0
        public async Task ExecuteAsync(ICommandContext context)
        {
            if (context.Parameters.Length != 1)
            {
                throw new CommandWrongUsageException("Missing arguments");
            }

            var activeVote = _callVotePlugin.VoteManager.GetActiveVote(await context.Parameters.GetAsync <string>(0));

            if (activeVote == null)
            {
                await _callVotePlugin.SendMessage(context.User, "Inactive");

                return;
            }

            if (activeVote.InCooldown)
            {
                await _callVotePlugin.SendMessage(context.User, "Cooldown", activeVote.Name, activeVote.Cooldown);

                return;
            }

            var player = (UnturnedUser)context.User;

            if (activeVote.Voters.Contains(player))
            {
                return;
            }

            activeVote.Voters.Add(player);
            await _callVotePlugin.SendMessage(context.User, "Status", activeVote.Name, activeVote.Status());
        }
예제 #2
0
        public async Task ExecuteAsync(ICommandContext context)
        {
            if (context.Parameters.Length < 1)
            {
                throw new CommandWrongUsageException("Missing arguments");
            }

            var voteName = await context.Parameters.GetAsync <string>(0);

            var argLine = context.Parameters.Skip(1);
            var votes   = _callVotePlugin.ConfigurationInstance.Votes;
            var vote    = votes.FirstOrDefault(v =>
                                               v.Name.Equals(voteName, StringComparison.OrdinalIgnoreCase) ||
                                               v.Alias.Equals(voteName, StringComparison.OrdinalIgnoreCase));

            if (vote == null)
            {
                await _callVotePlugin.SendMessage(context.User, string.Join(", ", votes.Select(v => v.Name).ToArray()));

                return;
            }

            if (!_callVotePlugin.VoteManager.CanStartVote(vote, out var cooldown))
            {
                await _callVotePlugin.SendMessage(context.User, "Cooldown", vote.Name, cooldown);

                return;
            }

            if (Provider.clients.Count < vote.MinimumPlayers)
            {
                await _callVotePlugin.SendMessage(context.User, "MinPlayers", vote.Name, vote.MinimumPlayers);

                return;
            }

            await _callVotePlugin.VoteManager.StartVote(vote, argLine);
        }