コード例 #1
0
        public async Task <IActionResult> CreateKudo([FromForm] SlashCommandDto request)
        {
            try
            {
                var command = kudoCommandFactory.CreateKudoCommand(request);

                var response = await Mediator.Send(command);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                if (ex is ArgumentException || ex is KudoSlashCommandValidationException)
                {
                    return(Ok(ex.Message));
                }

                throw;
            }
        }
コード例 #2
0
        public IKudoRequest CreateKudoCommand(SlashCommandDto slashCommandDto)
        {
            if (slashCommandDto == null || string.IsNullOrWhiteSpace(slashCommandDto.text))
            {
                throw new ArgumentException("You must specify a kudo command. Use /kudo help for the list of available commands.");
            }

            var actionString = slashCommandDto.text.Split(' ')[0];

            var commandAction = Enum.Parse(typeof(EKudoCommandAction), actionString, ignoreCase: true);

            switch (commandAction)
            {
            case EKudoCommandAction.Add:
                return(new CreateKudoCommand
                {
                    UserId = slashCommandDto.user_id,
                    Username = slashCommandDto.user_name,
                    ChannelId = slashCommandDto.channel_id,
                    ChannelName = slashCommandDto.channel_name,
                    Text = slashCommandDto.text
                });

            case EKudoCommandAction.Help:
                return(new HelpKudoQuery());

            case EKudoCommandAction.List:
                return(new ListKudosQuery
                {
                    UserId = slashCommandDto.user_id,
                    Text = slashCommandDto.text
                });

            case EKudoCommandAction.Delete:
                return(new DeleteKudoCommand
                {
                    CommandText = slashCommandDto.text
                });

            case EKudoCommandAction.Replace:
                return(new ReplaceKudoCommand
                {
                    CommandText = slashCommandDto.text
                });

            case EKudoCommandAction.User:
                return(new ListUserKudosQuery
                {
                    Text = slashCommandDto.text
                });

            case EKudoCommandAction.Top:
                return(new ListTopUsersQuery
                {
                    Text = slashCommandDto.text
                });

            default:
                throw new ArgumentException("Invalid kudo command. Use </kudo help> for options");
            }
        }