Exemplo n.º 1
0
        public async override Task ExecuteCommand(SocketMessage msg)
        {
            var message = msg.Content.Split(' '); //TODO make a method that does this nicely, this will get repeated a lot (the following few lines)

            if (message.Length < 3)
            {
                await CommandExecutorHelpers.ErrorMessage(msg);

                return;
            }

            var team                    = message[1];
            var commandString           = message[2];
            ScheduleCommandEnum command = 0;

            // Generate an enum from a string, enforces the command exists
            try
            {
                command = (ScheduleCommandEnum)Enum.Parse(typeof(ScheduleCommandEnum), commandString, true); // ignore case
            }
            catch (ArgumentException)
            {
                await CommandExecutorHelpers.ErrorMessage(msg, String.Format("I'm sorry, I didn't recognize the command: {0}", commandString));

                return;
            }

            // make sure the team id is a number until I sort out a better parsing solution.
            int teamId = -1;

            if (!int.TryParse(team, out teamId))
            {
                await CommandExecutorHelpers.ErrorMessage(msg);

                return;
            }

            var result = GenerateScheduleResult(team, command);

            if (result.Count() == 0)
            {
                await CommandExecutorHelpers.ErrorMessage(msg);

                return;
            }

            foreach (var response in result)
            {
                await msg.Channel.SendMessageAsync(response);
            }
        }
Exemplo n.º 2
0
        public async override Task ExecuteCommand(SocketMessage msg)
        {
            Locator.Instance.Fetch <ILogger>().LogLine("Schedule Command received.");

            var message = msg.Content.Split(' '); //TODO make a method that does this nicely, this will get repeated a lot (the following few lines)

            if (message.Length < 3)
            {
                Locator.Instance.Fetch <ILogger>().LogLine("ERROR: Schedule command did not have enough params, sending error response.");
                await CommandExecutorHelpers.ErrorMessage(msg);

                return;
            }

            var team                    = string.Join(" ", message.Skip(2));
            var commandString           = message[1];
            ScheduleCommandEnum command = 0;

            // Generate an enum from a string, enforces the command exists
            try
            {
                command = (ScheduleCommandEnum)Enum.Parse(typeof(ScheduleCommandEnum), commandString, true); // ignore case
            }
            catch (ArgumentException)
            {
                Locator.Instance.Fetch <ILogger>().LogLine("ERROR: Schedule command didn't match anything known, sending error response.");
                await CommandExecutorHelpers.ErrorMessage(msg, String.Format("I'm sorry, I didn't recognize the command: {0}", commandString));

                return;
            }

            var result = GenerateScheduleResult(team, command);

            if (result.Count() == 0)
            {
                Locator.Instance.Fetch <ILogger>().LogLine("ERROR: Failed to generate Schedule command response, sending error response.");
                await CommandExecutorHelpers.ErrorMessage(msg);

                return;
            }

            foreach (var response in result)
            {
                Locator.Instance.Fetch <ILogger>().LogLine("SUCCESS: Schedule command complete.");
                await msg.Channel.SendMessageAsync(response);
            }
        }