public async Task OpenSpecialWaifuBox() { if (!_config.SpecialWaifuActive) { await ReplyFailureEmbed("There are no special waifus active right now :/"); return; } // Check user cash var sc = _coinRepo.GetCoins(Context.User.Id); if (sc < _WAIFU_BOX_SPECIAL_COST) { await ReplyFailureEmbed($"You don't have enough Sora Coins! You need {_WAIFU_BOX_SPECIAL_COST.ToString()} SC."); return; } var special = await _waifuService.GetRandomSpecialWaifu(Context.User.Id, _config.SpecialWaifuType).ConfigureAwait(false); if (special == null) { await ReplyFailureEmbed("You already have all the special waifus. Pls try again another time."); return; } List <Waifu> waifusUnboxed = new List <Waifu>(); waifusUnboxed.Add(special); int additional = _WAIFU_AMOUNT_IN_BOX - 1; for (int i = 0; i < additional; i++) { waifusUnboxed.Add(await _waifuService.GetRandomWaifu().ConfigureAwait(false)); } if (waifusUnboxed.Count != _WAIFU_AMOUNT_IN_BOX) { await ReplyFailureEmbed("There don't seem to be Waifus to unbox at the moment. Sorry :/"); return; } // Now lets try to give everything to the user before we continue doing anything else if (!await _waifuService.TryGiveWaifusToUser(Context.User.Id, waifusUnboxed, _WAIFU_BOX_SPECIAL_COST).ConfigureAwait(false)) { await ReplyFailureEmbed("Failed to give Waifus :( Please try again"); return; } // We gave him the waifus. Now we just have to tell him :) waifusUnboxed.Sort((x, y) => - x.Rarity.CompareTo(y.Rarity)); var eb = new EmbedBuilder() { Title = "Congrats! You've got some nice waifus", Description = $"You opened a {WaifuFormatter.GetRarityString(_config.SpecialWaifuType)} WaifuBox for {_WAIFU_BOX_SPECIAL_COST.ToString()} SC.", Footer = RequestedByFooter(Context.User), Color = Purple, ImageUrl = waifusUnboxed[0].ImageUrl }; foreach (var waifu in waifusUnboxed) { eb.AddField(x => { x.IsInline = true; x.Name = waifu.Name; x.Value = $"Rarity: {WaifuFormatter.GetRarityString(waifu.Rarity)}\n" + $"[Image Url]({waifu.ImageUrl})\n" + $"*ID: {waifu.Id}*"; }); } await ReplyAsync("", embed : eb.Build()); }
private async Task WaifuTradeComp(IUser tradeUser, int wantId, int offerId) { // First we gotta make sure that the users have the respective waifus var wantUserWaifu = await _waifuService.GetUserWaifu(tradeUser.Id, wantId).ConfigureAwait(false); if (wantUserWaifu == null) { await ReplyFailureEmbed("The user does not have the Waifu you want."); return; } var offerUserWaifu = await _waifuService.GetUserWaifu(Context.User.Id, offerId).ConfigureAwait(false); if (offerUserWaifu == null) { await ReplyFailureEmbed("You do not have the Waifu that you offer!"); return; } // They both have both. So we can actually ask for the trade. // No further preparations or queries until the user actually accepts the trade var wantWaifu = await _waifuService.GetWaifuById(wantId).ConfigureAwait(false); var offerWaifu = await _waifuService.GetWaifuById(offerId).ConfigureAwait(false); if (wantWaifu == null || offerWaifu == null) { await ReplyFailureEmbed( "Could not find one of the Waifus. They might have been removed from the DB..."); return; } var eb = new EmbedBuilder() { Title = "Waifu Trade Request", Footer = RequestedByFooter(Context.User), Description = $"{Formatter.UsernameDiscrim(Context.User)} wishes to trade with you.", Color = Purple, ImageUrl = offerWaifu.ImageUrl, }; eb.AddField(x => { x.IsInline = true; x.Name = "User offers"; x.Value = $"{offerWaifu.Name}\n{WaifuFormatter.GetRarityString(offerWaifu.Rarity)}\n_ID: {offerWaifu.Id}_"; }); eb.AddField(x => { x.IsInline = true; x.Name = "User wants"; x.Value = $"{wantWaifu.Name}\n{WaifuFormatter.GetRarityString(wantWaifu.Rarity)}\n_ID: {wantWaifu.Id}_"; }); eb.AddField(x => { x.IsInline = false; x.Name = "Accept?"; x.Value = "You can accept this trade request by writing `y` or `yes` (nothing else). " + "If you write anything else Sora will count that as declining the offer."; }); await ReplyAsync("", embed : eb.Build()); // Now wait for response. var criteria = InteractiveServiceExtensions.CreateEnsureFromUserInChannelCriteria(tradeUser.Id, Context.Channel.Id); var resp = await _interactiveService.NextMessageAsync(Context, criteria, TimeSpan.FromSeconds(45)) .ConfigureAwait(false); if (resp == null) { await ReplyFailureEmbed($"{Formatter.UsernameDiscrim(tradeUser)} didn't answer in time >.<"); return; } if (!InteractiveServiceExtensions.StringIsYOrYes(resp.Content)) { await ReplyFailureEmbed($"{Formatter.UsernameDiscrim(tradeUser)} declined the trade offer."); return; } // User accepted offer. if (!await _waifuService.TryTradeWaifus(Context.User.Id, tradeUser.Id, offerId, wantId) .ConfigureAwait(false)) { await ReplyFailureEmbed("Failed to make trade. Please try again"); return; } await ReplySuccessEmbedExtended("Successfully traded Waifus!", $"{Formatter.UsernameDiscrim(Context.User)} got {wantWaifu.Name}\n" + $"{Formatter.UsernameDiscrim(tradeUser)} got {offerWaifu.Name}"); }
public async Task OpenWaifuBox() { // Check the user cash var sc = _coinRepo.GetCoins(Context.User.Id); if (sc < _WAIFU_BOX_COST) { await ReplyFailureEmbed($"You don't have enough Sora Coins! You need {_WAIFU_BOX_COST.ToString()} SC."); return; } // Get the waifus List <Waifu> waifusUnboxed = new List <Waifu>(); for (int i = 0; i < _WAIFU_AMOUNT_IN_BOX; ++i) { var wToAdd = await _waifuService.GetRandomWaifu().ConfigureAwait(false); if (wToAdd == null) { break; } // Check if URL is valid bcs it seems some are kinda broken ;_; // This is an extreme edge case but it happened once and that is enough as it should never happen if (!Helper.UrlValidUri(wToAdd.ImageUrl)) { await _waifuService.RemoveWaifu(wToAdd.Id).ConfigureAwait(false); --i; continue; } waifusUnboxed.Add(wToAdd); } if (waifusUnboxed.Count != _WAIFU_AMOUNT_IN_BOX) { await ReplyFailureEmbed("There don't seem to be Waifus to unbox at the moment. Sorry :/"); return; } // Now lets try to give everything to the user before we continue doing anything else if (!await _waifuService.TryGiveWaifusToUser(Context.User.Id, waifusUnboxed, _WAIFU_BOX_COST).ConfigureAwait(false)) { await ReplyFailureEmbed("Failed to give Waifus :( Please try again"); return; } // We gave him the waifus. Now we just have to tell him :) waifusUnboxed.Sort((x, y) => - x.Rarity.CompareTo(y.Rarity)); string waifuImageUrl = waifusUnboxed.FirstOrDefault(x => Uri.IsWellFormedUriString(x.ImageUrl, UriKind.Absolute))?.ImageUrl; var eb = new EmbedBuilder() { Title = "Congrats! You've got some nice waifus", Description = $"You opened a regular WaifuBox for {_WAIFU_BOX_COST.ToString()} SC." + $@"{(_config.SpecialWaifuActive ? $"\nThere are currently {WaifuFormatter.GetRarityString(_config.SpecialWaifuType)} special Waifus for a limited time only. " + $"You can open them with the `special` command" : $"")}", Footer = RequestedByFooter(Context.User), Color = Purple, ImageUrl = waifuImageUrl }; foreach (var waifu in waifusUnboxed) { eb.AddField(x => { x.IsInline = true; x.Name = waifu.Name; x.Value = $"Rarity: {WaifuFormatter.GetRarityString(waifu.Rarity)}\n" + $"[Image Url]({waifu.ImageUrl})\n" + $"*ID: {waifu.Id}*"; }); } await ReplyAsync("", embed : eb.Build()); }
public async Task GetWaifuStats( [Summary("@User to get the stats to. Leave blank to get your own")] DiscordGuildUser userT = null) { var user = userT?.GuildUser ?? (IGuildUser)Context.User; var waifus = await _waifuService.GetAllWaifusFromUser(user.Id).ConfigureAwait(false); if (waifus == null || waifus.Count == 0) { await ReplyFailureEmbed($"{(userT == null ? "You have" : $"{Formatter.UsernameDiscrim(user)} has")} no waifus."); return; } // Unlike the total waifus we actually cache this value for 1 hour. This is because it's less important and can be inaccurate for a while // This frees up resources for more important tasks var allRarityStats = await _waifuService.GetTotalWaifuRarityStats().ConfigureAwait(false); var eb = new EmbedBuilder() { Color = Purple, Footer = RequestedByFooter(Context.User), ThumbnailUrl = user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl(), Title = "Waifu Stats", Description = "This shows you how many waifus you own of each category and your completion percentage." + " This does not take dupes into account!" }; int totalHas = 0; var userRarity = waifus.GroupBy(w => w.Rarity, (rarity, ws) => new { rarity, count = ws.Count() }) .ToDictionary(x => x.rarity, x => x.count); // This line kinda sucks. Don't know if there is a better way to solve this but that aint it chief var allRarities = ((WaifuRarity[])Enum.GetValues(typeof(WaifuRarity))).OrderBy(x => x); int total = 0; foreach (var rarity in allRarities) { userRarity.TryGetValue(rarity, out int count); int allRar = allRarityStats[rarity]; total += allRar; eb.AddField(x => { x.Name = WaifuFormatter.GetRarityString(rarity); x.IsInline = true; x.Value = $"{count.ToString()} / {allRar.ToString()} ({((float) count / allRar):P2})"; }); totalHas += count; } eb.AddField(x => { x.Name = "Total"; x.IsInline = true; x.Value = $"{totalHas.ToString()} / {total.ToString()} ({((float) totalHas / total):P2})"; }); await ReplyAsync("", embed : eb.Build()); }