<commit_before>Robot   = require('hubot').Robot
Adapter = require('hubot').Adapter
TextMessage = require('hubot').TextMessage
HTTPS = require 'https'

class Slack extends Adapter
  send: (params, strings...) ->
    console.log "Sending message"

    user = @userFromParams(params)
    strings.forEach (str) =>
      # Escape this
      str = str.replace(/&/g, '&amp;')
      str = str.replace(/</g, '&lt;')
      str = str.replace(/>/g, '&gt;')

      # Linkify. We assume that the bot is well-behaved and
      # consistently sending links with the protocol part
      str = str.replace(/((\bhttp)\S+)/g, '<$1>')

      args = JSON.stringify({"channel": user.reply_to, "text": str, username: @robot.name})
      @post "/services/hooks/hubot", args

  reply: (params, strings...) ->
    console.log "Sending reply"

    user = @userFromParams(params)
    strings.forEach (str) =>
      @send params, "#{user.name}: #{str}"

  topic: (params, strings...) ->
    # TODO: Set the topic

  userFromParams: (params) ->
    # hubot < 2.4.2: params = user
    # hubot >= 2.4.2: params = {user: user, ...}
    if params.user then params.user else params

  run: ->
    self = @

    @options =
      token:   process.env.HUBOT_SLACK_TOKEN or null
      team:    process.env.HUBOT_SLACK_TEAM or null<commit_msg>Hack in a fix for robot.messageRoom()<commit_after>Robot   = require('hubot').Robot
Adapter = require('hubot').Adapter
TextMessage = require('hubot').TextMessage
HTTPS = require 'https'

class Slack extends Adapter
  send: (params, strings...) ->
    console.log "Sending message"

    user = @userFromParams(params)

    strings.forEach (str) =>
      # Escape this
      str = str.replace(/&/g, '&amp;')
      str = str.replace(/</g, '&lt;')
      str = str.replace(/>/g, '&gt;')

      # Linkify. We assume that the bot is well-behaved and
      # consistently sending links with the protocol part
      str = str.replace(/((\bhttp)\S+)/g, '<$1>')

      args = JSON.stringify({"channel": user.reply_to, "text": str, username: @robot.name})
      @post "/services/hooks/hubot", args

  reply: (params, strings...) ->
    console.log "Sending reply"

    user = @userFromParams(params)
    strings.forEach (str) =>
      @send params, "#{user.name}: #{str}"

  topic: (params, strings...) ->
    # TODO: Set the topic

  userFromParams: (params) ->
    # hubot < 2.4.2: params = user
    # hubot >= 2.4.2: params = {user: user, ...}
    params = if params.user then params.user else params

    # Ghetto hack to make robot.messageRoom work with Slack's adapter
    #
    # Note: Slack's API here uses rooom ID's, not room names. They look
    # something like C0capitallettersandnumbershere
    params.reply_to ||= params.room

    params

  run: ->
    self = @

    @options =
      token:   process.env.HUBOT_SLACK_TOKEN or null
      team:    process.env.HUBOT_SLACK_TEAM or null
{'fraction_non_alphanumeric': 0.1551783858676827, 'fraction_numerical': 0.005195704883962591, 'mean_word_length': 2.77023498694517, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 23, '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': '3778682', 'n_tokens_mistral': 975, 'n_tokens_neox': 944, 'n_words': 256}