Пример #1
0
        /// <summary>
        /// Transfers credits from sender to target receiver
        /// </summary>
        /// <param name="context">Sender, typically the one who initiated the command</param>
        /// <param name="targetUser">A @mention of the receiver</param>
        /// <param name="amount">Amount to send to the receiver</param>
        /// <returns></returns>
        public static async Task TransferCredits(SocketCommandContext context, string targetUser, long amount)
        {
            if (amount <= 0)
            {
                await context.Message.Author.SendMessageAsync(UserInteraction.BoldUserName(context) + ", you must send **1 or more** Credits**");
            }
            else if (GetUserCredits(context) - amount < 0)
            {
                await context.Message.Author.SendMessageAsync(UserInteraction.BoldUserName(context) + ", you do not have enough money to send || **" + UserBankingHandler.CreditCurrencyFormatter(GetUserCredits(context)) + " Credits**");
            }
            else
            {
                long taxAmount = UserCreditsTaxHandler.TaxCollector(amount);

                var recipient = context.Guild.GetUser(MentionUtils.ParseUser(targetUser));

                //Check if recipient has a profile
                UserBankingHandler.CheckIfUserCreditProfileExists(recipient);

                //Subtract money from sender
                AddCredits(context, -amount);

                //AddCredits credits to receiver
                AddCredits(context, MentionUtils.ParseUser(targetUser), amount - taxAmount);

                //Send receipts to both parties
                var embedBuilder = new EmbedBuilder()
                                   .WithTitle("Transaction Receipt")
                                   .WithDescription("​")
                                   .WithColor(new Color(68, 199, 40))
                                   .WithFooter(footer => {
                })
                                   .WithAuthor(author => {
                    author
                    .WithName("Duck Banking Inc.")
                    .WithIconUrl("https://freeiconshop.com/wp-content/uploads/edd/bank-flat.png");
                })
                                   .AddInlineField("Sender", context.Message.Author.ToString().Substring(0, context.Message.Author.ToString().Length - 5))
                                   .AddInlineField("Id", context.Message.Author.Id)
                                   .AddInlineField("Total Amount", $"-{UserBankingHandler.CreditCurrencyFormatter(amount)}")

                                   .AddInlineField("Recipient", recipient.ToString().Substring(0, recipient.ToString().Length - 5))
                                   .AddInlineField("​", recipient.Id)
                                   .AddInlineField("​", UserBankingHandler.CreditCurrencyFormatter(amount))

                                   .AddInlineField("​", "​")
                                   .AddInlineField("​", "​")
                                   .AddInlineField("Deductions", $"{UserBankingHandler.CreditCurrencyFormatter(taxAmount)} ({double.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")) * 100}% Tax) \n \n -------------- \n {UserBankingHandler.CreditCurrencyFormatter(amount - taxAmount)}");

                var embed = embedBuilder.Build();

                await context.Message.Author.SendMessageAsync("", embed : embed).ConfigureAwait(false);

                await recipient.SendMessageAsync("", embed : embed).ConfigureAwait(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Adds input amount to user balance
        /// </summary>
        /// <param name="Context">Used to determine channel to send messages to if necessary</param>
        /// <param name="guildID">Guild ID where the target user is in</param>
        /// <param name="userID">Target user ID</param>
        /// <param name="addAmount">Amount to add</param>
        /// <param name="deductTaxes">Whether or not deduct taxes from the add amount, tax rate is set in FinaceConfigValues</param>
        /// <returns></returns>
        public static bool AddCredits(SocketCommandContext Context, ulong userID, long addAmount, bool deductTaxes = false)
        {
            //Get user credits
            var userStorage = UserDataManager.GetUserStorage();

            //Check if user has sufficient credits
            if (GetUserCredits(Context) + addAmount > 0)
            {
                //Calculate new credits
                long userCreditsNew = 0;
                if (deductTaxes == true)
                {
                    userCreditsNew = userStorage.UserInfo[userID].UserBankingStorage.Credit + addAmount - UserCreditsTaxHandler.TaxCollector(addAmount);
                }
                else if (deductTaxes == false)
                {
                    userCreditsNew = userStorage.UserInfo[userID].UserBankingStorage.Credit + addAmount;
                }

                userStorage.UserInfo[userID].UserBankingStorage.Credit = userCreditsNew;

                //Write new credits amount
                UserDataManager.WriteUserStorage(userStorage);

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// Adds input amount to user balance
        /// </summary>
        /// <param name="context">This is the user, typically the sender</param>
        /// <param name="addAmount">Amount to add</param>
        /// <param name="deductTaxes">Whether or not deduct taxes from the add amount, tax rate is set in FinanceConfigValues</param>
        /// <returns></returns>
        public static bool AddCredits(SocketCommandContext context, long addAmount, bool deductTaxes = false)
        {
            //Get user credit storage
            var userStorage = UserDataManager.GetUserStorage();

            //Check if user has sufficient credits
            if (GetUserCredits(context) + addAmount > 0)
            {
                //Calculate new credits
                long userCreditsNew = 0;
                if (deductTaxes == true)
                {
                    userCreditsNew = userStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit + addAmount - UserCreditsTaxHandler.TaxCollector(addAmount);
                }
                else if (deductTaxes == false)
                {
                    userCreditsNew = userStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit + addAmount;
                }

                userStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit = userCreditsNew;

                //Write new credits amount
                UserDataManager.WriteUserStorage(userStorage);

                return(true);
            }
            else
            {
                //False to indicate that user does not have enough credits to be deducted
                return(false);
            }
        }