/// <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); } }
public static async Task <long> TaxCollectorAsync(SocketCommandContext Context, ulong guildID, ulong userID, long inputCredits, string sendMessage) { var guild = Context.Client.GetGuild(guildID); var user = guild.GetUser(userID); double taxSubtractions = inputCredits * double.Parse(SettingsManager.RetrieveFromConfigFile("taxRate"));; if (taxSubtractions < 0) { taxSubtractions = 0; } long roundedTaxSubtractions = Convert.ToInt64(taxSubtractions); await user.SendMessageAsync(sendMessage + " || A total of **" + UserBankingHandler.CreditCurrencyFormatter(roundedTaxSubtractions) + " Credits** was taken off as tax"); return(roundedTaxSubtractions); }
public static async Task <long> TaxCollectorAsync(SocketCommandContext Context, long inputCredits, string sendMessage) { double taxSubtractions = inputCredits * double.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")); if (taxSubtractions < 0) { taxSubtractions = 0; } long roundedTaxSubtractions = Convert.ToInt64(taxSubtractions); await Context.Message.Channel.SendMessageAsync(sendMessage + " || A total of **" + UserBankingHandler.CreditCurrencyFormatter(roundedTaxSubtractions) + " Credits** was taken off as tax"); return(roundedTaxSubtractions); }
/// <summary> /// Allows the user to pay back their credits borrowed /// </summary> /// <param name="context">Invoke data for the user</param> /// <param name="returnAmount">Amount to return for the user</param> /// <returns></returns> public static async Task ReturnCredits(SocketCommandContext context, long returnAmount) { if (returnAmount > GetUserCreditsDebt(context)) { await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you do not owe **{UserBankingHandler.CreditCurrencyFormatter(returnAmount)} Credits** || **{UserBankingHandler.CreditCurrencyFormatter(GetUserCreditsDebt(context))} Credits**"); } else if (returnAmount <= 0) { await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you have to pay back **1 or more** Credits"); } else if (returnAmount > UserCreditsHandler.GetUserCredits(context)) { await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you do not have enough credits to pay back || **{UserCreditsHandler.GetUserCredits(context)}** Credits"); } else { //Subtract from debt counter AddDebt(context, -returnAmount); //Subtract credits to user UserCreditsHandler.AddCredits(context, -returnAmount); //Send receipt await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you paid back **{UserBankingHandler.CreditCurrencyFormatter(returnAmount)} Credits**"); } }
/// <summary> /// Allows the user to borrow credits /// </summary> /// <param name="context">Invoke data for the user</param> /// <param name="borrowAmount">Amount to borrow for the user</param> /// <returns></returns> public static async Task BorrowCredits(SocketCommandContext context, long borrowAmount) { if (GetUserCreditsDebt(context) + borrowAmount > long.Parse(SettingsManager.RetrieveFromConfigFile("maxBorrow"))) { await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you have exceeded your credit limit of **{UserBankingHandler.CreditCurrencyFormatter(long.Parse(SettingsManager.RetrieveFromConfigFile("maxBorrow")))} Credits**"); } else if (borrowAmount <= 0) { await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you have to borrow **1 or more** Credits"); } else { //Add to debt counter AddDebt(context, borrowAmount); //Add credits to user UserCreditsHandler.AddCredits(context, borrowAmount); //Send receipt await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you borrowed **{UserBankingHandler.CreditCurrencyFormatter(borrowAmount)} Credits**"); } }