public async Task SellAfternoon(CommandContext ctx, int price) { await ctx.TriggerTypingAsync(); string response; DateTime currentDate = DateTimeOffsetter.ToUSCentralTime(DateTime.Now).DateTime; try { if (_turnipCalculationService.AddOrUpdateSellPriceInDB(Convert.ToInt32(ctx.Member.Discriminator), ctx.Member.DisplayName, price, currentDate.DayOfWeek, false)) { response = $"Recorded {ctx.Member.DisplayName}'s sell price for {currentDate.DayOfWeek} afternoon as {price} bells."; } else { response = "Couldn't record price. It's probably Owen's fault."; } } catch (Exception) { response = "Crashed updating your price. What did you do??"; } await ctx.RespondAsync(response); }
public async Task SellWithDate(CommandContext ctx, int price, string dayOfWeekString, string timeOfDayString) { await ctx.TriggerTypingAsync(); string[] morningOptions = new string[] { "morning", "m", "morn" }; string[] eveningOptions = new string[] { "evening", "e", "eve", "afternoon", "a", "after" }; bool success; string response; DateTime dateOfUpdate = DateTimeOffsetter.ToUSCentralTime(DateTimeOffset.Now).DateTime; success = Enum.TryParse(dayOfWeekString, true, out DayOfWeek dayOfWeek); if (success) { if (dayOfWeek > dateOfUpdate.DayOfWeek) { success = false; } else { while (dateOfUpdate.DayOfWeek != dayOfWeek) //Keep going back in days until we have the correct day of week { dateOfUpdate = dateOfUpdate.AddDays(-1); } } } if (success && morningOptions.Any(o => o.Equals(timeOfDayString, StringComparison.InvariantCultureIgnoreCase))) //Morning update { success = _turnipCalculationService.AddOrUpdateSellPriceInDB(Convert.ToInt32(ctx.Member.Discriminator), ctx.Member.DisplayName, price, dayOfWeek, true); } else if (success && eveningOptions.Any(o => o.Equals(timeOfDayString, StringComparison.InvariantCultureIgnoreCase))) //Evening update { success = _turnipCalculationService.AddOrUpdateSellPriceInDB(Convert.ToInt32(ctx.Member.Discriminator), ctx.Member.DisplayName, price, dayOfWeek, false); } else { success = false; } if (success) { response = $"Successfully updated {dayOfWeek.ToString()} {timeOfDayString}'s price to {price} bells."; } else { response = "There was an issue updating the sell price. Try again or blame Owen."; } await ctx.RespondAsync(response); }