public async Task <ICommandResult> End() { 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.EndRun_RunNotStarted(), ResponseType.User)); } var orders = await _mediator.Send(new GetRunOrdersQuery(run.Id, context.User.Id)).ConfigureAwait(false); var command = new EndRunCommand( runId: run.Id, roomId: context.Room.Id, userId: context.User.Id, orders: orders ); command.AddCallbackState(context.Command.ToCallbackData()); await _mediator.Send(command).ConfigureAwait(false); return(Response(null, ResponseType.Channel)); }
public async Task <IActionResult> SlashCommandHook(SlashCommand slashCommand) { if (slashCommand == null) { _logger.LogError("Null slash command"); return(Ok(ErrorStrings.General(), ResponseType.User)); } if (!_messageVerifier.IsValid(slashCommand)) { _logger.LogError("Bad verification token"); return(Ok(ErrorStrings.General(), ResponseType.User)); } _logger.LogInformation("Received slash command {Text} {@Command}", slashCommand.Text, slashCommand); try { var result = await _commandRunner.RunAsync(slashCommand.Text, new Dictionary <string, object> { { Constants.SlashCommand, slashCommand } }).ConfigureAwait(false); Response.ContentType = "application/json"; return(new CommandRouterResult(result)); } catch (CommandNotFoundException) { return(Ok(ErrorStrings.CommandUnknown(slashCommand.Text), ResponseType.User)); } catch (RunStartException e) { switch (e.Reason) { case RunStartException.RunStartExceptionReason.ExistingActiveRun: return(Ok(ErrorStrings.StartRun_RunAlreadyStarted(), ResponseType.User)); case RunStartException.RunStartExceptionReason.Unspecified: default: break; } _logger.LogError(e, "Failed to start run"); } catch (RunEndException e) { switch (e.Reason) { case RunEndException.RunEndExceptionReason.NoActiveRun: return(Ok(ErrorStrings.EndRun_RunNotStarted(), ResponseType.User)); case RunEndException.RunEndExceptionReason.NoOrders: return(Ok(ErrorStrings.EndRun_NoOrders(), ResponseType.User)); case RunEndException.RunEndExceptionReason.NotJoined: return(Ok(ErrorStrings.EndRun_NotJoined(), ResponseType.User)); case RunEndException.RunEndExceptionReason.Unspecified: default: break; } _logger.LogError(e, "Failed to end run"); } catch (PermissionException e) { return(Ok(e.Message, ResponseType.User)); } catch (Exception e) { _logger.LogError(e, "Failed to run command"); } return(Ok(ErrorStrings.CommandFailed(), ResponseType.User)); }