<commit_before>SlackClient = require 'slack-client'

class SlackConnection
  constructor: (@token) ->
    @client = new SlackClient @token, true, true

    @client.on 'error', @.error
    @client.on 'loggedIn', @.loggedIn
    @client.on 'open', @.open
    @client.on 'close', @.clientClose
    @client.on 'message', @.message
    @client.on 'userChange', @.userChange

    @client.login()

  error: (error) =>
    console.log "Received error #{JSON.stringify error}"
    console.log error.stack
    console.log "Exiting in 1 second"
    setTimeout process.exit.bind(process, 1), 1000

  loggedIn: (self, team) =>
    console.log "Logged in as #{self.name} of #{team.name}, but not yet connected"

    # store a copy of our own user data
    @self = self

  open: =>
    console.log 'Slack client now connected'

  clientClose: =>
    # Don't actually do anything since we may reconnect in the future
    console.log 'Slack client closed, waiting for reconnect'

  message: (msg) =>
    # Ignore our own messages
    return if msg.user == @self.id
    console.log msg.text

  userChange: (user) =>

# Export class for unit tests
module.exports = SlackConnection<commit_msg>slightly less noisy<commit_after>SlackClient = require 'slack-client'

class SlackConnection
  constructor: (@token) ->
    @client = new SlackClient @token, true, true

    @client.on 'error', @.error
    @client.on 'loggedIn', @.loggedIn
    @client.on 'open', @.open
    @client.on 'close', @.clientClose
    @client.on 'message', @.message
    @client.on 'userChange', @.userChange

    @client.login()

  error: (error) =>
    console.log "Received error #{JSON.stringify error}"
    console.log error.stack
    console.log "Exiting in 1 second"
    setTimeout process.exit.bind(process, 1), 1000

  loggedIn: (self, team) =>
    console.log "Logged in as #{self.name} of #{team.name}, but not yet connected"

  open: =>
    console.log 'Slack client now connected'

  clientClose: =>
    # Don't actually do anything since we may reconnect in the future
    console.log 'Slack client closed, waiting for reconnect'

  message: (msg) =>
    # Ignore our own messages
    return if msg.user == @self.id
    if msg.type == 'message'
      console.log "#{msg._client.team.name} / #{msg.channel} / #{msg.user} - #{msg.text}"
    else
      console.log "Unknown message type, #{msg.type}"

  userChange: (user) =>

# Export class for unit tests
module.exports = SlackConnection
{'fraction_non_alphanumeric': 0.13066557778685178, 'fraction_numerical': 0.004899959167006942, 'mean_word_length': 3.246100519930676, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '5154421', 'n_tokens_mistral': 795, 'n_tokens_neox': 763, 'n_words': 243}