<commit_before># Description:
#   Evaluate one line of Clojure script
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   hubot clojure|clj <script> - Evaluate one line of Clojure script
#
# Author:
#   jingweno

module.exports = (robot) ->
  robot.respond /(clojure|clj)\s+(.*)/i, (msg)->
    script = encodeURIComponent(msg.match[2])

    msg.http("http://tryclj.com/eval.json?expr=#{script}")
      .get() (err, res, body) ->
        switch res.statusCode
          when 200
            result = JSON.parse(body)

            if result.error
              msg.reply result.message
            else
              outputs = result.result.split("\n")
              for output in outputs
                msg.reply output
          else
            msg.reply "Unable to evaluate script: #{script}. Request returned with the status code: #{res.statusCode}"<commit_msg>Grab the session ID from the response.<commit_after># Description:
#   Evaluate one line of Clojure script
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   hubot clojure|clj <script> - Evaluate one line of Clojure script
#
# Author:
#   jingweno

ringSessionID = ''

module.exports = (robot) ->
  robot.respond /(clojure|clj)\s+(.*)/i, (msg)->
    script = msg.match[2]

    msg.http("http://tryclj.com/eval.json")
      .query(expr: script)
      .headers(Cookie: "ring-session=#{ringSessionID}")
      .get() (err, res, body) ->
        switch res.statusCode
          when 200
            if res.headers["set-cookie"]
              ringSessionID = res.headers["set-cookie"][0].match(/ring-session=([-a-z0-9]+);/)[1]
            result = JSON.parse(body)

            if result.error
              msg.reply result.message
            else
              outputs = result.result.split("\n")
              for output in outputs
                msg.reply output
          else
            msg.reply "Unable to evaluate script: #{script}. Request returned with the status code: #{res.statusCode}"
{'fraction_non_alphanumeric': 0.13223552894211577, 'fraction_numerical': 0.005988023952095809, 'mean_word_length': 2.15748031496063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '4197388', 'n_tokens_mistral': 628, 'n_tokens_neox': 611, 'n_words': 152}