public async Task<bool> Setup(BattleCommand cmd, Say e, string args)
        {
            command = cmd.Create();

            Creator = e;
            question = command.Arm(battle, e, args);
            if (question == null) return false;
            winCount = battle.Users.Values.Count(x => command.GetRunPermissions(battle, x.Name) >= BattleCommand.RunPermission.Vote && !cmd.IsSpectator(battle, x.Name, x)) / 2 + 1;
            if (winCount <= 0) winCount = 1;

            if (winCount <= 0) winCount = (battle.NonSpectatorCount / 2 + 1);
            if (winCount <= 0) winCount = 1;

            if (!await Vote(e, true)) await battle.SayBattle($"Poll: {question} [!y=0/{winCount}, !n=0/{winCount}]");
            else return false;

            return true;
        }
예제 #2
0
 public override string Arm(ServerBattle battle, Say e, string arguments = null)
 {
     if (string.IsNullOrEmpty(arguments))
     {
         battle.Respond(e, "Pick a command to poll, e.g. !poll map tabula");
         return null;
     }
     var parts = arguments.Split(new[] { ' ' }, 2);
     var commandName = parts[0] ?? "";
     var commandArgs = parts.Length > 1 ? parts[1] : null;
     commandToRun = battle.GetCommandByName(commandName);
     if (commandToRun.GetRunPermissions(battle, e.User) >= RunPermission.Vote)
     {
         return commandToRun.Arm(battle, e, commandArgs);
     }
     battle.Respond(e, "You cannot poll this");
     return null;
 }
        public async Task <bool> StartVote(BattleCommand cmd, Say e, string args, int timeout = PollTimeout, CommandPoll poll = null)
        {
            cmd = cmd.Create();

            if (cmd is CmdMap && string.IsNullOrEmpty(args))
            {
                return(await CreateMultiMapPoll());
            }

            string topic = cmd.Arm(this, e, args);

            if (topic == null)
            {
                return(false);
            }
            Func <string, string> selector = cmd.GetIneligibilityReasonFunc(this);

            if (e != null && selector(e.User) != null)
            {
                return(false);
            }
            var options = new List <PollOption>();

            string url = null;
            string map = null;

            if (cmd is CmdMap)
            {
                url = $"{GlobalConst.BaseSiteUrl}/Maps/Detail/{(cmd as CmdMap).Map.ResourceID}";
                map = (cmd as CmdMap).Map.InternalName;
            }
            poll = poll ?? new CommandPoll(this, true, true, cmd is CmdMap, map, cmd is CmdStart);
            options.Add(new PollOption()
            {
                Name   = "Yes",
                URL    = url,
                Action = async() =>
                {
                    if (cmd.Access == BattleCommand.AccessType.NotIngame && spring.IsRunning)
                    {
                        return;
                    }
                    if (cmd.Access == BattleCommand.AccessType.Ingame && !spring.IsRunning)
                    {
                        return;
                    }
                    await cmd.ExecuteArmed(this, e);
                }
            });
            options.Add(new PollOption()
            {
                Name   = "No",
                Action = async() => { }
            });

            if (await StartVote(selector, options, e, topic, poll))
            {
                await RegisterVote(e, 1);

                return(true);
            }
            return(false);
        }