void HeuristicVote(IChatChannel channel, StreamCommand command)
        {
            Logger.Info(this, $"Executing heuristic vote for '{command}'");


            PollOption[] options = module.FindOptions(command.Arguments);

            string optionname = string.Join(" ", command.Arguments);

            if (options.Length > 1)
            {
                throw new StreamCommandException($"Sadly there is more than one poll which contains an option '{optionname}' so you need to specify in which poll you want to vote ({string.Join(", ", options.Select(o => o.Poll))}).", false);
            }

            if (options.Length == 0)
            {
                Poll poll = module.GetPoll(optionname);
                if (poll == null)
                {
                    throw new StreamCommandException($"There is no poll and no option named '{optionname}' so i have no idea what you want to vote for.", false);
                }

                options = module.GetOptions(poll.Name);
                throw new StreamCommandException($"You need to specify the option to vote for. The following options are available. {string.Join(", ", options.Select(o => $"'{o.Key}' for '{o.Description}'"))}", false);
            }

            module.ExecuteVote(options[0].Poll, command.User, options[0].Key);
            SendMessage(channel, command.User, $"You voted successfully for '{options[0].Description}' in poll '{options[0].Poll}'.");
        }
Example #2
0
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            if (command.Arguments.Length != 1)
            {
                throw new StreamCommandException("Invalid command syntax");
            }

            string pollname = command.Arguments[0];

            Poll poll = module.GetPoll(pollname);

            if (poll == null)
            {
                throw new StreamCommandException($"There is no active poll named '{pollname}'");
            }

            PollOption[]  options = module.GetOptions(pollname);
            StringBuilder message = new StringBuilder(poll.Description).Append(": ");

            if (options.Length == 0)
            {
                message.Append("This is an unrestricted poll, so please vote for 'penis' when you're out of ideas");
            }
            else
            {
                message.Append(string.Join(", ", options.Select(o => $"{o.Key} - {o.Description}")));
                message.Append(". Usually there is more info available by typing !info <option>");
            }

            SendMessage(channel, command.User, message.ToString());
        }