Exemple #1
0
        /// <summary>
        /// Добавление предмета в список покупок
        /// </summary>
        /// <param name="link">ссылка на страницу с предметом</param>
        public void AddItem(string link, int _price = 0, PriceCheck _check = PriceCheck.Price)
        {
            var itm = new Itm {
                link = link, price = _price, priceCheck = _check
            };

            itm.hash = CLIENT.GetHash(itm, cfg.key);
            //проверяем, нет ли этого предмета в списке
            var ch = Items.Find(p => p.id == itm.id);

            if (ch != null)
            {
                WriteMessage("Данный предмет уже есть", MessageType.Info);
                return;
            }

            if (itm.name != "")
            {
                Items.Add(itm);
                WriteMessage($"Добавлен {itm.name}\nЦена {itm.price} рублей", MessageType.Info);
                Save(false);
            }
            else
            {
                WriteMessage($"Ошибка при добавлении. Попробуйте еще раз.", MessageType.Error);
            }
        }
Exemple #2
0
        /// <summary>
        /// Подписка на уведомления в сокетах на выбранные предметы
        /// </summary>
        /// <param name="item">Предмет</param>
        /// <param name="key">api ключ</param>
        /// <param name="price">1 если хотим удалить уведомление</param>
        /// <returns>возвращает строку true, если все прошло без ошибок, иначе текст ошибки</returns>
        public string Notification(Itm item, string key, int price = 0)
        {
            try
            {
                //https://market.csgo.com/api/UpdateNotification/[classid]/[instanceid]/[price]?key=[your_secret_key]
                string answer;
                if (price == 0)
                {
                    answer = Web(host + $"/api/UpdateNotification/{item.id.Replace('_', '/')}/{item.price * 100}/?key={key}");
                }
                else
                {
                    answer = Web(host + $"/api/UpdateNotification/{item.id.Replace('_', '/')}/0/?key={key}");
                }

                var pr  = new { success = false, error = "" };
                var inf = JsonConvert.DeserializeAnonymousType(answer, pr);
                if (inf.success)
                {
                    return(inf.success.ToString());
                }
                else
                {
                    return(inf.error);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Exemple #3
0
        /// <summary>
        /// Получает хеш предмета и заполняет название
        /// </summary>
        /// <param name="item">предмет для которого нужно получить хеш и заполнить название</param>
        /// <param name="key">Api key</param>
        /// <param name="lang">en,ru</param>
        /// <returns>string hash</returns>
        public string GetHash(Itm item, string key, string lang = "en")
        {
            string pattern = "[0-9]{1,15}[-]{1}[0-9]{1,15}";
            var    match   = System.Text.RegularExpressions.Regex.Match(item.link, pattern);
            var    code    = match.Value.Replace("-", "_");

            string resp = Web(host + "/api/ItemInfo/" + code + "/" + lang + "/?key=" + key, 5000);
            Info   inf  = JsonConvert.DeserializeObject <Info>(resp);

            item.name = inf.name + " (" + inf.quality + ")";
            item.id   = code;
            item.hash = inf.hash;
            return(inf.hash);
        }
Exemple #4
0
        /// <summary>
        /// Запрос последней в истории цены
        /// </summary>
        public string GetLastPrice(Itm item, string key)
        {
            string resp = Web(host + "/api/ItemHistory/" + item.id + "/?key=" + key);
            var    pr   = new { success = "", average = "", history = new[] { new { l_price = "" } }, error = "" };
            var    inf  = JsonConvert.DeserializeAnonymousType(resp, pr);

            if (inf.success == "True" || inf.success == "true")
            {
                return((Convert.ToDouble(inf.history[0].l_price)).ToString());
            }
            else
            {
                return("0");
            }
        }
Exemple #5
0
        /// <summary>
        /// Запрос средней цены
        /// </summary>
        public string GetAverangePrice(Itm item, string key)
        {
            string resp = Web(host + "/api/ItemHistory/" + item.id + "/?key=" + key);
            var    pr   = new { success = "", average = "" };
            var    inf  = JsonConvert.DeserializeAnonymousType(resp, pr);

            if (inf.success == "True" || inf.success == "true")
            {
                return(inf.average.ToString());
            }
            else
            {
                return("0");
            }
        }
Exemple #6
0
        /// <summary>
        /// Запрос мин. цены
        /// </summary>
        public string GetMinPrice(Itm item, string key)
        {
            string resp = Web(host + "/api/BestSellOffer/" + item.id + "/?key=" + key);

            var BestSellOffer = new { success = false, best_offer = "", error = "" };
            var Message       = JsonConvert.DeserializeAnonymousType(resp, BestSellOffer);

            if (Message != null && Message.error == null && Message.success)
            {
                return(Message.best_offer);
            }
            else
            {
                return("-1");
            }
        }
Exemple #7
0
        //поиск вещи
        public bool Buy(Itm item, string key, int timeout = 500)
        {
            int i = 0;

            try
            {
a:
                //string resp = Web(host + "/api/Buy/" + item.id + "/" + Convert.ToInt32(item.price * 100) + "/" + item.hash + "/" + "?key=" + key, timeout);
                string resp = Web(host + "/api/Buy/" + item.id + "/" + Convert.ToInt32(item.price * 100) + "/" + "?key=" + key, timeout);
                aBuy it = JsonConvert.DeserializeObject <aBuy>(resp);
                if (it.id != null && it.id.ToLower() != "false")
                {
                    if (it.result == "ok")
                    {
                        return(true);
                    }
                }
                else
                {
                    if (it.error != null && it.error.ToLower() == "bad key")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("неверный ключ");
                        Console.ResetColor();
                        Console.ReadKey();
                        Environment.Exit(-1);
                    }
                    if (it.result.ToLower().IndexOf("изменилось") != -1 || it.result.ToLower().IndexOf("вывод") != -1 || it.result.ToLower().IndexOf("средств") != -1 || it.result.ToLower().IndexOf("инвентарь") != -1 || it.result.ToLower().IndexOf("боты") != -1)
                    {
                        return(false);
                    }
                    if (it.result.IndexOf("устарело") == -1 && i++ < 5)
                    {
                        // Console.WriteLine(string.Format("[{0}] {1}", item.name, it.result));
                        goto a;
                    }
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
Exemple #8
0
 /// <summary>
 /// Добавление ордера на покупку
 /// </summary>
 public string ProcessOrder(Itm item, string key)
 {
     try
     {
         //https://market.csgo.com/api/ProcessOrder/[classid]/[instanceid]/[price]/?key=[your_secret_key]
         string answer = Web(host + string.Format("/api/ProcessOrder/{0}/{1}/?key={2}", item.id.Replace('_', '/'), item.price * 100, key));
         var    pr     = new { success = false, way = "", error = "" };
         var    inf    = JsonConvert.DeserializeAnonymousType(answer, pr);
         if (inf.success == true)
         {
             return(inf.way);
         }
         else
         {
             return(inf.error);
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }