<commit_before># Description
#   Manages a list of books, using the google books api for data
#
# Commands:
#   hubot booklist random - Returns a random book
#   hubot booklist add <title> - adds the book to the booklist
#   hubot booklist lookup <index> - retrieves book information
#   hubot booklist - displays full booklist
#   hubot booklist edit <index> <title> - edit book at index with new title
#   hubot booklist review book <index> stars <rating> - rates the selected book
#   hubot booklist add copy <index> <location> - add copy of book with owner and location details
#   hubot booklist copies - retrieves booklist copies
#
# Author:
#   <NAME> & <NAME>
#
# Title image by <NAME> - hosted by unsplash.com with CCO-1.0 License

module.exports = (robot) ->

  BOOK =
    TITLE: 0
    AUTHOR: 1
    CATEGORY: 2
    IMAGE: 3
    RATING: 4
    REVIEWCOUNT: 5
    COPIES: 6

  TITLE_IMAGE = 'https://goo.gl/g5Itaz'
  BOOKCASE_URL = process.env.HUBOT_BOOKCASE_URL;

  robot.hear /booklist initialize/i, (res) ->
    if robot.brain.get('booklist')
        emitString(res, "Booklist already exists")
    else
      robot.brain.set('booklist', [])
      emitString(res, "Booklist Initialized")

  robot.hear /booklist db (.*)$/i, (res) ->
    booklist = getBookList()
    if res.match[1] == "save"
      return emitString(res, "Null booklist") if booklist is null
      if booklist.length == 0
        emitString(res,"no-books")
      else
        robot.http(BOOKCASE_URL + '/api/books')
        .header("Content-Type", "application/json")
        .header("Accept", "*/*")
        .post(JSON.stringify(booklist)) (err, resp, body) ->
          if err
            emitString(res, "BACKUP ERROR -" + err)
          else
            emitString(res, "JSON.stringify(booklist)")
    else if res.match[1] == "load"
      if booklist and booklist.length > 0
        return emitString(res, "Booklist already exists")
      else
        robot.http(BOOKCASE_URL + '/api/books/newest')
        .get() (err, resp, body) ->
          if err
            emitString(res, "RELOAD ERROR - " + err)
          else
            robot.brain.set 'booklist', JSON.parse(body)
            emitString(res, "Booklist re-loaded")

  robot.hear /booklist add (?:(?!copy))(.*)$/i, (res) ->
    rawBookToAdd = res.match[1]
    rating = 0
    nbrOfReviews = 0

    addBook res, rawBookToAdd, rating, nbrOfReviews, null, (err) ->
<commit_msg>fixed save test<commit_after># Description
#   Manages a list of books, using the google books api for data
#
# Commands:
#   hubot booklist random - Returns a random book
#   hubot booklist add <title> - adds the book to the booklist
#   hubot booklist lookup <index> - retrieves book information
#   hubot booklist - displays full booklist
#   hubot booklist edit <index> <title> - edit book at index with new title
#   hubot booklist review book <index> stars <rating> - rates the selected book
#   hubot booklist add copy <index> <location> - add copy of book with owner and location details
#   hubot booklist copies - retrieves booklist copies
#
# Author:
#   <NAME> & <NAME>
#
# Title image by <NAME> - hosted by unsplash.com with CCO-1.0 License

module.exports = (robot) ->

  BOOK =
    TITLE: 0
    AUTHOR: 1
    CATEGORY: 2
    IMAGE: 3
    RATING: 4
    REVIEWCOUNT: 5
    COPIES: 6

  TITLE_IMAGE = 'https://goo.gl/g5Itaz'
  BOOKCASE_URL = process.env.HUBOT_BOOKCASE_URL;

  robot.hear /booklist initialize/i, (res) ->
    if robot.brain.get('booklist')
        emitString(res, "Booklist already exists")
    else
      robot.brain.set('booklist', [])
      emitString(res, "Booklist Initialized")

  robot.hear /booklist db (.*)$/i, (res) ->
    booklist = getBookList()
    if res.match[1] == "save"
      return emitString(res, "Null booklist") if booklist is null
      if booklist.length == 0
        emitString(res,"no-books")
      else
        robot.http(BOOKCASE_URL + '/api/books')
        .header("Content-Type", "application/json")
        .header("Accept", "*/*")
        .post(JSON.stringify(booklist)) (err, resp, body) ->
          if err
            emitString(res, "BACKUP ERROR -" + err)
          else
            emitString(res, "Booklist backed up")
    else if res.match[1] == "load"
      if booklist and booklist.length > 0
        return emitString(res, "Booklist already exists")
      else
        robot.http(BOOKCASE_URL + '/api/books/newest')
        .get() (err, resp, body) ->
          if err
            emitString(res, "RELOAD ERROR - " + err)
          else
            robot.brain.set 'booklist', JSON.parse(body)
            emitString(res, "Booklist re-loaded")

  robot.hear /booklist add (?:(?!copy))(.*)$/i, (res) ->
    rawBookToAdd = res.match[1]
    rating = 0
    nbrOfReviews = 0

    addBook res, rawBookToAdd, rating, nbrOfReviews, null, (err) ->

{'fraction_non_alphanumeric': 0.12334162520729684, 'fraction_numerical': 0.007048092868988391, 'mean_word_length': 2.590029761904762, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, 'https://': 2, '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': '6572067', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1585, 'n_words': 464}