Exemplo n.º 1
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)
            {
            }
        }
Exemplo n.º 2
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");
            }
        }
Exemplo n.º 3
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");
            }
        }
        private static void AddSkinFieldEntry(List <UserSkinEntry> foundUserSkins)
        {
            var rootWeaponSkin = CsgoDataHandler.GetRootWeaponSkin();

            //For every item belonging to sender
            foreach (var item in foundUserSkins)
            {
                //Find skin entry info
                foreach (var storageSkinEntry in rootWeaponSkin.ItemsList.Values)
                {
                    //Filter by market hash name
                    //LESSON LEARNED: Decode unicode before processing them to avoid them not being recognised!!!!!!!111!!
                    if (UnicodeLiteralConverter.DecodeToNonAsciiCharacters(storageSkinEntry.Classid) == UnicodeLiteralConverter.DecodeToNonAsciiCharacters(item.ClassId))
                    {
                        string skinQualityEmote = GetEmoteBySkinRarity(storageSkinEntry.Rarity, storageSkinEntry.WeaponType);

                        //Add skin entry
                        try
                        {
                            Emote emote = Emote.Parse(skinQualityEmote);

                            //Add skin entry to list
                            embedFieldsMaster.Add(emote + " " + storageSkinEntry.Name);


                            //Filter and Add skin price entry to list
                            embedPriceFieldsMaster.Add(emote + " " + storageSkinEntry.Price.AllTime.Average);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Source);
                        }
                    }
                }
            }
        }
        public static async Task DisplayCsgoItemStatistics(SocketCommandContext context, string filterString)
        {
            //Get skin data
            var rootWeaponSkin = CsgoDataHandler.GetRootWeaponSkin();

            try
            {
                //Find item equal to filter string
                var selectedRootWeaponSkin = rootWeaponSkin.ItemsList.Values.Where(s => s.Name == filterString).FirstOrDefault();

                long weaponSkinPrice = Convert.ToInt64(selectedRootWeaponSkin.Price.AllTime.Average);
                //Add tax markup for market item
                weaponSkinPrice += Convert.ToInt32(weaponSkinPrice * float.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")));


                //Send embed
                var embedBuilder = new EmbedBuilder()
                                   .WithColor(new Color(Convert.ToUInt32(selectedRootWeaponSkin.RarityColor, 16)))
                                   .WithFooter(footer =>
                {
                    footer
                    .WithText("Sent by " + context.Message.Author.ToString())
                    .WithIconUrl(context.Message.Author.GetAvatarUrl());
                })
                                   .WithAuthor(author =>
                {
                    author
                    .WithName("Item Info")
                    .WithIconUrl("https://i.redd.it/1s0j5e4fhws01.png");
                })
                                   .AddField(selectedRootWeaponSkin.Name, $"Market Value: {weaponSkinPrice}")
                                   .WithImageUrl("https://steamcommunity.com/economy/image/" + selectedRootWeaponSkin.IconUrlLarge);

                var embed = embedBuilder.Build();

                await context.Message.Channel.SendMessageAsync(" ", embed : embed).ConfigureAwait(false);
            }
            catch (Exception)
            {
                //Send embed
                var embedBuilder = new EmbedBuilder()
                                   .WithColor(new Color(0, 200, 0))
                                   .WithFooter(footer =>
                {
                    footer
                    .WithText("Sent by " + context.Message.Author.ToString())
                    .WithIconUrl(context.Message.Author.GetAvatarUrl());
                })
                                   .WithAuthor(author =>
                {
                    author
                    .WithName("Item Info")
                    .WithIconUrl("https://i.redd.it/1s0j5e4fhws01.png");
                })
                                   .AddField("The selected item could not be found", "Broaden your search parameters and try again");

                var embed = embedBuilder.Build();

                await context.Message.Channel.SendMessageAsync(" ", embed : embed).ConfigureAwait(false);
            }
        }
        public static PaginatedMessage GetCsgoMarketInventory(SocketCommandContext context, string filterString)
        {
            string botCommandPrefix = CommandGuildPrefixManager.GetGuildCommandPrefix(context);

            //Get skin data
            var rootWeaponSkin = CsgoDataHandler.GetRootWeaponSkin();

            List <string> filteredRootWeaponSkin      = new List <string>();
            List <string> filteredRootWeaponSkinPrice = new List <string>();

            try
            {
                //Filter rootWeaponSkin to those with a price found in rootWeaponSkinPrice
                foreach (var skin in rootWeaponSkin.ItemsList.Values)
                {
                    //If filter string is not null, filter market results by user filter string
                    if ((!string.IsNullOrEmpty(filterString) && skin.Name.ToLower().Contains(filterString.ToLower())) || (string.IsNullOrEmpty(filterString)))
                    {
                        string skinQualityEmote = GetEmoteBySkinRarity(skin.Rarity, skin.WeaponType);

                        //Add skin entry
                        try
                        {
                            Emote emote = Emote.Parse(skinQualityEmote);

                            //Add weapon skin
                            filteredRootWeaponSkin.Add(emote + " " + skin.Name);

                            //Add tax markup for market item
                            long weaponSkinValue = Convert.ToInt64(skin.Price.AllTime.Average);
                            weaponSkinValue += Convert.ToInt64(weaponSkinValue * float.Parse(SettingsManager.RetrieveFromConfigFile("taxRate")));

                            //Add weapon skin price
                            filteredRootWeaponSkinPrice.Add(emote + " " + weaponSkinValue.ToString());
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            //Configurate paginated message
            var paginationConfig = new PaginationConfig
            {
                AuthorName = "CS:GO Market",
                AuthorURL  = context.Message.Author.GetAvatarUrl(),

                Description = $"Current skin market, to buy skins, use `{botCommandPrefix} cs buy [name]` \n use `{botCommandPrefix} cs market [name]` to filter skins by name \n use `{botCommandPrefix} cs info [name]` to preview skins",

                DefaultFieldHeader      = "Unable to find specified weapon skin!",
                DefaultFieldDescription = $"Broaden your search parameters and try again",

                Field1Header = "Item Name",
                Field2Header = "Price",
            };

            var paginationManager = new PaginationManager();

            //Generate paginated message
            var pager = paginationManager.GeneratePaginatedMessage(filteredRootWeaponSkin, filteredRootWeaponSkinPrice, paginationConfig);

            return(pager);
        }
Exemplo n.º 7
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);
            }
        }