Exemplo n.º 1
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            PollVote[] votes;
            if (command.Arguments.Length == 0 || (command.Arguments.Length == 1 && command.Arguments[0] == "all"))
            {
                votes = module.GetUserVotes(command.User).ToArray();
                if (votes.Length == 0)
                {
                    throw new StreamCommandException("You haven't voted for anything, so revoking a vote doesn't make any sense.", false);
                }

                if (votes.Length > 1)
                {
                    if (command.Arguments.Length == 1 && command.Arguments[0] == "all")
                    {
                        foreach (PollVote vote in votes)
                        {
                            module.ExecuteRevoke(vote.Poll, command.User);
                        }
                        SendMessage(channel, command.User, $"You revoked your votes in polls '{string.Join(", ", votes.Select(v => v.Poll))}'");
                        return;
                    }
                    throw new StreamCommandException($"You have voted in more than one poll. Type !revoke all to remove all your votes. You voted in the following polls: {string.Join(", ", votes.Select(v => v.Poll))}");
                }

                module.ExecuteRevoke(votes[0].Poll, command.User);
                SendMessage(channel, command.User, $"You revoked your vote in poll '{votes[0].Poll}'");
                return;
            }

            string poll = command.Arguments[0].ToLower();

            if (module.RevokeVote(command.User, poll))
            {
                SendMessage(channel, command.User, $"You revoked your vote in poll '{poll}'");
                return;
            }

            PollOption[] options = module.FindOptions(command.Arguments);
            string[]     keys    = options.Select(o => o.Key).ToArray();
            votes = module.GetUserVotes(command.User, keys).ToArray();

            if (votes.Length == 0)
            {
                SendMessage(channel, command.User, "No votes match your arguments so no clue what you want to revoke.");
                return;
            }

            foreach (PollVote vote in votes)
            {
                module.ExecuteRevoke(vote.Poll, command.User);
            }
            SendMessage(channel, command.User, $"You revoked your votes in polls '{string.Join(", ", votes.Select(v => v.Poll))}'");
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            PollVote[] votes = module.GetUserVotes(command.User, command.Arguments.Length > 0 ? command.Arguments[0] : null).ToArray();

            if (votes.Length == 0)
            {
                SendMessage(channel, command.User, $"You didn't vote for anything{(command.Arguments.Length > 0 ? $" in poll {command.Arguments[0]}" : "")}");
            }
            else
            {
                SendMessage(channel, command.User, $"You voted for: {string.Join(", ", votes.Select(v => $"'{v.Vote}' in poll '{v.Poll}'"))}");
            }
        }