Example #1
0
        public async Task TransferCurrency(double amount, string c, IGuildUser user)
        {
            if (amount == 0)
            {
                await Context.Channel.SendMessageAsync($"Wow you gave nothing to {user.Nickname ?? user.Username},what are you Dutch, you greedy bastard");

                return;
            }

            if (amount < 0)
            {
                await Context.Channel.SendMessageAsync($"You can't transfer a negative amount to {user.Nickname ?? user.Username}, greedy stealing bastard.");

                return;
            }

            EntityUser euO = _userRepo.GetByID(Context.User.Id);

            if (euO == null)
            {
                await ErrorUserDoesntExistInSystem();

                return;
            }

            if (user.IsBot)
            {
                await Context.Channel.SendMessageAsync("Why would you transfer money to a bot?");

                return;
            }

            EntityUser euT = _userRepo.GetByID(user.Id);

            if (euT == null)
            {
                await ErrorOtherUserDoesntExistInSystem();

                return;
            }

            string[] names         = Enum.GetNames(typeof(CurrencyEnum));
            var      curToTransfer = names.SingleOrDefault(n => n.ToLower().StartsWith(c.ToLower()));

            if (curToTransfer == null)
            {
                var em = await CurrencyEmbedBuilder.MakeCurrencyError(names, Context);

                await Context.Channel.SendMessageAsync(embed : em.Build());

                return;
            }

            CurrencyEnum cu = (CurrencyEnum)Enum.Parse(typeof(CurrencyEnum), curToTransfer);

            if (euO.GetCurrencyAmount(cu) < amount)
            {
                await Context.Channel.SendMessageAsync($"You're {Math.Round((amount - euO.GetCurrencyAmount(cu)), 2)} " +
                                                       $"{cu} short to transfer this amount");

                return;
            }

            euO.RemoveAmount(cu, amount);
            euT.AddAmount(cu, amount);
            _userRepo.SaveChanges();

            var emb = await CurrencyEmbedBuilder.GetTransferEmbed(Context, euT, euO, cu, amount);

            await Context.Channel.SendMessageAsync(embed : emb.Build());
        }