<commit_before>require 'json'
require 'open-uri'
require 'active_support/time'

class Hubstat < Linkbot::Plugin
  @@config = Linkbot::Config["plugins"]["hubstat"]
  @@hipchat = Linkbot::Config["plugins"]["hipchat"]

  if @@config && @@hipchat
    Linkbot::Plugin.register('hubstat', self, {
     :message => { :regex => /\A!hubstat/, :handler => :on_message, :help => :help },
     :periodic => {:handler => :periodic}
    })
  end

  if Linkbot.db.table_info('hubstatus').empty?
    Linkbot.db.execute('CREATE TABLE hubstatus (dt TEXT)');
  end

  def self.help
    '!hubstat - see whether your trouble with GitHub is just you'
  end

  def self.post_status(response)
    colors = {
      "good" => "green",
      "minor" => "yellow",
      "major" => "red"
    }
    color = colors.fetch(response['status'], "gray")

    timestr = message_time.in_time_zone("EST").strftime("%b %d %H:%m EST")

    message = "As of #{timestr}, GitHub is <a href='https://status.github.com/'>reporting</a>: #{response["body"]}"
    hipchat_send(color, message)
  end

  def self.periodic
    #by default, post the message if it's within the last day
    last_pulled = Time.now.utc - 60*60*24

    rows = Linkbot.db.execute("select dt from hubstatus")
    last_pulled = Time.parse(rows[0][0]) if !rows.empty? && rows[0][0]

    response = self.get_status

    #don't print the message if time exists and is newer than the message
    status_time = Time.parse(response["created_on"])
    if last_pulled && last_pulled < status_time
      self.post_status(response)
    end

    Linkbot.db.execute("delete from hubstatus")
    Linkbot.db.execute("insert into hubstatus (dt) VALUES ('#{status_time.to_s}')")
    {:messages => []}
  end

  def self.on_message(message, matches)
    response = self.get_status<commit_msg>re-adding missing variable in github_status.rb<commit_after>require 'json'
require 'open-uri'
require 'active_support/time'

class Hubstat < Linkbot::Plugin
  @@config = Linkbot::Config["plugins"]["hubstat"]
  @@hipchat = Linkbot::Config["plugins"]["hipchat"]

  if @@config && @@hipchat
    Linkbot::Plugin.register('hubstat', self, {
     :message => { :regex => /\A!hubstat/, :handler => :on_message, :help => :help },
     :periodic => {:handler => :periodic}
    })
  end

  if Linkbot.db.table_info('hubstatus').empty?
    Linkbot.db.execute('CREATE TABLE hubstatus (dt TEXT)');
  end

  def self.help
    '!hubstat - see whether your trouble with GitHub is just you'
  end

  def self.post_status(response)
    colors = {
      "good" => "green",
      "minor" => "yellow",
      "major" => "red"
    }
    color = colors.fetch(response['status'], "gray")

    message_time = Time.parse(response["created_on"])
    timestr = message_time.in_time_zone("EST").strftime("%b %d %H:%m EST")

    message = "As of #{timestr}, GitHub is <a href='https://status.github.com/'>reporting</a>: #{response["body"]}"
    hipchat_send(color, message)
  end

  def self.periodic
    #by default, post the message if it's within the last day
    last_pulled = Time.now.utc - 60*60*24

    rows = Linkbot.db.execute("select dt from hubstatus")
    last_pulled = Time.parse(rows[0][0]) if !rows.empty? && rows[0][0]

    response = self.get_status

    #don't print the message if time exists and is newer than the message
    status_time = Time.parse(response["created_on"])
    if last_pulled && last_pulled < status_time
      self.post_status(response)
    end

    Linkbot.db.execute("delete from hubstatus")
    Linkbot.db.execute("insert into hubstatus (dt) VALUES ('#{status_time.to_s}')")
    {:messages => []}
  end

  def self.on_message(message, matches)
    response = self.get_status
{'fraction_non_alphanumeric': 0.1563942438229704, 'fraction_numerical': 0.005430355688297583, 'mean_word_length': 3.6929936305732483, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, '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': '1427184', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1196, 'n_words': 293}