/// <summary> /// Finish the order, update balance and publish the updated balance to slack along with closed order message. /// </summary> private async Task HandleFinalizeOrderAction(SlashCommand command) { var(finishedOrder, updatedBalance) = await foodService.FinishOrder(); var responseBlocks = new List <Block>(); responseBlocks.AddRange(SlackFormatter.BuildOrderMessage(finishedOrder)); responseBlocks.AddRange(SlackFormatter.BuildBalanceMessage(updatedBalance)); await SendCommandResponse(command, responseBlocks); }
/// <summary> /// Reopen last finished order, revert balance and notify slack. /// </summary> private async Task HandleReopenOrderAction(SlashCommand command) { var(reopenedOrder, updatedBalance) = await foodService.ReopenOrder(); await SendPublicResponse(command, "Order reopened, reverting last balance changes."); var responseBlocks = new List <Block>(); responseBlocks.AddRange(SlackFormatter.BuildBalanceMessage(updatedBalance)); responseBlocks.AddRange(SlackFormatter.BuildOrderMessage(reopenedOrder)); await SendCommandResponse(command, responseBlocks); }
/// <summary> /// Add someone else as eater to currently open order and publish updated order to slack. /// Update current entry, if already added. /// Can be used to host external guests. /// </summary> private async Task HandleEatAsOtherAction(SlashCommand command) { try { // Example: ['eat', 'batman', '12.50', 'pizza'] var args = command.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); if (args.Count < 3) { throw new FormatException(); } // Eater var eaterStr = args[1].Trim(); var eater = FoodUser.CreateFromString(eaterStr); // Cost args[2] = args[2].Replace(',', '.'); var cost = decimal.Parse(args[2], CultureInfo.InvariantCulture); // Optional item description string item = null !; if (args.Count >= 4) { item = item = string.Join(' ', args.Skip(3).ToArray()); } var updatedOrder = await foodService.AddEater(eater : eater, cost, item); await SendCommandResponse(command, SlackFormatter.BuildOrderMessage(updatedOrder)); } catch (FormatException) { await SendError(command.ResponseUrl, new BadRequestException($"Incorrect format, expected: `/food {CommandTexts.EatAs} <who> <cost> [description]`")); } catch (Exception x) { await SendError(command.ResponseUrl, x); } }
/// <summary> /// Set cost (e.g. delivery) that should be shared equally by all eaters. /// Update current order and publish it to slack. /// </summary> private async Task HandleSharedCostAction(SlashCommand command) { try { // Example: ['shared', '4.99'] var args = command.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (args.Length != 2) { throw new FormatException(); } args[1] = args[1].Replace(',', '.'); var cost = decimal.Parse(args[1]); var updatedOrder = await foodService.SetSharedCost(cost); await SendCommandResponse(command, SlackFormatter.BuildOrderMessage(updatedOrder)); } catch (FormatException) { await SendError(command.ResponseUrl, new BadRequestException($"Incorrect format, expected: `/food {CommandTexts.Shared} <cost>`")); } }
/// <summary> /// Add caller as eater to currently open order and publish updated order to slack. /// Update current entry, if already added. /// </summary> private async Task HandleEatAsCallerAction(SlashCommand command) { try { // Example: ['eat', '12.50', 'pizza'] var args = command.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); if (args.Count < 2) { throw new FormatException(); } // Cost args[1] = args[1].Replace(',', '.'); var cost = decimal.Parse(args[1], CultureInfo.InvariantCulture); // Optional item description string item = null !; if (args.Count >= 3) { // Join all remaining items because spaces may have been used in item description item = string.Join(' ', args.Skip(2).ToArray()); } var updatedOrder = await foodService.AddEater(eater : new FoodUser(command.UserId, command.UserName), cost, item); await SendCommandResponse(command, SlackFormatter.BuildOrderMessage(updatedOrder)); } catch (FormatException) { await SendError(command.ResponseUrl, new BadRequestException($"Incorrect format, expected: /{CommandTexts.Eat} <cost> [description]")); } catch (Exception x) { await SendError(command.ResponseUrl, x); } }
/// <summary> /// Open a new order and publish it to slack. /// </summary> private async Task HandleOpenOrderAction(SlashCommand command) { var order = await foodService.OpenNewOrder(context.Caller); await SendCommandResponse(command, SlackFormatter.BuildOrderMessage(order)); }