Exemplo n.º 1
0
            public async Task WaifuInfo([Remainder] IGuildUser target = null)
            {
                if (target == null)
                {
                    target = (IGuildUser)Context.User;
                }
                WaifuInfo         w;
                IList <WaifuInfo> claims;
                int divorces;

                using (var uow = _db.UnitOfWork)
                {
                    w        = uow.Waifus.ByWaifuUserId(target.Id);
                    claims   = uow.Waifus.ByClaimerUserId(target.Id);
                    divorces = uow._context.WaifuUpdates.Count(x => x.Old != null &&
                                                               x.Old.UserId == target.Id &&
                                                               x.UpdateType == WaifuUpdateType.Claimed &&
                                                               x.New == null);
                    if (w == null)
                    {
                        uow.Waifus.Add(w = new WaifuInfo()
                        {
                            Affinity = null,
                            Claimer  = null,
                            Price    = 1,
                            Waifu    = uow.DiscordUsers.GetOrCreate(target),
                        });
                    }

                    w.Waifu.Username      = target.Username;
                    w.Waifu.Discriminator = target.Discriminator;
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                var claimInfo = GetClaimTitle(target.Id);
                var affInfo   = GetAffinityTitle(target.Id);

                var rng = new NadekoRandom();

                var nobody = GetText("nobody");
                var embed  = new EmbedBuilder()
                             .WithOkColor()
                             .WithTitle("Waifu " + w.Waifu + " - \"the " + claimInfo.Title + "\"")
                             .AddField(efb => efb.WithName(GetText("price")).WithValue(w.Price.ToString()).WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("claimed_by")).WithValue(w.Claimer?.ToString() ?? nobody).WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("likes")).WithValue(w.Affinity?.ToString() ?? nobody).WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("changes_of_heart")).WithValue($"{affInfo.Count} - \"the {affInfo.Title}\"").WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("divorces")).WithValue(divorces.ToString()).WithIsInline(true))
                             .AddField(efb => efb.WithName(GetText("gifts")).WithValue(!w.Items.Any() ? "-" : string.Join("\n", w.Items.OrderBy(x => x.Price).GroupBy(x => x.ItemEmoji).Select(x => $"{x.Key} x{x.Count()}"))).WithIsInline(false))
                             .AddField(efb => efb.WithName($"Waifus ({claims.Count})").WithValue(claims.Count == 0 ? nobody : string.Join("\n", claims.OrderBy(x => rng.Next()).Take(30).Select(x => x.Waifu))).WithIsInline(false));

                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
            }
Exemplo n.º 2
0
        public async Task <(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId)
        {
            DivorceResult result;
            TimeSpan?     remaining = null;
            long          amount    = 0;
            WaifuInfo     w         = null;

            using (var uow = _db.UnitOfWork)
            {
                w = uow.Waifus.ByWaifuUserId(targetId);
                var now = DateTime.UtcNow;
                if (w?.Claimer == null || w.Claimer.UserId != user.Id)
                {
                    result = DivorceResult.NotYourWife;
                }
                else if (!_cache.TryAddDivorceCooldown(user.Id, out remaining))
                {
                    result = DivorceResult.Cooldown;
                }
                else
                {
                    amount = w.Price / 2;

                    if (w.Affinity?.UserId == user.Id)
                    {
                        await _cs.AddAsync(w.Waifu.UserId, "Waifu Compensation", amount, gamble : true);

                        w.Price = (int)Math.Floor(w.Price * 0.75f);
                        result  = DivorceResult.SucessWithPenalty;
                    }
                    else
                    {
                        await _cs.AddAsync(user.Id, "Waifu Refund", amount, gamble : true);

                        result = DivorceResult.Success;
                    }
                    var oldClaimer = w.Claimer;
                    w.Claimer = null;

                    uow._context.WaifuUpdates.Add(new WaifuUpdate()
                    {
                        User       = w.Waifu,
                        Old        = oldClaimer,
                        New        = null,
                        UpdateType = WaifuUpdateType.Claimed
                    });
                }

                await uow.CompleteAsync();
            }

            return(w, result, amount, remaining);
        }
Exemplo n.º 3
0
            public async Task WaifuGift(WaifuItem.ItemName item, [Remainder] IUser waifu)
            {
                if (waifu.Id == Context.User.Id)
                {
                    return;
                }

                var itemObj = WaifuItem.GetItem(item, _bc.BotConfig.WaifuGiftMultiplier);

                using (var uow = _db.UnitOfWork)
                {
                    var w = uow.Waifus.ByWaifuUserId(waifu.Id);

                    //try to buy the item first

                    if (!await _cs.RemoveAsync(Context.User.Id, "Bought waifu item", itemObj.Price, gamble: true))
                    {
                        await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencySign).ConfigureAwait(false);

                        return;
                    }
                    if (w == null)
                    {
                        uow.Waifus.Add(w = new WaifuInfo()
                        {
                            Affinity = null,
                            Claimer  = null,
                            Price    = 1,
                            Waifu    = uow.DiscordUsers.GetOrCreate(waifu),
                        });

                        w.Waifu.Username      = waifu.Username;
                        w.Waifu.Discriminator = waifu.Discriminator;
                    }
                    w.Items.Add(itemObj);
                    if (w.Claimer?.UserId == Context.User.Id)
                    {
                        w.Price += itemObj.Price;
                    }
                    else
                    {
                        w.Price += itemObj.Price / 2;
                    }

                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                await ReplyConfirmLocalized("waifu_gift", Format.Bold(item.ToString() + " " + itemObj.ItemEmoji), Format.Bold(waifu.ToString())).ConfigureAwait(false);
            }
Exemplo n.º 4
0
            public async Task WaifuInfo([Remainder] IUser target = null)
            {
                if (target == null)
                {
                    target = Context.User;
                }
                WaifuInfo         w;
                IList <WaifuInfo> claims;
                int divorces = 0;

                using (var uow = DbHandler.UnitOfWork())
                {
                    w        = uow.Waifus.ByWaifuUserId(target.Id);
                    claims   = uow.Waifus.ByClaimerUserId(target.Id);
                    divorces = uow._context.WaifuUpdates.Count(x => x.Old != null &&
                                                               x.Old.UserId == target.Id &&
                                                               x.UpdateType == WaifuUpdateType.Claimed &&
                                                               x.New == null);
                    if (w == null)
                    {
                        uow.Waifus.Add(w = new WaifuInfo()
                        {
                            Affinity = null,
                            Claimer  = null,
                            Price    = 1,
                            Waifu    = uow.DiscordUsers.GetOrCreate(target),
                        });
                    }

                    w.Waifu.Username      = target.Username;
                    w.Waifu.Discriminator = target.Discriminator;
                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                var claimInfo = GetClaimTitle(target.Id);
                var affInfo   = GetAffinityTitle(target.Id);

                var embed = new EmbedBuilder()
                            .WithOkColor()
                            .WithTitle("Waifu " + w.Waifu.ToString() + " - \"the " + claimInfo.Title + "\"")
                            .AddField(efb => efb.WithName("Price").WithValue(w.Price.ToString()).WithIsInline(true))
                            .AddField(efb => efb.WithName("Claimed by").WithValue(w.Claimer?.ToString() ?? "No one").WithIsInline(true))
                            .AddField(efb => efb.WithName("Likes").WithValue(w.Affinity?.ToString() ?? "Nobody").WithIsInline(true))
                            .AddField(efb => efb.WithName("Changes Of Heart").WithValue($"{affInfo.Count} - \"the {affInfo.Title}\"").WithIsInline(true))
                            .AddField(efb => efb.WithName("Divorces").WithValue(divorces.ToString()).WithIsInline(true))
                            .AddField(efb => efb.WithName($"Waifus ({claims.Count})").WithValue(claims.Count == 0 ? "Nobody" : string.Join("\n", claims.Select(x => x.Waifu))).WithIsInline(true));

                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
            }
Exemplo n.º 5
0
        public async Task <bool> GiftWaifuAsync(IUser from, IUser giftedWaifu, WaifuItemModel itemObj)
        {
            if (!await _cs.RemoveAsync(from, "Bought waifu item", itemObj.Price, gamble: true))
            {
                return(false);
            }

            using (var uow = _db.GetDbContext())
            {
                var w = uow.Waifus.ByWaifuUserId(giftedWaifu.Id,
                                                 set => set.Include(x => x.Items)
                                                 .Include(x => x.Claimer));
                if (w == null)
                {
                    uow.Waifus.Add(w = new WaifuInfo()
                    {
                        Affinity = null,
                        Claimer  = null,
                        Price    = 1,
                        Waifu    = uow.DiscordUsers.GetOrCreate(giftedWaifu),
                    });
                }

                w.Items.Add(new WaifuItem()
                {
                    Name      = itemObj.Name.ToLowerInvariant(),
                    ItemEmoji = itemObj.ItemEmoji,
                });

                if (w.Claimer?.UserId == from.Id)
                {
                    w.Price += (int)(itemObj.Price * _gss.Data.Waifu.Multipliers.GiftEffect);
                }
                else
                {
                    w.Price += itemObj.Price / 2;
                }

                await uow.SaveChangesAsync();
            }

            return(true);
        }
Exemplo n.º 6
0
        public async Task <bool> GiftWaifuAsync(ulong from, IUser giftedWaifu, WaifuItem itemObj)
        {
            using (var uow = _db.UnitOfWork)
            {
                var w = uow.Waifus.ByWaifuUserId(giftedWaifu.Id);

                //try to buy the item first

                if (!await _cs.RemoveAsync(from, "Bought waifu item", itemObj.Price, gamble: true))
                {
                    return(false);
                }
                if (w == null)
                {
                    uow.Waifus.Add(w = new WaifuInfo()
                    {
                        Affinity = null,
                        Claimer  = null,
                        Price    = 1,
                        Waifu    = uow.DiscordUsers.GetOrCreate(giftedWaifu),
                    });

                    w.Waifu.Username      = giftedWaifu.Username;
                    w.Waifu.Discriminator = giftedWaifu.Discriminator;
                }
                w.Items.Add(itemObj);
                if (w.Claimer?.UserId == from)
                {
                    w.Price += (int)(itemObj.Price * 0.95);
                }
                else
                {
                    w.Price += itemObj.Price / 2;
                }

                await uow.CompleteAsync();
            }
            return(true);
        }
Exemplo n.º 7
0
        public async Task <int> GiftWaifuAsync(ulong from, IUser giftedWaifu, WaifuItem itemObj)
        {
            var Mosh = 0;

            if (!await _cs.RemoveAsync(from, "Bought waifu item", itemObj.Price, gamble: true))
            {
                return(Mosh);
            }

            using (var uow = _db.UnitOfWork)
            {
                var w = uow.Waifus.ByWaifuUserId(giftedWaifu.Id, set => set.Include(x => x.Items)
                                                 .Include(x => x.Claimer));
                if (w == null)
                {
                    uow.Waifus.Add(w = new WaifuInfo()
                    {
                        Affinity = null,
                        Claimer  = null,
                        Price    = 1,
                        Waifu    = uow.DiscordUsers.GetOrCreate(giftedWaifu),
                    });
                }
                w.Items.Add(itemObj);

                /*if (w.Claimer?.UserId == from)
                 * {
                 *  w.Price += (int)(itemObj.Price * 0.95);
                 * }
                 * else
                 *  w.Price += itemObj.Price / 2;*/
                w.Price += itemObj.Price;
                Mosh     = w.Price;

                await uow.CompleteAsync();
            }
            return(Mosh);
        }
Exemplo n.º 8
0
        public async Task <FullWaifuInfo> GetFullWaifuInfoAsync(IGuildUser target)
        {
            FullWaifuInfo fwi;

            using (var uow = _db.UnitOfWork)
            {
                var w        = uow.Waifus.ByWaifuUserId(target.Id);
                var claims   = uow.Waifus.ByClaimerUserId(target.Id);
                var divorces = uow._context.WaifuUpdates.Count(x => x.Old != null &&
                                                               x.Old.UserId == target.Id &&
                                                               x.UpdateType == WaifuUpdateType.Claimed &&
                                                               x.New == null);
                if (w == null)
                {
                    uow.Waifus.Add(w = new WaifuInfo()
                    {
                        Affinity = null,
                        Claimer  = null,
                        Price    = 1,
                        Waifu    = uow.DiscordUsers.GetOrCreate(target),
                    });
                }
                fwi = new FullWaifuInfo
                {
                    Waifu    = w,
                    Claims   = claims,
                    Divorces = divorces
                };

                w.Waifu.Username      = target.Username;
                w.Waifu.Discriminator = target.Discriminator;
                await uow.CompleteAsync();
            }

            return(fwi);
        }
Exemplo n.º 9
0
            public async Task WaifuClaim(int amount, [Remainder] IUser target)
            {
                if (amount < 50)
                {
                    await ReplyErrorLocalized("waifu_isnt_cheap", 50 + CurrencySign).ConfigureAwait(false);

                    return;
                }

                if (target.Id == Context.User.Id)
                {
                    await ReplyErrorLocalized("waifu_not_yourself").ConfigureAwait(false);

                    return;
                }

                WaifuClaimResult result;
                WaifuInfo        w;
                bool             isAffinity;

                using (var uow = DbHandler.UnitOfWork())
                {
                    w          = uow.Waifus.ByWaifuUserId(target.Id);
                    isAffinity = (w?.Affinity?.UserId == Context.User.Id);
                    if (w == null)
                    {
                        var claimer = uow.DiscordUsers.GetOrCreate(Context.User);
                        var waifu   = uow.DiscordUsers.GetOrCreate(target);
                        if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
                        {
                            result = WaifuClaimResult.NotEnoughFunds;
                        }
                        else
                        {
                            uow.Waifus.Add(w = new WaifuInfo()
                            {
                                Waifu    = waifu,
                                Claimer  = claimer,
                                Affinity = null,
                                Price    = amount
                            });
                            uow._context.WaifuUpdates.Add(new WaifuUpdate()
                            {
                                User       = waifu,
                                Old        = null,
                                New        = claimer,
                                UpdateType = WaifuUpdateType.Claimed
                            });
                            result = WaifuClaimResult.Success;
                        }
                    }
                    else if (isAffinity && amount > w.Price * 0.88f)
                    {
                        if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
                        {
                            result = WaifuClaimResult.NotEnoughFunds;
                        }
                        else
                        {
                            var oldClaimer = w.Claimer;
                            w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
                            w.Price   = amount + (amount / 4);
                            result    = WaifuClaimResult.Success;

                            uow._context.WaifuUpdates.Add(new WaifuUpdate()
                            {
                                User       = w.Waifu,
                                Old        = oldClaimer,
                                New        = w.Claimer,
                                UpdateType = WaifuUpdateType.Claimed
                            });
                        }
                    }
                    else if (amount >= w.Price * 1.1f) // if no affinity
                    {
                        if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
                        {
                            result = WaifuClaimResult.NotEnoughFunds;
                        }
                        else
                        {
                            var oldClaimer = w.Claimer;
                            w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
                            w.Price   = amount;
                            result    = WaifuClaimResult.Success;

                            uow._context.WaifuUpdates.Add(new WaifuUpdate()
                            {
                                User       = w.Waifu,
                                Old        = oldClaimer,
                                New        = w.Claimer,
                                UpdateType = WaifuUpdateType.Claimed
                            });
                        }
                    }
                    else
                    {
                        result = WaifuClaimResult.InsufficientAmount;
                    }


                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (result == WaifuClaimResult.InsufficientAmount)
                {
                    await ReplyErrorLocalized("waifu_not_enough", Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))).ConfigureAwait(false);

                    return;
                }
                if (result == WaifuClaimResult.NotEnoughFunds)
                {
                    await ReplyErrorLocalized("not_enough", CurrencySign).ConfigureAwait(false);

                    return;
                }
                var msg = GetText("waifu_claimed",
                                  Format.Bold(target.ToString()),
                                  amount + CurrencySign);

                if (w.Affinity?.UserId == Context.User.Id)
                {
                    msg += "\n" + GetText("waifu_fulfilled", target, w.Price + CurrencySign);
                }
                await Context.Channel.SendConfirmAsync(Context.User.Mention + msg).ConfigureAwait(false);
            }
Exemplo n.º 10
0
            public async Task Divorce([Remainder] IUser target)
            {
                if (target.Id == Context.User.Id)
                {
                    return;
                }

                DivorceResult result;
                var           difference = TimeSpan.Zero;
                var           amount     = 0;
                WaifuInfo     w          = null;

                using (var uow = DbHandler.UnitOfWork())
                {
                    w = uow.Waifus.ByWaifuUserId(target.Id);
                    var now = DateTime.UtcNow;
                    if (w?.Claimer == null || w.Claimer.UserId != Context.User.Id)
                    {
                        result = DivorceResult.NotYourWife;
                    }
                    else if (divorceCooldowns.AddOrUpdate(Context.User.Id,
                                                          now,
                                                          (key, old) => ((difference = now.Subtract(old)) > _divorceLimit) ? now : old) != now)
                    {
                        result = DivorceResult.Cooldown;
                    }
                    else
                    {
                        amount = w.Price / 2;

                        if (w.Affinity?.UserId == Context.User.Id)
                        {
                            await CurrencyHandler.AddCurrencyAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);

                            w.Price = (int)Math.Floor(w.Price * 0.75f);
                            result  = DivorceResult.SucessWithPenalty;
                        }
                        else
                        {
                            await CurrencyHandler.AddCurrencyAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);

                            result = DivorceResult.Success;
                        }
                        var oldClaimer = w.Claimer;
                        w.Claimer = null;

                        uow._context.WaifuUpdates.Add(new WaifuUpdate()
                        {
                            User       = w.Waifu,
                            Old        = oldClaimer,
                            New        = null,
                            UpdateType = WaifuUpdateType.Claimed
                        });
                    }

                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (result == DivorceResult.SucessWithPenalty)
                {
                    await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + CurrencySign).ConfigureAwait(false);
                }
                else if (result == DivorceResult.Success)
                {
                    await ReplyConfirmLocalized("waifu_divorced_notlike", amount + CurrencySign).ConfigureAwait(false);
                }
                else if (result == DivorceResult.NotYourWife)
                {
                    await ReplyErrorLocalized("waifu_not_yours").ConfigureAwait(false);
                }
                else
                {
                    var remaining = _divorceLimit.Subtract(difference);
                    await ReplyErrorLocalized("waifu_recent_divorce",
                                              Format.Bold(((int)remaining.TotalHours).ToString()),
                                              Format.Bold(remaining.Minutes.ToString())).ConfigureAwait(false);
                }
            }
Exemplo n.º 11
0
        public async Task <(WaifuInfo, bool, WaifuClaimResult)> ClaimWaifuAsync(IUser user, IUser target, int amount)
        {
            var settings = _gss.Data;
            WaifuClaimResult result;
            WaifuInfo        w;
            bool             isAffinity;

            using (var uow = _db.GetDbContext())
            {
                w          = uow.Waifus.ByWaifuUserId(target.Id);
                isAffinity = (w?.Affinity?.UserId == user.Id);
                if (w == null)
                {
                    var claimer = uow.DiscordUsers.GetOrCreate(user);
                    var waifu   = uow.DiscordUsers.GetOrCreate(target);
                    if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
                    {
                        result = WaifuClaimResult.NotEnoughFunds;
                    }
                    else
                    {
                        uow.Waifus.Add(w = new WaifuInfo()
                        {
                            Waifu    = waifu,
                            Claimer  = claimer,
                            Affinity = null,
                            Price    = amount
                        });
                        uow._context.WaifuUpdates.Add(new WaifuUpdate()
                        {
                            User       = waifu,
                            Old        = null,
                            New        = claimer,
                            UpdateType = WaifuUpdateType.Claimed
                        });
                        result = WaifuClaimResult.Success;
                    }
                }
                else if (isAffinity && amount > w.Price * settings.Waifu.Multipliers.CrushClaim)
                {
                    if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
                    {
                        result = WaifuClaimResult.NotEnoughFunds;
                    }
                    else
                    {
                        var oldClaimer = w.Claimer;
                        w.Claimer = uow.DiscordUsers.GetOrCreate(user);
                        w.Price   = amount + (amount / 4);
                        result    = WaifuClaimResult.Success;

                        uow._context.WaifuUpdates.Add(new WaifuUpdate()
                        {
                            User       = w.Waifu,
                            Old        = oldClaimer,
                            New        = w.Claimer,
                            UpdateType = WaifuUpdateType.Claimed
                        });
                    }
                }
                else if (amount >= w.Price * settings.Waifu.Multipliers.NormalClaim) // if no affinity
                {
                    if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
                    {
                        result = WaifuClaimResult.NotEnoughFunds;
                    }
                    else
                    {
                        var oldClaimer = w.Claimer;
                        w.Claimer = uow.DiscordUsers.GetOrCreate(user);
                        w.Price   = amount;
                        result    = WaifuClaimResult.Success;

                        uow._context.WaifuUpdates.Add(new WaifuUpdate()
                        {
                            User       = w.Waifu,
                            Old        = oldClaimer,
                            New        = w.Claimer,
                            UpdateType = WaifuUpdateType.Claimed
                        });
                    }
                }
                else
                {
                    result = WaifuClaimResult.InsufficientAmount;
                }


                await uow.SaveChangesAsync();
            }

            return(w, isAffinity, result);
        }
Exemplo n.º 12
0
            public async Task WaifuClaim(int amount, [Remainder] IUser target)
            {
                if (amount < 50)
                {
                    await Context.Channel.SendErrorAsync($"{Context.User.Mention} No waifu is that cheap. You must pay at least 50{NadekoBot.BotConfig.CurrencySign} to get a waifu, even if their actual value is lower.").ConfigureAwait(false);

                    return;
                }

                if (target.Id == Context.User.Id)
                {
                    await Context.Channel.SendErrorAsync(Context.User.Mention + " You can't claim yourself.").ConfigureAwait(false);

                    return;
                }

                WaifuClaimResult result = WaifuClaimResult.NotEnoughFunds;
                int?      oldPrice      = null;
                WaifuInfo w;
                var       isAffinity = false;

                using (var uow = DbHandler.UnitOfWork())
                {
                    w          = uow.Waifus.ByWaifuUserId(target.Id);
                    isAffinity = (w?.Affinity?.UserId == Context.User.Id);
                    if (w == null)
                    {
                        var claimer = uow.DiscordUsers.GetOrCreate(Context.User);
                        var waifu   = uow.DiscordUsers.GetOrCreate(target);
                        if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
                        {
                            result = WaifuClaimResult.NotEnoughFunds;
                        }
                        else
                        {
                            uow.Waifus.Add(w = new WaifuInfo()
                            {
                                Waifu    = waifu,
                                Claimer  = claimer,
                                Affinity = null,
                                Price    = amount
                            });
                            uow._context.WaifuUpdates.Add(new WaifuUpdate()
                            {
                                User       = waifu,
                                Old        = null,
                                New        = claimer,
                                UpdateType = WaifuUpdateType.Claimed
                            });
                            result = WaifuClaimResult.Success;
                        }
                    }
                    else if (isAffinity && amount >= w.Price * 0.88f)
                    {
                        if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
                        {
                            result = WaifuClaimResult.NotEnoughFunds;
                        }
                        else
                        {
                            var oldClaimer = w.Claimer;
                            w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
                            oldPrice  = w.Price;
                            w.Price   = amount + (amount / 4);
                            result    = WaifuClaimResult.Success;

                            uow._context.WaifuUpdates.Add(new WaifuUpdate()
                            {
                                User       = w.Waifu,
                                Old        = oldClaimer,
                                New        = w.Claimer,
                                UpdateType = WaifuUpdateType.Claimed
                            });
                        }
                    }
                    else if (amount >= w.Price * 1.1f) // if no affinity
                    {
                        if (!await CurrencyHandler.RemoveCurrencyAsync(Context.User.Id, "Claimed Waifu", amount, uow).ConfigureAwait(false))
                        {
                            result = WaifuClaimResult.NotEnoughFunds;
                        }
                        else
                        {
                            var oldClaimer = w.Claimer;
                            w.Claimer = uow.DiscordUsers.GetOrCreate(Context.User);
                            oldPrice  = w.Price;
                            w.Price   = amount;
                            result    = WaifuClaimResult.Success;

                            uow._context.WaifuUpdates.Add(new WaifuUpdate()
                            {
                                User       = w.Waifu,
                                Old        = oldClaimer,
                                New        = w.Claimer,
                                UpdateType = WaifuUpdateType.Claimed
                            });
                        }
                    }
                    else
                    {
                        result = WaifuClaimResult.InsufficientAmount;
                    }


                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (result == WaifuClaimResult.InsufficientAmount)
                {
                    await Context.Channel.SendErrorAsync($"{Context.User.Mention} You must pay {Math.Ceiling(w.Price * (isAffinity ? 0.88f : 1.1f))} or more to claim that waifu!").ConfigureAwait(false);

                    return;
                }
                else if (result == WaifuClaimResult.NotEnoughFunds)
                {
                    await Context.Channel.SendConfirmAsync($"{Context.User.Mention} you don't have {amount}{NadekoBot.BotConfig.CurrencySign}!")
                    .ConfigureAwait(false);
                }
                else
                {
                    var msg = $"{Context.User.Mention} claimed {target.Mention} as their waifu for {amount}{NadekoBot.BotConfig.CurrencySign}!";
                    if (w.Affinity?.UserId == Context.User.Id)
                    {
                        msg += $"\n🎉 Their love is fulfilled! 🎉\n**{target}'s** new value is {w.Price}{NadekoBot.BotConfig.CurrencySign}!";
                    }
                    await Context.Channel.SendConfirmAsync(msg)
                    .ConfigureAwait(false);
                }
            }
Exemplo n.º 13
0
            public async Task Divorce([Remainder] IUser target)
            {
                var channel = (ITextChannel)Context.Channel;

                if (target.Id == Context.User.Id)
                {
                    return;
                }

                var       result     = DivorceResult.NotYourWife;
                TimeSpan  difference = TimeSpan.Zero;
                var       amount     = 0;
                WaifuInfo w          = null;

                using (var uow = DbHandler.UnitOfWork())
                {
                    w = uow.Waifus.ByWaifuUserId(target.Id);
                    var now = DateTime.UtcNow;
                    if (w == null || w.Claimer == null || w.Claimer.UserId != Context.User.Id)
                    {
                        result = DivorceResult.NotYourWife;
                    }
                    else if (_divorceCooldowns.AddOrUpdate(Context.User.Id,
                                                           now,
                                                           (key, old) => ((difference = now.Subtract(old)) > DivorceLimit) ? now : old) != now)
                    {
                        result = DivorceResult.Cooldown;
                    }
                    else
                    {
                        amount = w.Price / 2;

                        if (w.Affinity?.UserId == Context.User.Id)
                        {
                            await CurrencyHandler.AddCurrencyAsync(w.Waifu.UserId, "Waifu Compensation", amount, uow).ConfigureAwait(false);

                            w.Price = (int)Math.Floor(w.Price * 0.75f);
                            result  = DivorceResult.SucessWithPenalty;
                        }
                        else
                        {
                            await CurrencyHandler.AddCurrencyAsync(Context.User.Id, "Waifu Refund", amount, uow).ConfigureAwait(false);

                            result = DivorceResult.Success;
                        }
                        var oldClaimer = w.Claimer;
                        w.Claimer = null;

                        uow._context.WaifuUpdates.Add(new WaifuUpdate()
                        {
                            User       = w.Waifu,
                            Old        = oldClaimer,
                            New        = null,
                            UpdateType = WaifuUpdateType.Claimed
                        });
                    }

                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (result == DivorceResult.SucessWithPenalty)
                {
                    await Context.Channel.SendConfirmAsync($"{Context.User.Mention} You have divorced a waifu who likes you. You heartless monster.\n{w.Waifu} received {amount}{NadekoBot.BotConfig.CurrencySign} as a compensation.").ConfigureAwait(false);
                }
                else if (result == DivorceResult.Success)
                {
                    await Context.Channel.SendConfirmAsync($"{Context.User.Mention} You have divorced a waifu who doesn't like you. You received {amount}{NadekoBot.BotConfig.CurrencySign} back.").ConfigureAwait(false);
                }
                else if (result == DivorceResult.NotYourWife)
                {
                    await Context.Channel.SendErrorAsync($"{Context.User.Mention} That waifu is not yours.").ConfigureAwait(false);
                }
                else
                {
                    var remaining = DivorceLimit.Subtract(difference);
                    await Context.Channel.SendErrorAsync($"{Context.User.Mention} You divorced recently. You must wait **{remaining.Hours} hours and {remaining.Minutes} minutes** to divorce again.").ConfigureAwait(false);
                }
            }
Exemplo n.º 14
0
            public async Task Divorce([Remainder] ulong targetId)
            {
                if (targetId == Context.User.Id)
                {
                    return;
                }

                DivorceResult result;
                TimeSpan?     remaining = null;
                var           amount    = 0;
                WaifuInfo     w         = null;

                using (var uow = _db.UnitOfWork)
                {
                    w = uow.Waifus.ByWaifuUserId(targetId);
                    var now = DateTime.UtcNow;
                    if (w?.Claimer == null || w.Claimer.UserId != Context.User.Id)
                    {
                        result = DivorceResult.NotYourWife;
                    }
                    else if (!_cache.TryAddDivorceCooldown(Context.User.Id, out remaining))
                    {
                        result = DivorceResult.Cooldown;
                    }
                    else
                    {
                        amount = w.Price / 2;

                        if (w.Affinity?.UserId == Context.User.Id)
                        {
                            await _cs.AddAsync(w.Waifu.UserId, "Waifu Compensation", amount, gamble : true).ConfigureAwait(false);

                            w.Price = (int)Math.Floor(w.Price * 0.75f);
                            result  = DivorceResult.SucessWithPenalty;
                        }
                        else
                        {
                            await _cs.AddAsync(Context.User.Id, "Waifu Refund", amount, gamble : true).ConfigureAwait(false);

                            result = DivorceResult.Success;
                        }
                        var oldClaimer = w.Claimer;
                        w.Claimer = null;

                        uow._context.WaifuUpdates.Add(new WaifuUpdate()
                        {
                            User       = w.Waifu,
                            Old        = oldClaimer,
                            New        = null,
                            UpdateType = WaifuUpdateType.Claimed
                        });
                    }

                    await uow.CompleteAsync().ConfigureAwait(false);
                }

                if (result == DivorceResult.SucessWithPenalty)
                {
                    await ReplyConfirmLocalized("waifu_divorced_like", Format.Bold(w.Waifu.ToString()), amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
                }
                else if (result == DivorceResult.Success)
                {
                    await ReplyConfirmLocalized("waifu_divorced_notlike", amount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
                }
                else if (result == DivorceResult.NotYourWife)
                {
                    await ReplyErrorLocalized("waifu_not_yours").ConfigureAwait(false);
                }
                else
                {
                    await ReplyErrorLocalized("waifu_recent_divorce",
                                              Format.Bold(((int)remaining?.TotalHours).ToString()),
                                              Format.Bold(remaining?.Minutes.ToString())).ConfigureAwait(false);
                }
            }
Exemplo n.º 15
0
        public async Task <(WaifuInfo, bool, WaifuClaimResult)> ClaimWaifuAsync(IUser user, IUser target, int amount, int count)
        {
            WaifuClaimResult result;
            WaifuInfo        w;
            bool             isAffinity;

            using (var uow = _db.UnitOfWork)
            {
                w          = uow.Waifus.ByWaifuUserId(target.Id);
                isAffinity = (w?.Affinity?.UserId == user.Id);
                if (w == null)
                {
                    var waifu = uow.DiscordUsers.GetOrCreate(target);
                    uow.Waifus.Add(w = new WaifuInfo()
                    {
                        Waifu      = waifu,
                        Affinity   = null,
                        Claimer    = null,
                        Price      = 1,
                        Immune     = false,
                        Reputation = 0
                    });
                }
                if (w.Immune == false)
                {
                    if (count < 7)
                    {
                        if (w == null)
                        {
                            var claimer = uow.DiscordUsers.GetOrCreate(user);
                            var waifu   = uow.DiscordUsers.GetOrCreate(target);
                            if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
                            {
                                result = WaifuClaimResult.NotEnoughFunds;
                            }
                            else
                            {
                                uow.Waifus.Add(w = new WaifuInfo()
                                {
                                    Waifu    = waifu,
                                    Claimer  = claimer,
                                    Affinity = null,
                                    Price    = amount
                                });
                                uow._context.WaifuUpdates.Add(new WaifuUpdate()
                                {
                                    User       = waifu,
                                    Old        = null,
                                    New        = claimer,
                                    UpdateType = WaifuUpdateType.Claimed
                                });
                                result = WaifuClaimResult.Success;
                            }
                        }
                        else if (isAffinity && amount > w.Price * 0.88f)
                        {
                            if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
                            {
                                result = WaifuClaimResult.NotEnoughFunds;
                            }
                            else
                            {
                                var oldClaimer = w.Claimer;
                                w.Claimer = uow.DiscordUsers.GetOrCreate(user);
                                w.Price   = amount + (amount / 4);
                                result    = WaifuClaimResult.Success;

                                uow._context.WaifuUpdates.Add(new WaifuUpdate()
                                {
                                    User       = w.Waifu,
                                    Old        = oldClaimer,
                                    New        = w.Claimer,
                                    UpdateType = WaifuUpdateType.Claimed
                                });
                            }
                        }
                        else if (amount >= w.Price * 1.1f) // if no affinity
                        {
                            if (!await _cs.RemoveAsync(user.Id, "Claimed Waifu", amount, gamble: true))
                            {
                                result = WaifuClaimResult.NotEnoughFunds;
                            }
                            else
                            {
                                var oldClaimer = w.Claimer;
                                w.Claimer = uow.DiscordUsers.GetOrCreate(user);
                                w.Price   = amount;
                                result    = WaifuClaimResult.Success;

                                uow._context.WaifuUpdates.Add(new WaifuUpdate()
                                {
                                    User       = w.Waifu,
                                    Old        = oldClaimer,
                                    New        = w.Claimer,
                                    UpdateType = WaifuUpdateType.Claimed
                                });
                            }
                        }
                        else
                        {
                            result = WaifuClaimResult.InsufficientAmount;
                        }
                    }
                    else
                    {
                        result = WaifuClaimResult.MaxCount;
                    }
                }
                else
                {
                    result = WaifuClaimResult.Immune;
                }

                await uow.CompleteAsync();
            }

            return(w, isAffinity, result);
        }