Esempio n. 1
0
 public async Task GetIp()
 {
     if (await NetUtills.GetJsonUrl("https://api.ipify.org/?format=json") is JObject res)
     {
         await ReplyAsync(res["ip"].ToString());
     }
 }
Esempio n. 2
0
        public async Task <List <string> > GetRecomendations()
        {
            var recs = new List <string>();

            try
            {
                var htmlDoc = await NetUtills.GetHtmlDoc(BaseUrl + _id);

                if (htmlDoc == null)
                {
                    return(recs);
                }

                var node = htmlDoc.DocumentNode.SelectSingleNode("//ul[@class='anime-slide js-anime-slide']");
                var lis  = node.Descendants(0).Where(n => n.HasClass("btn-anime"));

                foreach (var li in lis)
                {
                    recs.Add(li.Attributes["title"].Value);
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine($"Error getting recommendations: {e.Message}");
            }
            return(recs);
        }
Esempio n. 3
0
        public async Task GetSynonyms()
        {
            var httpClient = new HttpClient();

            try
            {
                var htmlDoc = await NetUtills.GetHtmlDoc(BaseUrl + _id);

                if (htmlDoc == null)
                {
                    return;
                }

                var node = htmlDoc.DocumentNode.SelectSingleNode("//td[@class='borderClass']");
                var divs = node.Descendants(0).Where(n => n.HasClass("spaceit_pad"));

                foreach (var div in divs)
                {
                    _synonyms.Add(div.SelectSingleNode("text()[normalize-space()]").InnerText.Trim());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine(e.InnerException.Message);
                }
            }
        }
Esempio n. 4
0
        public static async Task <string> GetWeatherCommand(string city)
        {
            if (_weatherToken == null)
            {
                return("Module didn't init");
            }
            var uriBuilder = new UriBuilder(WeatherUrl);
            var query      = HttpUtility.ParseQueryString(uriBuilder.Query);

            query["q"]       = city;
            query["appid"]   = _weatherToken;
            query["units"]   = "metric";
            uriBuilder.Query = query.ToString();
            var url = uriBuilder.ToString();

            if (!(await NetUtills.GetJsonUrl(url) is JObject res))
            {
                return("Couldn't get weather");
            }
            if (!res.ContainsKey("main"))
            {
                return("Couldn't get weather");
            }

            var tempMin = res["main"]["temp_min"].ToString();
            var tempMax = res["main"]["temp_max"].ToString();
            var desc    = res["weather"][0]["description"].ToString();

            return($"Weather for {city}\n{tempMin}°/{tempMax}° - {desc}");
        }
Esempio n. 5
0
        public static async Task <GroupPost> GetNewPost(GroupFeeder.Group group)
        {
            var url = Vkapiurl + $"wall.get?count=2&owner_id=-{group.Id}&v=5.84&access_token={_token}";

            var  id      = "";
            var  text    = "";
            var  picture = "";
            long date    = 0;

            try
            {
                var response = ((JObject)await NetUtills.GetJsonUrl(url))["response"];

                var neededObj = response["items"].Contains("is_pinned")
                    ? (JObject)response["items"][1]
                    : (JObject)response["items"][0];

                id   = neededObj["id"].ToString();
                text = neededObj["text"].ToString();

                date = long.Parse(neededObj["date"].ToString());

                picture = GetPicture(neededObj);
            }

            catch (Exception e)
            {
                Logger.Error($"Can't load group info {group.Name}: {e}");
            }

            return(new GroupPost(id, text, picture, date));
        }
Esempio n. 6
0
        public static async Task <List <AnimeInfo> > GetAnime()
        {
            var list = new List <AnimeInfo>();

            if (!(await NetUtills.GetJsonUrl(Url) is JArray array))
            {
                return(list);
            }
            list.AddRange(array.Select(entity => new AnimeInfo(entity)));

            return(list);
        }
Esempio n. 7
0
        public static async void RunFeeder()
        {
            while (_isRunning)
            {
                var switchRes = await NetUtills.GetRss(SwitchPricesUrl);

                foreach (var res in switchRes.Items)
                {
                    var text = res.Title.Text;
                    if (_storedData.Contains(text))
                    {
                        continue;
                    }

                    var cgPrice = RegexUtills.GetPrices(text);

                    if (!(cgPrice.InitPrice >= MinInitPrice) || cgPrice.Percent < MinDiscount)
                    {
                        continue;
                    }
                    await _channel.SendMessageAsync($"@everyone\nNew: {text}");

                    _storedData.Add(text);
                }

                await Task.Delay(1 * 1000);

                var ps4Res = await NetUtills.GetRss(Ps4PriceUrl);

                foreach (var res in ps4Res.Items)
                {
                    var text = res.Title.Text;
                    if (_storedData.Contains(text))
                    {
                        continue;
                    }

                    var cgPrice = RegexUtills.GetPrices(text);

                    if (!(cgPrice.InitPrice >= MinInitPrice) || cgPrice.Percent < MinDiscount)
                    {
                        continue;
                    }
                    await _channel.SendMessageAsync($"@everyone\nNew: {text}");

                    _storedData.Add(text);
                }

                Logger.Info("Prices are checked");
                //1 hour
                await Task.Delay(1 * 60 * 60 * 1000);
            }
        }
Esempio n. 8
0
        private Task AddInfiniteTasks()
        {
            NetUtills.Init(_config).Wait();
            PongCommandHandler.Init(_config);

            AnimeFeeder.Init(_client, _config);
            StreamerFeeder.Init(_client, _config);
            GroupFeeder.Init(_client, _config);
            ConsolesPriceFeeder.Init(_client);

            Task.Run(GroupFeeder.RunGroupFeeder);
            Task.Run(StreamerFeeder.RunStreamerFeeder);
            Task.Run(AnimeFeeder.RuAnimeFeeder);
            Task.Run(ConsolesPriceFeeder.RunFeeder);

            return(Task.CompletedTask);
        }
Esempio n. 9
0
        public static async void RuAnimeFeeder()
        {
            await PreStartMethod();

            while (_isRunning)
            {
                await FindNewData();

                var animeData = (from item in _animeDataCached
                                 where item.WatchingStatus == 1 || item.WatchingStatus == 6
                                 select RegexUtills.RemoveChars(item.GetAllNames())).ToList();

                Logger.Info(string.Join(" ", animeData));

                var rssData = await NetUtills.GetRss(NyaUrl);

                var pattern = await GetCurrentPattern();

                foreach (var entry in rssData.Items)
                {
                    if (!entry.Title.Text.Contains(pattern) ||
                        !entry.Title.Text.Contains("1080p") ||
                        RssFeedList.Contains(entry.Title.Text))
                    {
                        continue;
                    }

                    var title = entry.Title.Text.Replace(pattern, "");
                    title = RegexUtills.FixRssTitle(title);

                    foreach (var data in from s in animeData
                             where s.Contains(title)
                             select $"@everyone\nNew series: {entry.Title.Text}\n[Link]({entry.Links[0].Uri})")
                    {
                        await _channel.SendMessageAsync(data);

                        RssFeedList.Add(entry.Title.Text);
                        break;
                    }
                }

                Logger.Info("Rss has been read");
                await Task.Delay(300 * 1000);
            }
        }
Esempio n. 10
0
        public static async Task GetDiscountsConsole(string type, int minInitPrice, int minDiscount)
        {
            string url;
            var    messagesSent = new List <string>();

            if (type.Equals("ps4"))
            {
                url = Ps4PriceUrl;
            }
            else if (type.Equals("switch"))
            {
                url = SwitchPricesUrl;
            }
            else
            {
                await _channel.SendMessageAsync("Typo in console type");

                return;
            }

            var res = await NetUtills.GetRss(url);

            foreach (var item in res.Items)
            {
                var text = item.Title.Text;

                var cgPrice = RegexUtills.GetPrices(text);

                if (!(cgPrice.InitPrice >= minInitPrice) || cgPrice.Percent < minDiscount)
                {
                    continue;
                }
                await _channel.SendMessageAsync($"{text}");

                messagesSent.Add(item.Title.Text);
            }

            if (messagesSent.Count == 0)
            {
                await _channel.SendMessageAsync("No items found");
            }
        }
Esempio n. 11
0
        public async Task DownloadLink(string url)
        {
            if (!_isDownload)
            {
                return;
            }

            //TODO add disc space check


            var name = url.Split("//")[1].Replace('/', '_');
            await NetUtills.DownloadFileFromUrl(url, "/home/pi/torrents/", name);

            var info = new NewTorrent {
                Filename = name
            };


            await _client.TorrentAddAsync(info);
        }
Esempio n. 12
0
        public static async Task <List <PostComment> > GetCommentsFromPost(GroupFeeder.Group group, string postId)
        {
            var url = Vkapiurl +
                      $"wall.getComments?count=100&need_likes=1&owner_id=-{group.Id}&post_id={postId}&v=5.84&access_token={_token}";

            var comments = new List <PostComment>();

            try
            {
                if (!(await NetUtills.GetJsonUrl(url) is JObject data))
                {
                    return(null);
                }
                var count = data["response"]["count"].ToObject <int>();
                var items = data["response"]["items"];

                comments.AddRange(from JObject item in items
                                  let likes                                                  = item["likes"]["count"].ToObject <int>()
                                                                  let text                   = item["text"].ToString()
                                                                                      let id = item["id"].ToString()
                                                                                               let picture = GetPicture(item)
                                                                                                             where !text.Equals("") || !picture.Equals("")
                                                                                                             select new PostComment(likes, text, picture, id));

                if (count < 100)
                {
                    return(comments);
                }
                var k = 100;
                Console.WriteLine(items.ToString());
                while (k < count)
                {
                    var innerUrl =
                        Vkapiurl +
                        $"wall.getComments?count=100&offset={k.ToString()}&need_likes=1&owner_id=-{group.Id}&post_id={postId}&v=5.84&access_token={_token}";
                    data = await NetUtills.GetJsonUrl(innerUrl) as JObject;

                    if (data != null)
                    {
                        items = data["response"]["items"];
                    }

                    comments.AddRange(from JObject item in items
                                      let likes                                                  = item["likes"]["count"].ToObject <int>()
                                                                      let text                   = item["text"].ToString()
                                                                                          let id = item["id"].ToString()
                                                                                                   let picture = GetPicture(item)
                                                                                                                 where !text.Equals("") || !picture.Equals("")
                                                                                                                 select new PostComment(likes, text, picture, id));

                    k += 100;
                    await Task.Delay(500);
                }

                return(comments);
            }
            catch (Exception e)
            {
                Logger.Error($"Can't load comments info {group.Name}: {e}");
                return(null);
            }
        }