public async Task BuyLootbox([Remainder] string str = "") { var prefix = Program.GetPrefix(Context); if (!PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus)) { await Context.Channel.SendMessageAsync(embed : new EmbedBuilderPrepared(Context.User) .WithDescription($"*~ This command requires Pro Guild+ ~*\n" + $"Try `{prefix}lootboxstats` to see drop rates.") .WithFooter($"`{prefix}pro`") .Build()); return; } LootboxStat box = null; var boxes = LootboxStats.Lootboxes.Where(x => x.Value.Price >= 0).Select(x => x.Value).ToList(); if (str != "") { var matches = boxes.Where(x => x.Name.Contains(str, StringComparison.OrdinalIgnoreCase)); if (matches.Count() == 1) { box = matches.First(); } } if (box == null) { var listMsg = await Context.Channel.SendMessageAsync(embed : ToastieUtil.BoxShopEmbed(Context.User) .WithFooter("Times out in 23 seconds. Try the `lootboxstats` command") .WithDescription("Enter the number of the lootbox you wish to purchase.") .Build()); var response = await NextMessageAsync( new Criteria <IMessage>() .AddCriterion(new EnsureSourceUserCriterion()) .AddCriterion(new EnsureSourceChannelCriterion()) .AddCriterion(new EnsureRangeCriterion(boxes.Count(), Program.GetPrefix(Context))), new TimeSpan(0, 0, 23)); _ = listMsg.DeleteAsync(); int i = 0; try { i = int.Parse(response.Content); } catch { _ = Context.Message.DeleteAsync(); return; } _ = response.DeleteAsync(); box = boxes[i - 1]; } var msg = await Context.Channel.SendMessageAsync($"How many **{box.Name}** lootboxes do you wish to buy? (max 100)"); var resp = await NextMessageAsync( new Criteria <IMessage>() .AddCriterion(new EnsureSourceUserCriterion()) .AddCriterion(new EnsureSourceChannelCriterion()) .AddCriterion(new EnsureRangeCriterion(100, Program.GetPrefix(Context))), new TimeSpan(0, 0, 23)); _ = msg.DeleteAsync(); int amount = 0; try { amount = int.Parse(resp.Content); } catch { _ = Context.Message.DeleteAsync(); return; } _ = resp.DeleteAsync(); try { await BalanceDb.AddToasties(Context.User.Id, -box.Price *amount, Context.Guild.Id); } catch (Exception ex) { await Context.Channel.SendMessageAsync(ex.Message); return; } await LootBoxDb.AddLootbox(Context.User.Id, (LootBoxType)box.TypeId, amount, Context.Guild.Id); await Context.Channel.SendMessageAsync(embed : new EmbedBuilderPrepared(Context.User) .WithDescription($"You bought {amount}x **{box.Name}**!\nType `{Program.GetPrefix(Context)}open` to open it!") .Build()); }
public async Task LootboxShop([Remainder] string str = "") { await Context.Channel.SendMessageAsync(embed : ToastieUtil.BoxShopEmbed(Context.User).Build()); }