示例#1
0
        public void ProcessCommand(MessageData data)
        {
            _mMainController.AddMessage(data.Chat);

            if (!data.Text.Any())
            {
                return;
            }
            if (data.Text.First() != '/' || data.Text.Length > 50)
            {
                return;
            }

            var lower  = data.Text.ToLower();
            var splits = lower.Split(Separator);

            var signing = new Signing(data.Username);

            switch (splits.First())
            {
            case Add:
                if (splits.Length > 1)
                {
                    var newdata = new MessageData
                    {
                        Username = splits[1],
                        Text     = splits.Skip(2).Aggregate(Go, (current, next) => current + " " + next),
                        Chat     = data.Chat
                    };
                    ProcessCommand(newdata);
                }
                break;

            case Go:
            case Play:
            case Sign:
                if (splits.Length < 2)
                {
                    InvalidSign(data);
                    return;
                }

                List <DateTime?> times;
                times = splits.Length > 2 ? ExtractTimeTag(splits) : new List <DateTime?> {
                    null, null
                };

                if (times == null)
                {
                    InvalidSign(data);
                    return;
                }

                switch (splits[1])
                {
                case "2":
                case Twos:
                    signing = signing.SetTwos(true, times);
                    break;

                case "3":
                case Threes:
                    signing = signing.SetThrees(true, times);
                    break;

                case AnyTeam:
                case Any:
                    signing = new Signing(data.Username, true, true, times[0], times[1]);
                    break;

                default:
                    InvalidSign(data);
                    return;
                }
                var result = _mMainController.AddSigning(data.Chat, signing);
                _mBotWrapper.PingParty(result, data.Chat);
                break;

            case Status:
                _mBotWrapper.PingParty(_mMainController.GetState(data.Chat), data.Chat);
                break;

            case Reset:
                _mMainController.Reset(data.Chat);
                _mBotWrapper.SendMessage(data.Chat, "Party statuses reset.");
                break;

            case Echo:
                _mBotWrapper.SendMessage(data.Chat, GetSay(data.Text));
                break;

            case Backlog:
                _mBotWrapper.SendMessage(data.Chat, GetBacklog());
                break;

            case Roll:
                var amount = 1;
                if (splits.Length == 2)
                {
                    var success = TryParse(splits[1], out amount);
                    if (!success)
                    {
                        amount = 1;
                    }
                }
                _mBotWrapper.SendMessage(
                    data.Chat, data.Username + RollTimes(amount));
                break;

            case "/petallbunnies":
            case "/petbunny":
                _mBotWrapper.SendMessage(data.Chat,
                                         "\uD83D\uDC30 Pet the bunnies! \uD83D\uDC30");
                break;

            case "/lolapua":
            case "/h":
            case Help:
                _mBotWrapper.SendMessage(data.Chat, GetCommands());
                return;
            }
        }