<commit_before>Robot        = require '../robot'
Adapter      = require '../adapter'

HTTPS        = require 'https'
EventEmitter = require('events').EventEmitter

class Campfire extends Adapter

  send: (user, strings...) ->
    if strings.length > 0
      @bot.Room(user.room).speak strings.shift(), (err, data) =>
        @robot.logger.error "Campfire error: #{err}" if err?
        @send user, strings...

  reply: (user, strings...) ->
    @send user, strings.map((str) -> "#{user.name}: #{str}")...

  topic: (user, strings...) ->
    @bot.Room(user.room).topic strings.join(" / "), (err, data) =>
      @robot.logger.error "Campfire error: #{err}" if err?

  run: ->
    self = @

    options =
      token:   process.env.HUBOT_CAMPFIRE_TOKEN
      rooms:   process.env.HUBOT_CAMPFIRE_ROOMS
      account: process.env.HUBOT_CAMPFIRE_ACCOUNT

    bot = new CampfireStreaming(options, @robot)

    withAuthor = (callback) -> (id, created, room, user, body) ->
      bot.User user, (err, userData) ->
        if userData.user
          author = self.userForId(userData.user.id, userData.user)
          self.robot.brain.data.users[userData.user.id].name = userData.user.name
          self.robot.brain.data.users[userData.user.id].email_address = userData.user.email_address
          author.room = room
          callback id, created, room, user, body, author

    bot.on "TextMessage", withAuthor (id, created, room, user, body, author) ->
      unless bot.info.id == author.id
        self.receive new Robot.TextMessage(author, body)

    bot.on "EnterMessage", withAuthor (id, created, room, user, body, author) ->
      unless bot.info.id == author.id
        self.receive new Robot.EnterMessage(author)

    bot.on "LeaveMessage", withAuthor (id, created, room, user, body, author) ->
      unless bot.info.id == author.id
        self.receive new Robot.LeaveMessage(author)

    bot.Me (err, data) ->
      bot.info = data.user
      bot.name = bot.info.name

      for roomId in bot.rooms
        do (roomId) ->
          bot.Room(roomId).join (err, callback) ->
            bot.Room(roomId).listen()

    bot.on "reconnect", (roomId) ->
      bot.Room(roomId).join (err, callback) ->
        bot.Room(roomId).listen()

    @bot = bot

exports.use = (robot) ->
  new Campfire robot<commit_msg>Lets add some logging<commit_after>Robot        = require '../robot'
Adapter      = require '../adapter'

HTTPS        = require 'https'
EventEmitter = require('events').EventEmitter

class Campfire extends Adapter

  send: (user, strings...) ->
    if strings.length > 0
      @bot.Room(user.room).speak strings.shift(), (err, data) =>
        @robot.logger.error "Campfire error: #{err}" if err?
        @send user, strings...

  reply: (user, strings...) ->
    @send user, strings.map((str) -> "#{user.name}: #{str}")...

  topic: (user, strings...) ->
    @bot.Room(user.room).topic strings.join(" / "), (err, data) =>
      @robot.logger.error "Campfire error: #{err}" if err?

  run: ->
    self = @

    options =
      token:   process.env.HUBOT_CAMPFIRE_TOKEN
      rooms:   process.env.HUBOT_CAMPFIRE_ROOMS
      account: process.env.HUBOT_CAMPFIRE_ACCOUNT

    bot = new CampfireStreaming(options, @robot)

    withAuthor = (callback) -> (id, created, room, user, body) ->
      if user is null
        console.log "Null user!"

      bot.User user, (err, userData) ->
        if userData.user
          author = self.userForId(userData.user.id, userData.user)
          self.robot.brain.data.users[userData.user.id].name = userData.user.name
          self.robot.brain.data.users[userData.user.id].email_address = userData.user.email_address
          author.room = room
          callback id, created, room, user, body, author

    bot.on "TextMessage", withAuthor (id, created, room, user, body, author) ->
      unless bot.info.id == author.id
        self.receive new Robot.TextMessage(author, body)

    bot.on "EnterMessage", withAuthor (id, created, room, user, body, author) ->
      unless bot.info.id == author.id
        self.receive new Robot.EnterMessage(author)

    bot.on "LeaveMessage", withAuthor (id, created, room, user, body, author) ->
      unless bot.info.id == author.id
        self.receive new Robot.LeaveMessage(author)
    
    bot.on "TimestampMessage", withAuthor (id, created, room, user , author) ->
      console.log "Timestamp"
      console.log author

    bot.Me (err, data) ->
      bot.info = data.user
      bot.name = bot.info.name

      for roomId in bot.rooms
        do (roomId) ->
          bot.Room(roomId).join (err, callback) ->
            bot.Room(roomId).listen()

    bot.on "reconnect", (roomId) ->
      bot.Room(roomId).join (err, callback) ->
        bot.Room(roomId).listen()

    @bot = bot

exports.use = (robot) ->
  new Campfire robot
{'fraction_non_alphanumeric': 0.1470710427918571, 'fraction_numerical': 0.0004154549231408392, 'mean_word_length': 2.5145985401459856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, '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': '95819', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1542, 'n_words': 369}