Exemple #1
0
        public void AddItemsToList()
        {
            List <ItemClass> itemlisthelp;

            ItemList.Clear();
            RollsList.Clear();
            using (AuctionContext a = new AuctionContext())
            {
                itemlisthelp = a.Items.ToList();
            }
            ItemClassComparer Comparer = new ItemClassComparer();

            ItemList = itemlisthelp.Distinct(Comparer).ToDictionary(c => (c.Name).ToLower());
            return;

            LoadFromWiki("http://roshpit.wikia.com/wiki/World_Drops");
            LoadFromWikiSpecific("http://roshpit.wikia.com/wiki/Specific_Drops%27_Rolls");
            LoadFromWikiArcana("http://roshpit.wikia.com/wiki/Arcana_Rolls");
            LoadFromWeapon("http://roshpit.wikia.com/wiki/Weapons%27_Rolls");
            foreach (KeyValuePair <string, List <string> > i in RollsList)
            {
                ItemClass it = Search(i.Key.Replace("\n", ""));
                if (ItemList.ContainsKey((it.Name).ToLower()))
                {
                    ItemList[it.Name.ToLower()].Rolls = i.Value;

                    if (it.Name.ToLower().Contains("lv2"))
                    {
                        if (ItemList.ContainsKey((it.Name.Substring(0, it.Name.Length - 1) + "1").ToLower()))
                        {
                            ItemList[((it.Name.Substring(0, it.Name.Length - 1)) + "1").ToLower()].Rolls = i.Value;
                        }
                    }
                    if (it.Name.ToLower().Contains("lv3"))
                    {
                        if (ItemList.ContainsKey((it.Name.Substring(0, it.Name.Length - 1) + "1").ToLower()))
                        {
                            ItemList[((it.Name.Substring(0, it.Name.Length - 1)) + "1").ToLower()].Rolls = i.Value;
                        }
                        if (ItemList.ContainsKey((it.Name.Substring(0, it.Name.Length - 1) + "2").ToLower()))
                        {
                            ItemList[((it.Name.Substring(0, it.Name.Length - 1)) + "2").ToLower()].Rolls = i.Value;
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void AddSellersToList()
        {
            auction_counter = 0;
            Users.Clear();
            using (AuctionContext MyAuctionContext = new AuctionContext())
            {
                List <AuctionNewClass> auctions;
                auctions = (((IEnumerable <AuctionNewClass>)MyAuctionContext.Auctions).Where(c => (int)c.final_price > 0))
                           .ToList();

                foreach (AuctionNewClass auc in auctions)
                {
                    if (Users.ContainsKey(auc.steam_id) == false)
                    {
                        Users.Add(auc.steam_id, new UserNewClass((ulong)auc.steam_id));
                    }
                    Users[auc.steam_id].Add_To_list(auc);
                    if (auc.final_price > 0)
                    {
                        if (Users.ContainsKey((int)auc.buyer_id) == false)
                        {
                            Users.Add((int)auc.buyer_id, new UserNewClass((ulong)auc.buyer_id));
                        }
                        Users[(int)auc.buyer_id].Add_To_list_Buy(auc);
                    }
                }
            }

            foreach (UserNewClass Au in Users.Values)
            {
                Au.CalculateStats();
            }
            Leaderboard = null;
            Leaderboard = Users.Values.ToList();
            Leaderboard.Sort((x, y) => y.Total_Income.CompareTo(x.Total_Income));
            for (var i = 0; i <= Leaderboard.Count - 1; i++)
            {
                Users[(int)Leaderboard[i].id].Global_Top_Position = i + 1;
            }
            Leaderboard.Sort((x, y) => y.Pure_Profit.CompareTo(x.Pure_Profit));
            for (var i = 0; i <= Leaderboard.Count - 1; i++)
            {
                Users[(int)Leaderboard[i].id].Global_Top_Pure = i + 1;
            }
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            GC.Collect();
        }
Exemple #3
0
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // Ignore system messages, or messages from other bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }
            if (message.MentionedRoles.Count > 0)
            {
                await returnPing(message);
            }

            // This value holds the offset where the prefix ends
            var argPos = 0;

            // Perform prefix check. You may want to replace this with
            // (!message.HasCharPrefix('!', ref argPos))
            // for a more traditional command format like !help.
            if (message.Content.Contains("roshpit.ca/market/auction/"))
            {
                AuctionNewClass new_auc;
                string          helpstring;
                ItemClass       helpitem = new ItemClass();
                helpstring = Regex.Matches(message.Content, @"(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?")[0].Value;
                new_auc    = RoshpitStats.GetOngoingAuction2(helpstring);
                helpitem   = RoshpitStats.Search(new_auc.item_name_en, true);
                if (helpitem == null)
                {
                    UpdateTablesClass a = new UpdateTablesClass();
                    helpitem = a.LoadItem($"https://www.roshpit.ca/items/{new_auc.roshpititem_variant}");
                    using (AuctionContext acontext = new AuctionContext())
                    {
                        int mid = 0;
                        foreach (KeyValuePair <string, ItemClass> item in RoshpitStats.ItemList)
                        {
                            if (mid < item.Value.id)
                            {
                                mid = item.Value.id;
                            }
                        }
                        helpitem.id = mid + 1;
                        acontext.Items.Add(helpitem);
                        acontext.SaveChanges();
                    }
                    RoshpitStats.ItemList.Add(helpitem.Name.ToLower(), helpitem);
                }
                if (helpitem == null)
                {
                    return;
                }
                EmbedBuilder builder = new EmbedBuilder();
                builder.WithAuthor(new EmbedAuthorBuilder {
                    IconUrl = message.Author.GetAvatarUrl(), Name = message.Author.Username
                });
                builder.WithTitle("Auction for **" + helpitem.Name + "**");
                builder.WithThumbnailUrl(helpitem.Image);
                builder.WithUrl(helpstring);
                //Rarity Color
                if (helpitem.Rarity == "Immortal")
                {
                    builder.WithColor(228, 174, 51);
                }
                else if (helpitem.Rarity == "Arcana")
                {
                    builder.WithColor(173, 229, 92);
                }
                else
                {
                    System.Drawing.Color col;
                    col = System.Drawing.ColorTranslator.FromHtml(helpitem.Rarity);
                    builder.WithColor(col.R, col.G, col.B);
                    builder.AddField(helpitem.Special_Ability, "Lv. " + helpitem.Required_level, true);
                }
                if (new_auc.level_req.HasValue)
                {
                    helpstring = $"Lv. {new_auc.level_req}\t";
                }
                else
                {
                    helpstring = "";
                }
                //Base Armor
                if ((new_auc.base_armor.HasValue) && (new_auc.base_magic_armor.HasValue) && (new_auc.base_armor > 0) && (new_auc.base_magic_armor > 0))
                {
                    helpstring = helpstring + $"{emoArmor} {new_auc.base_armor}\t{emoMagicArmor} {new_auc.base_magic_armor}\r\n";
                }
                else if (new_auc.base_armor.HasValue && new_auc.base_armor > 0)
                {
                    helpstring = helpstring + $"{emoArmor} {new_auc.base_armor}\r\n";
                }
                else if (new_auc.base_magic_armor.HasValue && new_auc.base_magic_armor > 0)
                {
                    helpstring = helpstring + $"{emoMagicArmor} {new_auc.base_magic_armor}\r\n";
                }

                //Sockets
                if (new_auc.socket1 == "none" || new_auc.socket1 == null)
                {
                    ;
                }
                else if (new_auc.socket1 == "open")
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains(new_auc.socket1))}";
                }
                else
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains($"{new_auc.socket1}{new_auc.socket1value}"))}";
                }
                if (new_auc.socket2 == "none" || new_auc.socket2 == null)
                {
                    ;
                }
                else if (new_auc.socket2 == "open")
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains(new_auc.socket2))}";
                }
                else
                {
                    helpstring = helpstring + $"{PingedEmotes.Find(c => c.ToString().Contains($"{new_auc.socket2}{new_auc.socket2value}"))}";
                }
                //Properties
                //Property1
                if (new_auc.property1name != null)
                {
                    if (new_auc.property1name.Contains("immortal*weapon"))
                    {
                        string hero;
                        hero = new_auc.roshpititem_variant.Split("_")[2];
                        if (hero == "axe")
                        {
                            hero = "redgeneral";
                        }
                        helpstring = helpstring + $"★ {RoshpitEmotes.Find(c => c.ToString().Contains(hero))} **Weapon**\r\n";
                    }
                    else if (new_auc.property1name.Contains("arcana"))
                    {
                        string hero;
                        hero = new_auc.roshpititem_variant.Split("_")[2];
                        if (hero == "axe")
                        {
                            hero = "redgeneral";
                        }
                        helpstring = helpstring + $"★ {RoshpitEmotes.Find(c => c.ToString().Contains(hero))} **Arcana**\r\n";
                    }
                    else if (new_auc.property1name.Contains("immortal"))
                    {
                        helpstring = helpstring + $"★**{new_auc.property1name.Substring(21).Replace("_", " ")}**\r\n";
                    }
                    else
                    {
                        helpstring = helpstring + $"**{new_auc.property1name.Replace("_", " ")}** \t{new_auc.property1}\r\n";
                    }
                }
                //Property2 3 4
                if (new_auc.property2name != null)
                {
                    helpstring = helpstring + $"**{new_auc.property2name.Replace("_", " ")}**\t{new_auc.property2}\r\n";
                }
                if (new_auc.property3name != null)
                {
                    helpstring = helpstring + $"**{new_auc.property3name.Replace("_", " ")}**\t{new_auc.property3}\r\n";
                }
                if (new_auc.property4name != null)
                {
                    helpstring = helpstring + $"**{new_auc.property4name.Replace("_", " ")}**\t{new_auc.property4}\r\n";
                }
                if (new_auc.property1name != null)
                {
                    builder.AddField("Properties:", helpstring, true);
                }

                //Bids
                helpstring = "";
                string emote = "";
                if (new_auc.resource_type == "Mithril Shards")
                {
                    emote = emoShard;
                }
                if (new_auc.resource_type == "Arcane Crystals")
                {
                    emote = emoCrystal;
                }
                if (new_auc.resource_type == "Prismatic Gemstones")
                {
                    emote = emoGem;
                }

                if (new_auc.minimum_bid > 0)
                {
                    helpstring = helpstring + $"\r\nStarting Bid:\t\t{emote}{new_auc.minimum_bid.ToString("#,##0")}";
                }
                if (new_auc.current_bid > 0)
                {
                    helpstring = helpstring + $"\r\nHighest Bid:\t\t{emote}{new_auc.current_bid.ToString("#,##0")}";
                }
                if (new_auc.buyout > 0)
                {
                    helpstring = helpstring + $"\r\nBuyout:\t\t{emote}{new_auc.buyout.ToString("#,##0")}";
                }
                helpstring = helpstring + "\r\n\\_\\_\\_\\_\\_\\_\\_\\_";
                //Time

                double hours;
                hours      = (new_auc.expiry_time - DateTime.Today).TotalHours - 12;
                helpstring = helpstring + $"\r\nExpiry:\t\t{hours.ToString("#,##0")} Hours\r\n";
                builder.AddField("Auction Details", helpstring, true);
                builder.Description = Regex.Replace(message.Content, @"(http|ftp|https)://([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?", "");
                //
                await message.Channel.SendMessageAsync("", embed : builder.Build());

                Discord.Rest.RestUserMessage mes;
                mes = (Discord.Rest.RestUserMessage)(await message.Channel.GetMessageAsync(message.Id));
                await mes.DeleteAsync();
            }
            if ((!message.HasMentionPrefix(_discord.CurrentUser, ref argPos)) && (!message.HasCharPrefix(conf.prefix, ref argPos)))
            {
                return;
            }
            if ((message.Channel.Id == 391268932696145920) || (message.Channel.Id == 391268981446803466) || (message.Channel.Id == 331554376181219350) || (message.Channel.Id == 299731610683572224))
            {
                await message.Channel.SendMessageAsync("<:MonkaS:663460636490989597> 👉 <#431938235267284992>");

                return;
            }
            var context = new SocketCommandContext(_discord, message);
            // Perform the execution of the command. In this method,
            // the command service will perform precondition and parsing check
            // then execute the command if one is matched.
            await _commands.ExecuteAsync(context, argPos, _services);

            // Note that normally a result will be returned by this format, but here
            // we will handle the result in CommandExecutedAsync,
        }
Exemple #4
0
        public async Task <bool> Update()
        {
            UpdateIsRunning = true;
            Dictionary <int, AuctionNewClass> NewAuctionlist = new Dictionary <int, AuctionNewClass>();
            StreamWriter writer = new StreamWriter(LOG_FILE);

            try
            {
                int       counter    = 1000;
                int       multiplier = 0;
                string    a;
                WebClient wc = new WebClient()
                {
                    Encoding = System.Text.Encoding.UTF8
                };
                int start;
                using (AuctionContext dbAucContext = new AuctionContext())
                {
                    try
                    {
                        start = dbAucContext.Auctions.First(c => c.status == 0 & c.id > 1730000).id;
                    }
                    catch
                    {
                        // start = dbAucContext.Auctions.Last(Function(c) c.id > 1730000).id
                        start = 1730000;
                    }
                    writer.WriteLine(start);
                    while (counter == 1000)
                    {
                        counter = 0;
                        System.Threading.Thread.Sleep(2000);
                        writer.WriteLine(multiplier);
                        try
                        {
                            a = wc.DownloadString($"http://www.roshpit.ca/champions/API/get_auctions?id={start + (1000 * multiplier)}");
                        }
                        catch (Exception ex)
                        {
                            counter = 1000;
                            writer.WriteLine(ex.Message);
                            continue;
                        }
                        try
                        {
                            foreach (AuctionNewClass auc in JsonConvert.DeserializeObject <AuctionNewClass[]>(a))
                            {
                                try
                                {
                                    if (NewAuctionlist.ContainsKey(auc.id) == false)
                                    {
                                        NewAuctionlist.Add(auc.id, auc);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    writer.WriteLine(ex.Message);
                                }
                                counter += 1;
                            }
                            multiplier += 1;
                        }
                        catch (Exception ex)
                        {
                            writer.WriteLine(ex.Message);
                            counter = 0;
                        }
                    }
                    dbAucContext.Auctions.RemoveRange(((IEnumerable <AuctionNewClass>)dbAucContext.Auctions).Where(c => c.id >= start));
                    dbAucContext.SaveChanges();
                    writer.WriteLine("removed");
                }

                List <int> remid = new List <int>();
                using (AuctionContext dbAucContext = new AuctionContext())
                {
                    dbAucContext.AddRange(NewAuctionlist.Values);
                    writer.WriteLine("saved " + NewAuctionlist.Count);
                    dbAucContext.SaveChanges();
                }
                writer.WriteLine(DateTime.Now);
                writer.Close();
                writer.Dispose();
                LastModified = DateTime.Now;
                GC.Collect();
            }
            catch (Exception ex)
            {
                UpdatesEnabled = false;
                writer.WriteLine(ex.Message);
                writer.Close();
                writer.Dispose();
            }
            writer.Close();
            writer.Dispose();
            UpdateIsRunning = false;
            return(true);
        }