Example #1
0
        public static async Task UserGambling(SocketCommandContext context, SocketMessage message, long gambleAmount)
        {
            //Tell off the user if they are trying to gamble 0 dollars
            if (gambleAmount <= 0)
            {
                await message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", Quack, you have to gamble **1 or more** credits");
            }
            else
            {
                //Get user credits to list
                var userCreditStorage = UserDataManager.GetUserStorage();

                //Money subtractor
                if ((userCreditStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit - gambleAmount) < 0)
                {
                    await message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", you broke quack, you do not have enough credits || **" + UserBankingHandler.CreditCurrencyFormatter(userCreditStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit) + " Credits**");
                }
                else
                {
                    //Calculate outcome (userCredits - amountGambled + AmountReturned)
                    long returnAmount = CalculateUserGamblingOutcome(gambleAmount);

                    long userReturnAmount = userCreditStorage.UserInfo[context.Message.Author.Id].UserBankingStorage.Credit - gambleAmount + returnAmount;

                    //Send outcome & calculate taxes
                    //Write credits to file
                    UserCreditsHandler.SetCredits(
                        context,
                        userReturnAmount - await UserCreditsTaxHandler.TaxCollectorAsync(context, returnAmount, UserInteraction.BoldUserName(context) + $", you gambled **{UserBankingHandler.CreditCurrencyFormatter(gambleAmount)} credits** and made **{UserBankingHandler.CreditCurrencyFormatter(returnAmount)} credits**"));
                }
            }
        }
        /// <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**");
            }
        }
Example #3
0
        //Daily
        public static async Task GiveDailyCreditsAsync(SocketCommandContext context)
        {
            //Get user storage
            var userStorage = UserDataManager.GetUserStorage();

            //If 24 hours has passed
            if (userStorage.UserInfo[context.Message.Author.Id].UserDailyLastUseStorage.DateTime.AddHours(24) < DateTime.UtcNow)
            {
                //Add credits
                UserCreditsHandler.AddCredits(context, long.Parse(SettingsManager.RetrieveFromConfigFile("dailyAmount")));

                //Write last use date
                userStorage.UserInfo[context.Message.Author.Id].UserDailyLastUseStorage.DateTime = DateTime.UtcNow;


                //Write new credits and last redeem date to file
                userStorage = UserDataManager.GetUserStorage();
                userStorage.UserInfo[context.Message.Author.Id].UserDailyLastUseStorage.DateTime = DateTime.UtcNow;
                UserDataManager.WriteUserStorage(userStorage);


                //Send channel message confirmation
                await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", you have redeemed your daily **" + UserBankingHandler.CreditCurrencyFormatter(long.Parse(SettingsManager.RetrieveFromConfigFile("dailyAmount"))) + " Credits!**");
            }
            else
            {
                await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", you quacker, it has not yet been 24 hours since you last redeemed");
            }
        }
Example #4
0
        public static async Task SellAllInventoryItemAsync(SocketCommandContext Context)
        {
            //Get price data
            var rootSkinData = CsgoDataHandler.GetRootWeaponSkin();
            var userSkin     = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

            try
            {
                long weaponSkinValue = GetItemValue(userSkin.UserSkinEntries, rootSkinData);

                //Give user credits
                UserCreditsHandler.AddCredits(Context, weaponSkinValue, true);

                //Remove skin from inventory
                var filteredUserSkinEntries = userSkin.UserSkinEntries.Where(s => s.OwnerID == Context.Message.Author.Id).Where(s => s.OwnerID != Context.Message.Author.Id).ToList();

                //Write to file
                WriteUserSkinDataToFile(filteredUserSkinEntries);

                //Send receipt
                await Context.Channel.SendMessageAsync(
                    UserInteraction.BoldUserName(Context) + $", you sold your inventory" +
                    $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits** " +
                    $"| A total of **{UserBankingHandler.CreditCurrencyFormatter(UserCreditsTaxHandler.TaxCollector(weaponSkinValue))} Credits was taken off as tax**");
            }
            catch (Exception)
            {
            }
        }
Example #5
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);
            }
        }
Example #6
0
            public async Task ChangeGuildCommandPrefixAsync([Remainder] string input)
            {
                //Find guild id
                var chnl = Context.Channel as SocketGuildChannel;

                //Make sure invoker is owner of guild
                if (chnl.Guild.OwnerId == Context.Message.Author.Id)
                {
                    CommandGuildPrefixManager.ChangeGuildCommandPrefix(Context, input);
                    await Context.Channel.SendMessageAsync(UserInteraction.BoldUserName(Context) + $", server prefix has successfully been changed to `{CommandGuildPrefixManager.GetGuildCommandPrefix(Context)}`");
                }
                //Otherwise send error
                else
                {
                    await Context.Channel.SendMessageAsync(UserInteraction.BoldUserName(Context) + ", only the server owner may invoke this command");
                }
            }
Example #7
0
        public static async Task SellAllSelectedInventoryItemAsync(SocketCommandContext Context, string itemMarketHash)
        {
            //Get skin data
            var rootSkinData = CsgoDataHandler.GetRootWeaponSkin();
            var userSkin     = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

            try
            {
                //Find ALL user selected items, make sure it is owned by user
                var selectedSkinToSell = userSkin.UserSkinEntries
                                         .Where(s => s.MarketName.ToLower().Contains(itemMarketHash.ToLower()))
                                         .Where(s => s.OwnerID == Context.Message.Author.Id).ToList();

                //Get item prices
                long weaponSkinValue = GetItemValue(selectedSkinToSell, rootSkinData);

                //Give user credits
                UserCreditsHandler.AddCredits(Context, weaponSkinValue, true);

                //Remove skin from inventory
                List <string> filterUserSkinNames = new List <string>();
                foreach (var item in selectedSkinToSell)
                {
                    //Remove items that were selected to be sold
                    userSkin.UserSkinEntries.Remove(item);

                    filterUserSkinNames.Add(item.MarketName);
                }

                //Write to file
                WriteUserSkinDataToFile(userSkin);

                //Send receipt
                await Context.Channel.SendMessageAsync(
                    UserInteraction.BoldUserName(Context) + $", you sold your \n`{string.Join("\n", filterUserSkinNames)}`" +
                    $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits** " +
                    $"| A total of **{UserBankingHandler.CreditCurrencyFormatter(UserCreditsTaxHandler.TaxCollector(weaponSkinValue))} Credits was taken off as tax**");
            }
            catch (Exception)
            {
                //Send error if user does not have item
                await Context.Channel.SendMessageAsync($"**{Context.Message.Author.ToString().Substring(0, Context.Message.Author.ToString().Length - 5)}**, you do not have `{itemMarketHash}` in your inventory");
            }
        }
        /// <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**");
            }
        }
Example #9
0
        /// <summary>
        /// Selects the appropriate cs go container to open, user replies with a number corrosponding to the case, the paginator message showing case options will also be deleted
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static async Task SelectOpenCase(SocketCommandContext context, string input, Discord.IUserMessage sentMessage)
        {
            //Delete the pagination message after receiving user input
            await sentMessage.DeleteAsync();


            var continers = CsgoUnboxingHandler.csgoContiners.Containers.Where(c => c.Name != null).ToList();

            //Try to turn user input to string
            int       userInput             = 0;
            Container userSelectedContainer = new Container();

            try
            {
                userInput = int.Parse(input);

                //Get the case user selected
                userSelectedContainer = continers[userInput];
            }
            catch (Exception)
            {
                await context.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + ", Please input a valid number");

                return;
            }

            //Set user case preference
            if (!CsgoUnboxingHandler.userSelectedCase.TryGetValue(context.Message.Author.Id, out var t))
            {
                //If user does not exist, generate and set
                CsgoUnboxingHandler.userSelectedCase.Add(context.Message.Author.Id, userSelectedContainer.Name);
            }
            else
            {
                //If user does exist, only set
                CsgoUnboxingHandler.userSelectedCase[context.Message.Author.Id] = userSelectedContainer.Name;
            }

            await context.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", You set your case to open to **{userSelectedContainer.Name}**");
        }
Example #10
0
        //Sell
        public static async Task SellInventoryItemAsync(SocketCommandContext Context, string itemMarketHash)
        {
            //Get skin data
            var rootWeaponSkin = CsgoDataHandler.GetRootWeaponSkin();
            var rootUserSkin   = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

            try
            {
                //Find user selected item, make sure it is owned by user
                var selectedSkinToSell = rootUserSkin.UserSkinEntries
                                         .Where(s => s.MarketName.ToLower().Contains(itemMarketHash.ToLower()))
                                         .Where(s => s.OwnerID == Context.Message.Author.Id)
                                         .FirstOrDefault();

                //Get item price
                long weaponSkinValue = Convert.ToInt64(rootWeaponSkin.ItemsList.Values.Where(s => s.Name == selectedSkinToSell.MarketName).FirstOrDefault().Price.AllTime.Average);

                //Give user credits
                UserCreditsHandler.AddCredits(Context, weaponSkinValue, true);

                //Remove skin from inventory
                var filteredUserSkinEntries = rootUserSkin.UserSkinEntries.Where(s => s.OwnerID == Context.Message.Author.Id).Where(s => s.ClassId != selectedSkinToSell.ClassId).ToList();

                //Write to file
                WriteUserSkinDataToFile(filteredUserSkinEntries);

                //Send receipt
                await Context.Channel.SendMessageAsync(
                    UserInteraction.BoldUserName(Context) + $", you sold your `{selectedSkinToSell.MarketName}`" +
                    $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits** " +
                    $"| A total of **{UserBankingHandler.CreditCurrencyFormatter(UserCreditsTaxHandler.TaxCollector(weaponSkinValue))} Credits was taken off as tax**");
            }
            catch (Exception)
            {
                //Send error if user does not have item
                await Context.Channel.SendMessageAsync($"**{Context.Message.Author.ToString().Substring(0, Context.Message.Author.ToString().Length - 5)}**, you do not have `{itemMarketHash}` in your inventory");
            }
        }
        public async Task GetBorrowedCreditsAsync()
        {
            long creditsOwed = UserDebtHandler.GetUserCreditsDebt(Context);

            await Context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(Context) + $", you owe **{creditsOwed} Credits**");
        }
Example #12
0
        //Buy
        public static async Task BuyItemFromMarketAsync(SocketCommandContext context, string itemMarketHash)
        {
            //Get skin data
            var rootWeaponSkins = CsgoDataHandler.GetRootWeaponSkin();

            try
            {
                UserSkinEntry selectedMarketSkin = new UserSkinEntry();

                //Get market skin cost
                long weaponSkinValue = Convert.ToInt64(rootWeaponSkins.ItemsList.Values.Where(s => s.Name.ToLower().Contains(itemMarketHash.ToLower())).FirstOrDefault().Price.AllTime.Average);

                //Add tax markup :)
                weaponSkinValue += Convert.ToInt64(weaponSkinValue * float.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")));



                bool userSpecifiedSkinExistsInMarket = false;

                //Make sure skin exists in market
                foreach (var marketSkin in rootWeaponSkins.ItemsList.Values)
                {
                    //If it does exist, get info on it
                    if (marketSkin.Name.ToLower().Contains(itemMarketHash.ToLower()))
                    {
                        userSpecifiedSkinExistsInMarket = true;

                        selectedMarketSkin.ClassId    = marketSkin.Classid;
                        selectedMarketSkin.OwnerID    = context.Message.Author.Id;
                        selectedMarketSkin.UnboxDate  = DateTime.UtcNow;
                        selectedMarketSkin.MarketName = marketSkin.Name;
                    }
                }
                //Send error if skin does not exist
                if (userSpecifiedSkinExistsInMarket == false)
                {
                    await context.Message.Channel.SendMessageAsync(UserInteraction.BoldUserName(context) + $", `{itemMarketHash}` does not exist in the current skin market");
                }
                //Make sure user has enough credits to buy skin
                else if (UserCreditsHandler.GetUserCredits(context) < weaponSkinValue)
                {
                    await context.Message.Channel.SendMessageAsync($"**{context.Message.Author.ToString().Substring(0, context.Message.Author.ToString().Length - 5)}**, you do not have enough credits to buy`{itemMarketHash}` | **{UserCreditsHandler.GetUserCredits(context)} Credits**");
                }
                else
                {
                    //Checks are true, now give user skin and remove credits

                    //Remove user credits
                    UserCreditsHandler.AddCredits(context, -weaponSkinValue, true);

                    //Add skin to inventory
                    var userSkins = XmlManager.FromXmlFile <UserSkinStorageRootobject>(CoreMethod.GetFileLocation("UserSkinStorage.xml"));

                    userSkins.UserSkinEntries.Add(selectedMarketSkin);

                    var filteredUserSkin = new UserSkinStorageRootobject
                    {
                        SkinAmount      = 0,
                        UserSkinEntries = userSkins.UserSkinEntries
                    };

                    XmlManager.ToXmlFile(filteredUserSkin, CoreMethod.GetFileLocation("UserSkinStorage.xml"));

                    //Send receipt
                    await context.Channel.SendMessageAsync(
                        UserInteraction.BoldUserName(context) + $", you bought`{selectedMarketSkin.MarketName}`" +
                        $" for **{UserBankingHandler.CreditCurrencyFormatter(weaponSkinValue)} Credits**");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }