<commit_before>﻿using System;
using System.Text.RegularExpressions;

namespace Cactbot {

  // This class can determine the current plugin version, as well as the latest version
  // released of the plugin on GitHub. It is inspired by the work of anoyetta in
  // https://github.com/anoyetta/ACT.SpecialSpellTimer/blob/master/ACT.SpecialSpellTimer.Core/UpdateChecker.cs
  class VersionChecker {
    private ILogger logger_ = null;

    public const string kReleaseUrl = "http://github.com/quisquous/cactbot/releases/latest";
    public const string kIssueUrl = "http://github.com/quisquous/cactbot/issues";

    public VersionChecker(ILogger logger) {
      logger_ = logger;
    }

    public Version GetLocalVersion() {
      return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
    }

    public Version GetRemoteVersion() {
      string html;
      try {
        var web = new System.Net.WebClient();
        var page_stream = web.OpenRead(kReleaseUrl);
        var reader = new System.IO.StreamReader(page_stream);
        html = reader.ReadToEnd();
      } catch (Exception e) {
        logger_.LogError("Error fetching most recent github release: " + e.Message + "\n" + e.StackTrace);
        return new Version();
      }

      var pattern = @"<h1(\s.*?)?\sclass=""release-title"".*?>(?<Header>.*?)</h1>";
      var regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
      var match = regex.Match(html);
      if (!match.Success) {
        logger_.LogError("Error parsing most recent github release, no match found. Please report an issue at " + kIssueUrl);
        return new Version();
      }

      string header_string = match.Groups["Header"].Value;

      pattern = @"<a\s.*?>\s*(?<ReleaseTitle>.*?)\s*</a>";<commit_msg>Fix github version scraping<commit_after>﻿using System;
using System.Text.RegularExpressions;

namespace Cactbot {

  // This class can determine the current plugin version, as well as the latest version
  // released of the plugin on GitHub. It is inspired by the work of anoyetta in
  // https://github.com/anoyetta/ACT.SpecialSpellTimer/blob/master/ACT.SpecialSpellTimer.Core/UpdateChecker.cs
  class VersionChecker {
    private ILogger logger_ = null;

    public const string kReleaseUrl = "http://github.com/quisquous/cactbot/releases/latest";
    public const string kIssueUrl = "http://github.com/quisquous/cactbot/issues";

    public VersionChecker(ILogger logger) {
      logger_ = logger;
    }

    public Version GetLocalVersion() {
      return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
    }

    public Version GetRemoteVersion() {
      string html;
      try {
        var web = new System.Net.WebClient();
        var page_stream = web.OpenRead(kReleaseUrl);
        var reader = new System.IO.StreamReader(page_stream);
        html = reader.ReadToEnd();
      } catch (Exception e) {
        logger_.LogError("Error fetching most recent github release: " + e.Message + "\n" + e.StackTrace);
        return new Version();
      }

      var pattern = @"<h1(\s.*?)?\sclass=""[^""]*release-title[^""]*"".*?>(?<Header>.*?)</h1>";
      var regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
      var match = regex.Match(html);
      if (!match.Success) {
        logger_.LogError("Error parsing most recent github release, no match found. Please report an issue at " + kIssueUrl);
        return new Version();
      }

      string header_string = match.Groups["Header"].Value;

      pattern = @"<a\s.*?>\s*(?<ReleaseTitle>.*?)\s*</a>";
{'fraction_non_alphanumeric': 0.12944444444444445, 'fraction_numerical': 0.0011111111111111111, 'mean_word_length': 3.167824074074074, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2991716', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1038, 'n_words': 268}