<commit_before># Description:
#   factoid (responses) support for hubot
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   None
#
# Notes:
#   Copyright (c) 2013 <NAME>
#   Licensed under the MIT license.
#
# Author:
#   halkeye

'use strict'

module.exports = (robot) ->

<commit_msg>factoids and actions<commit_after># Description:
#   factoid (responses) support for hubot
#
# Dependencies:
#   None
#
# Configuration:
#   None
#
# Commands:
#   None
#
# Notes:
#   Copyright (c) 2013 <NAME>
#   Licensed under the MIT license.
#
# Author:
#   halkeye

'use strict'

module.exports = (robot) ->
  if robot.adapter.bot?
    robot.adapter.action = (envelope, strings...) ->
      target = @_getTargetFromEnvelope envelope
      unless target
        return console.log "ERROR: Not sure who to send to. envelope=", envelope
      for str in strings
        @bot.action target, str

  class Factoids
    @get = (str) ->
      if !robot.brain.data.factoids
        return
      factoid = robot.brain.data.factoids[str]
      if !factoid
        return
      if factoid.alias
        return @get factoid.alias
      return factoid.tidbits[Math.floor(Math.random() * factoid.tidbits.length)]

  robot.hear /^(.*)\??$/, (msg) =>
    factoid_name = msg.match[1]
    factoid = Factoids.get factoid_name
    if !factoid
      return
    console.log factoid
    tidbit = factoid.tidbit

    if robot.variables?
      tidbit = robot.variables.process tidbit, msg.message.user

    if factoid.verb == "<reply>"
      msg.send tidbit
    else if factoid.verb == "<action>"
      if msg.action?
        msg.action tidbit
      else
        msg.send "/me " + tidbit
    else if factoid.verb == "is" && factoid_name.toLowerCase() == robot.name.toLowerCase()
      msg.send "I am " + tidbit
    else
      msg.send [factoid_name, factoid.verb, factoid.tidbit].join ' '


{'fraction_non_alphanumeric': 0.12260127931769722, 'fraction_numerical': 0.004797441364605544, 'mean_word_length': 2.5957854406130267, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 12, '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': '950806', 'n_tokens_mistral': 641, 'n_tokens_neox': 627, 'n_words': 160}