private async Task NotifyUser(WaifuRequest wr, bool accepted, string reason = null) { try { var user = await _userService.GetOrSetAndGet(wr.UserId); if (!user) { return; } var eb = new EmbedBuilder() { Color = accepted ? SoraSocketCommandModule.Green : SoraSocketCommandModule.Red, Title = accepted ? $"You request for {wr.Name} has been accepted. You've been awarded with {_REQUEST_REWARD.ToString()} SC." : $"You request for {wr.Name} has been rejected." }; if (!string.IsNullOrWhiteSpace(reason)) { eb.WithDescription($"**Reason:** {reason}"); } eb.WithImageUrl(wr.ImageUrl); await(~user).SendMessageAsync(embed: eb.Build()); } catch (Exception) { // Ignore since user could have DMs disabled } }
public async Task AddWaifu(WaifuRequest wr) => await _soraTransactor.DoInTransactionAsync(async context => { context.Waifus.Add(new Waifu() { ImageUrl = wr.ImageUrl, Name = wr.Name, Rarity = wr.Rarity }); await context.SaveChangesAsync().ConfigureAwait(false); }).ConfigureAwait(false);
public async Task <uint> AddWaifuRequest(WaifuRequestAddDto waifuRequestAddDto) => await _soraTransactor.DoInTransactionAndGetAsync(async context => { WaifuRequest req = new WaifuRequest() { Name = waifuRequestAddDto.Name, ImageUrl = waifuRequestAddDto.ImageUrl, Rarity = waifuRequestAddDto.Rarity, RequestState = RequestState.Pending, RequestTime = DateTime.UtcNow, UserId = ulong.Parse(waifuRequestAddDto.UserId), }; context.WaifuRequests.Add(req); await context.SaveChangesAsync().ConfigureAwait(false); return(req.Id); }).ConfigureAwait(false);