Beispiel #1
0
        public static async Task <EmbedBuilder> GetTransferEmbed(ICommandContext context, EntityUser eu, EntityUser own, CurrencyEnum cu, double amount)
        {
            IGuildUser owner      = context.User as IGuildUser;
            IGuildUser transferee = await context.Guild.GetUserAsync(eu.Id);

            string ownerName    = owner.Nickname ?? owner.Username;
            string transferName = transferee.Nickname ?? transferee.Username;

            EmbedBuilder emb = new EmbedBuilder()
            {
                Color        = Color.Teal,
                Title        = $"Transferred {amount.RoundDownTwoDecimals()} {cu} succesfully",
                Footer       = await EmbedBuilderFunctions.AddFooter(context),
                ThumbnailUrl = "https://static.thenounproject.com/png/175569-200.png"
            };

            var desc = $"{ownerName} succesfully transferred {amount} {cu} to {transferName}";

            emb.Description = desc;
            emb.WithCurrentTimestamp();

            emb.AddField($"{ownerName}s Balance", $"\t{own.GetCurrencyAmount(CurrencyEnum.Complexity).RoundDownTwoDecimals()}🚀(C)\t"
                         + $"{own.GetCurrencyAmount(CurrencyEnum.Entropy).RoundDownTwoDecimals()}🌕(E)", false);

            emb.AddField($"{transferName}s Balance", $"\t{eu.GetCurrencyAmount(CurrencyEnum.Complexity).RoundDownTwoDecimals()}🚀(C)\t"
                         + $"{eu.GetCurrencyAmount(CurrencyEnum.Entropy).RoundDownTwoDecimals()}🌕(E)", false);

            return(emb);
        }
        public async Task TradeCurrency(double amount, string cur1, string cur2)
        {
            if (amount <= 0)
            {
                await Context.Channel.SendMessageAsync("You can't exchange  an invalid amount good try :^)");

                return;
            }

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

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

                return;
            }

            string[] names      = Enum.GetNames(typeof(CurrencyEnum));
            var      curToTrade = names.SingleOrDefault(n => n.ToLower().StartsWith(cur1.ToLower()));
            var      curConvert = names.SingleOrDefault(n => n.ToLower().StartsWith(cur2.ToLower()));

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

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

                return;
            }

            CurrencyEnum curr1 = (CurrencyEnum)Enum.Parse(typeof(CurrencyEnum), curToTrade);

            if (eu.GetCurrencyAmount(curr1) < amount)
            {
                await Context.Channel.SendMessageAsync($"You're {amount - Math.Round(eu.GetCurrencyAmount(curr1), 2)}"
                                                       + $" {curr1} short for that exchange.");

                return;
            }

            CurrencyEnum curr2 = (CurrencyEnum)Enum.Parse(typeof(CurrencyEnum), curConvert);

            ConversionRate cr1 = (ConversionRate)Enum.Parse(typeof(ConversionRate), $"{curToTrade}To{curConvert}");
            ConversionRate cr2 = (ConversionRate)Enum.Parse(typeof(ConversionRate), $"{curConvert}To{curToTrade}");

            var rate      = (((double)(int)cr2) / ((double)(int)cr1));
            var addAmount = rate * amount;

            eu.RemoveAmount(curr1, amount);
            eu.AddAmount(curr2, addAmount);
            _userRepo.SaveChanges();

            var embed = await CurrencyEmbedBuilder.MakeTradeEmbed(addAmount, amount, Context, curr2, curr1);

            await Context.Channel.SendMessageAsync(embed : embed.Build());
        }
Beispiel #3
0
        public static async Task <EmbedBuilder> MakeBalanceEmbed(ICommandContext context, EntityUser eu)
        {
            var user = await context.Guild.GetUserAsync(eu.Id);

            EmbedBuilder emb = new EmbedBuilder()
            {
                Color        = Color.Teal,
                Title        = $"Balance for {user.Nickname ?? user.Username}",
                Footer       = await EmbedBuilderFunctions.AddFooter(context),
                ThumbnailUrl = user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl(),
                Description  = $"Current balance:\t{eu.GetCurrencyAmount(CurrencyEnum.Complexity).RoundDownTwoDecimals()}🚀(C)\t "
                               + $"{eu.GetCurrencyAmount(CurrencyEnum.Entropy).RoundDownTwoDecimals()}🌕(E)"
            };

            emb.WithCurrentTimestamp();
            return(emb);
        }
Beispiel #4
0
        public static async Task <EmbedBuilder> MakeRedeemEmbed(ICommandContext context, EntityUser eu, double amount)
        {
            var user = context.User as IGuildUser;

            amount = Math.Round(amount, 2);

            EmbedBuilder emb = new EmbedBuilder()
            {
                Color        = Color.Teal,
                Title        = $"{user.Nickname ?? user.Username} has redeemed {amount} Entropy",
                Footer       = await EmbedBuilderFunctions.AddFooter(context),
                ThumbnailUrl = user.GetAvatarUrl() ?? user.GetDefaultAvatarUrl(),
                Description  = $"Redeemed {amount} Entropy \n" +
                               $"Current balance:\t{eu.GetCurrencyAmount(CurrencyEnum.Complexity).RoundDownTwoDecimals()}🚀(C)\t "
                               + $"{eu.GetCurrencyAmount(CurrencyEnum.Entropy).RoundDownTwoDecimals()}🌕(E)"
            };

            return(emb);
        }
        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());
        }