<commit_before>Robot        = require "robot"
HTTPS        = require "https"
EventEmitter = require("events").EventEmitter

class Campfire extends Robot
  send: (user, strings...) ->
    strings.forEach (str) =>
      @bot.Room(user.room).speak str, (err, data) ->
        if err
          console.log "campfire error: #{err}"

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

  run: ->
    self = @
    options =
      token:   process.env.HUBOT_CAMPFIRE_TOKEN
      rooms:   process.env.HUBOT_CAMPFIRE_ROOMS
      account: process.env.HUBOT_CAMPFIRE_ACCOUNT

    console.log options
    bot = new CampfireStreaming(options)
    console.log bot

    bot.on "TextMessage", (id, created, room, user, body) ->
      bot.User user, (err, userData) ->
        if userData.user
          author = self.userForId(userData.user.id, userData.user)
          author.room = room
          self.receive new Robot.Message(author, body)

    bot.Me (err, data) ->
      console.log data
      bot.info = data.user
      bot.name = bot.info.name
      bot.rooms.forEach (room_id) ->
        bot.Room(room_id).join (err, callback) ->
          bot.Room(room_id).listen()

    @bot = bot

exports.Campfire = Campfire

class CampfireStreaming extends EventEmitter
  constructor: (options) ->
    @token         = options.token
    @rooms         = options.rooms.split(",")
    @account       = options.account
    @domain        = @account + ".campfirenow.com"
    @authorization = "Basic " + new Buffer("#{@token}:x").toString("base64")

  Rooms: (callback) ->
    @get "/rooms", callback

  User: (id, callback) ->
    @get "/users/#{id}", callback

  Me: (callback) ->
    @get "/users/me", callback

  Room: (id) ->
    self = @

    show: (callback) ->
      self.post "/room/#{id}", "", callback
    join: (callback) ->
      self.post "/room/#{id}/join", "", callback
    leave: (callback) ->
      self.post "/room/#{id}/leave", "", callback
    lock: (callback) ->
      self.post "/room/#{id}/lock", "", callback
    unlock: (callback) -><commit_msg>provide an explicit error if the token, rooms or account options are not provided<commit_after>Robot        = require "robot"
HTTPS        = require "https"
EventEmitter = require("events").EventEmitter

class Campfire extends Robot
  send: (user, strings...) ->
    strings.forEach (str) =>
      @bot.Room(user.room).speak str, (err, data) ->
        if err
          console.log "campfire error: #{err}"

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

  run: ->
    self = @
    options =
      token:   process.env.HUBOT_CAMPFIRE_TOKEN
      rooms:   process.env.HUBOT_CAMPFIRE_ROOMS
      account: process.env.HUBOT_CAMPFIRE_ACCOUNT

    console.log options
    bot = new CampfireStreaming(options)
    console.log bot

    bot.on "TextMessage", (id, created, room, user, body) ->
      bot.User user, (err, userData) ->
        if userData.user
          author = self.userForId(userData.user.id, userData.user)
          author.room = room
          self.receive new Robot.Message(author, body)

    bot.Me (err, data) ->
      console.log data
      bot.info = data.user
      bot.name = bot.info.name
      bot.rooms.forEach (room_id) ->
        bot.Room(room_id).join (err, callback) ->
          bot.Room(room_id).listen()

    @bot = bot

exports.Campfire = Campfire

class CampfireStreaming extends EventEmitter
  constructor: (options) ->
    if options.token? && options.rooms? && options.account?
      @token         = options.token
      @rooms         = options.rooms.split(",")
      @account       = options.account
      @domain        = @account + ".campfirenow.com"
      @authorization = "Basic " + new Buffer("#{@token}:x").toString("base64")
    else
      throw new Error("Not enough parameters provided. I need a token, rooms and account")

  Rooms: (callback) ->
    @get "/rooms", callback

  User: (id, callback) ->
    @get "/users/#{id}", callback

  Me: (callback) ->
    @get "/users/me", callback

  Room: (id) ->
    self = @

    show: (callback) ->
      self.post "/room/#{id}", "", callback
    join: (callback) ->
      self.post "/room/#{id}/join", "", callback
    leave: (callback) ->
      self.post "/room/#{id}/leave", "", callback
    lock: (callback) ->
      self.post "/room/#{id}/lock", "", callback
    unlock: (callback) ->
{'fraction_non_alphanumeric': 0.154627539503386, 'fraction_numerical': 0.0009029345372460496, 'mean_word_length': 2.3876146788990824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 45, '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': '5598423', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1402, 'n_words': 337}