public async Task <ICommandResult> RemoveGroup(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(Response(ErrorStrings.RemoveGroup_BadArguments(), ResponseType.User));
            }

            var context = await GetContextAsync().ConfigureAwait(false);

            var group = await _mediator.Send(new GetRoomItemGroupByNameQuery(context.Room.Id, context.User.Id, name)).ConfigureAwait(false);

            if (group == null)
            {
                return(Response(ErrorStrings.RemoveGroup_GroupInvalidName(name), ResponseType.User));
            }

            var command = new DeleteRoomItemGroupCommand(
                groupId: group.Id,
                userId: context.User.Id
                );

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(ResponseStrings.GroupRemoved(name), ResponseType.User));
        }
        public async Task <ICommandResult> IllMake()
        {
            var context = await GetContextAsync().ConfigureAwait(false);

            var run = await _mediator.Send(new GetCurrentRunQuery(context.Room.Id, context.User.Id)).ConfigureAwait(false);

            if (run == null)
            {
                return(Response(ErrorStrings.IllMake_RunNotStarted(), ResponseType.User));
            }

            var command = new Common.Features.IllMake.Commands.IllMakeCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                runId: run.Id,
                userId: context.User.Id
                );

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(new SlashCommandResponse
            {
                Text = ResponseStrings.IllMake(context.Command.UserId),
                Type = ResponseType.Channel
            }));
        }
Exemple #3
0
        public async Task <ICommandResult> Start(string group = "tea")
        {
            var context = await GetContextAsync().ConfigureAwait(false);

            var roomItemGroup = await _mediator.Send(new GetRoomItemGroupByNameQuery(roomId : context.Room.Id, userId : context.User.Id, name : group)).ConfigureAwait(false);

            if (roomItemGroup == null)
            {
                return(Response(ErrorStrings.StartRun_GroupInvalidName(group), ResponseType.User));
            }

            if (!roomItemGroup.Options.Any())
            {
                return(Response(ErrorStrings.StartRun_GroupNoOptions(roomItemGroup.Name), ResponseType.User));
            }

            var command = new StartRunCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                userId: context.User.Id,
                roomId: context.Room.Id,
                roomGroupId: roomItemGroup.Id,
                startTime: _clock.UtcNow());

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(new SlashCommandResponse
            {
                Text = ResponseStrings.RunStarted(context.Command.UserId, roomItemGroup.Name),
                Type = ResponseType.Channel,
                Attachments = AttachmentBuilder.BuildOptions(roomItemGroup.Options)
            }));
        }
Exemple #4
0
        public async Task <ICommandResult> RemoveOption(string groupName, string optionName)
        {
            if (string.IsNullOrWhiteSpace(groupName) || string.IsNullOrWhiteSpace(optionName))
            {
                return(Response(ErrorStrings.RemoveOption_BadArguments(), ResponseType.User));
            }

            var context = await GetContextAsync().ConfigureAwait(false);

            var group = await _mediator.Send(new GetRoomItemGroupByNameQuery(
                                                 roomId : context.Room.Id,
                                                 userId : context.User.Id,
                                                 name : groupName)).ConfigureAwait(false);

            if (group == null)
            {
                return(Response(ErrorStrings.RemoveOption_GroupInvalidName(groupName), ResponseType.User));
            }

            var option = group.Options.FirstOrDefault(o => o.Name.Equals(optionName));

            if (option == null)
            {
                return(Response(ErrorStrings.RemoveOption_UnknownOption(optionName), ResponseType.User));
            }

            var command = new DeleteOptionCommand(option.Id, context.User.Id);

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(ResponseStrings.OptionRemoved(optionName, groupName), ResponseType.User));
        }
Exemple #5
0
        public async Task <ICommandResult> AddOption(string groupName, string optionName)
        {
            if (string.IsNullOrWhiteSpace(groupName) || string.IsNullOrWhiteSpace(optionName))
            {
                return(Response(ErrorStrings.AddOption_BadArguments(), ResponseType.User));
            }

            var context = await GetContextAsync().ConfigureAwait(false);

            var group = await _mediator.Send(new GetRoomItemGroupByNameQuery(
                                                 roomId : context.Room.Id,
                                                 userId : context.User.Id,
                                                 name : groupName)).ConfigureAwait(false);

            if (group == null)
            {
                return(Response(ErrorStrings.AddOption_GroupInvalidName(groupName), ResponseType.User));
            }

            var command =
                new CreateOptionCommand(
                    id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                    userId: context.User.Id,
                    groupId: group.Id,
                    name: optionName);

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(ResponseStrings.OptionAddedToGroup(optionName, group.Name), ResponseType.User));
        }
Exemple #6
0
        public async Task Handle(OrderPlacedEvent notification, CancellationToken cancellationToken)
        {
            var slackUserId = await GetSlackUserId(notification.UserId).ConfigureAwait(false);

            if (slackUserId == null)
            {
                return;
            }

            await SendMessage(notification, ResponseStrings.RunUserJoined(slackUserId), ResponseType.Channel).ConfigureAwait(false);
        }
        public async Task <ICommandResult> AddGroup(string name)
        {
            var context = await GetContextAsync().ConfigureAwait(false);

            var command = new CreateRoomItemGroupCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                roomId: context.Room.Id,
                name: name,
                userId: context.User.Id
                );

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(ResponseStrings.GroupAdded(name), ResponseType.User));
        }
Exemple #8
0
        public async Task Handle(OrderOptionChangedEvent notification, CancellationToken cancellationToken)
        {
            var slackUserId = await GetSlackUserId(notification.UserId).ConfigureAwait(false);

            if (slackUserId == null)
            {
                return;
            }

            var options = await _optionsRepository.GetManyAsync(new[] { notification.PreviousOptionId, notification.OptionId })
                          .ConfigureAwait(false);

            var oDict = options.ToDictionary(o => o.Id);

            var message = ResponseStrings.RunUserOrderChanged(
                oDict[notification.PreviousOptionId].Name,
                oDict[notification.OptionId].Name);

            await SendMessage(notification, message, ResponseType.User).ConfigureAwait(false);
        }