예제 #1
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());
        }
예제 #2
0
        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}'.");
        }
        public override void ExecuteCommand(IChatChannel channel, StreamCommand command)
        {
            string pollkey;

            if (command.Arguments.Length == 0)
            {
                Logger.Info(this, $"Starting heuristic poll result estimation for '{command.User}'");
                ActivePoll leadingpoll = module.GetMostActivePoll();
                if (leadingpoll == null)
                {
                    SendMessage(channel, command.User, "Since no one voted for anything i can't show you any poll.");
                    return;
                }

                SendMessage(channel, command.User, $"You seem to be too lazy to tell me which poll you want to know something about. I just guess you want to see poll '{leadingpoll.Name}' since it is the most active poll.");
                pollkey = leadingpoll.Name;
            }
            else
            {
                pollkey = command.Arguments[0];
            }

            Poll poll = module.GetPoll(pollkey);

            if (poll == null)
            {
                SendMessage(channel, command.User, $"There is no poll named '{pollkey}'");
                return;
            }

            PollDiagramData data = new PollDiagramData(module.GetWeightedVotes(pollkey));

            string message = $"Results for {pollkey}: {string.Join(", ", data.GetItems(100).Where(r => r.Count > 0).Select(r => $"{r.Item} [{r.Count}]"))}";

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