Exemplo n.º 1
0
        private void Reset(bool live = false)
        {
            HtmlDocument doc = Etc.GetDocFromURL(Etc.DEFAULT_URI);

            //rush will skip the listing of all matches
            Get(doc, rush: live);
        }
Exemplo n.º 2
0
        private SocketIO SetupSIOClient(string id, string scorebotURL = "")
        {
            //format with match/scorebot id
            const string hltvMatchFormat = "https://www.hltv.org/matches/{0}/allo";
            //remembers to add { and } before emitting
            const string hltvMatchData = "'token':'','listId':'{0}'";

            //new instances of scoreboard and match log
            this.log        = new Log(10);
            this.scoreboard = new ScoreBoard(logHeight: this.log.limit, quitLen: this.log.HINT.Length);

            //loads match page to retrieve scorebot uri
            if (scorebotURL == "")
            {
                string       hltvMatchURL = String.Format(hltvMatchFormat, id);
                HtmlDocument doc          = Etc.GetDocFromURL(hltvMatchURL);
                HtmlNode     el           = doc.DocumentNode.SelectSingleNode("//*[@id=\"scoreboardElement\"]");
                scorebotURL = el.GetAttributeValue("data-scorebot-url", "").Split(",")[0];
            }

            SocketIO client = new SocketIO(scorebotURL);

            client.OnConnected += async() => {
                await client.EmitAsync("readyForMatch", "{" + String.Format(hltvMatchData, id) + "}");

                client.On("scoreboard", data => {
                    this.scoreboard.LoadJSON(data.Text);
                });
                client.On("log", data => {
                    //waits for scoreboard to be setup before printing log
                    if (this.scoreboard.initialised)
                    {
                        this.log.LoadJSON(data.Text, this.scoreboard.bottom);
                    }
                    else
                    {
                        this.log.AddQueue(data.Text);
                    }
                });
                client.On("fullLog", data => {
                    //no clue when this is emitted
                    Console.Write("Catcher");
                });
            };

            client.OnClosed += (reason) => {
                Console.WriteLine("Client closed: " + reason.ToString());
            };

            return(client);
        }
Exemplo n.º 3
0
        //everything is an async due to the live match functionality :/
        public void Get(string matchURL)
        {
            HtmlDocument doc     = Etc.GetDocFromURL(matchURL);
            HtmlNode     docNode = doc.DocumentNode;

            int    selection = 5;
            string title     = "You are viewing: " +
                               docNode.SelectSingleNode("//title").InnerText.Split('|')[0].Trim(),
                   watchLive = "";

            this.printout = "\n" + title + "\n" +
                            "\nPlease enter the category to view:\n" +
                            "1. Maps\n" +
                            "2. Lineups\n" +
                            "3. Past Matches\n" +
                            "4. Head to Head\n" +
                            "5. Comments\n";

            CheckLiveStatus(doc.DocumentNode);

            if (!this.over)
            {
                this.printout += "6. Streams\n";
                selection++;
                if (this.live)
                {
                    this.printout += "W. Watch Live\n";
                    watchLive      = ", W to watch";
                }
            }
            else
            {
                this.printout += "6. VODs\n" +
                                 "7. Highlights\n" +
                                 "8. Match Stats\n" +
                                 "9. Player of the Match\n";
                selection += 4;
            }
            //-4 for the first and last lines and overhead
            this.hint = "(1-" + selection + watchLive + ", Q to quit, B to return): ";
            Console.Write(this.printout + this.hint);
            GetEntry(docNode);
        }
Exemplo n.º 4
0
        public void Get(string postURL, bool prompt = false, HtmlNode matchNode = null) {
            //reinitialising stuff
            this.prompt = prompt;

            HtmlDocument doc = Etc.GetDocFromURL(postURL);

            //will use match page document node if provided
            HtmlNode contents = (matchNode == null) ? doc.DocumentNode.SelectSingleNode("//div[@class=\"contentCol\"]")
                                                  : matchNode.SelectSingleNode("//div[@class=\"contentCol\"]");

            //only finds op if on forum and not the match page
            if (matchNode == null) {
                //gets op/first box in thread
                HtmlNode opContainer = contents.SelectSingleNode(".//div[contains(@class, \"forumthread\")]");
                HtmlNode opPost = opContainer.SelectSingleNode(".//div[@class=\"standard-box\"]");
                string[] opString = GetPostString(opPost, op: true);

                Console.WriteLine("\n" + String.Join("\n", opString) + "\n");
            }

            //gets all replies
            HtmlNode replyContainer = contents.SelectSingleNode(".//div[@class=\"forum no-promode\"]");
            //yes there's a space there. single slash for getting post 1 level down
            HtmlNodeCollection mainPosts = replyContainer.SelectNodes("./div[@class=\"post \"]");
            foreach (HtmlNode post in mainPosts) {
                string[] parentString = GetPostString(post, op: false);
                string formattedComment = FormatConsole("", parentString);
                Console.WriteLine(formattedComment);

                //children are sibling elements that contain replies to the post currently working on
                HtmlNode childrenNode = post.NextSibling.NextSibling;
                if (childrenNode.HasChildNodes) {
                    HandleChildren(childrenNode, TAB);
                }
            }
        }