 module.exports = (robot) ->
   class Factoid
     constructor: (name, data) ->
+      if !data
+        data = {}
       @name = name
       @tidbits = []
       @alias = false
-      @readonly = data.readonly
+      @readonly = false
+      if data.readonly
+        @readonly = true
       if data.alias
         @alias = data.alias
-      else
+      else if data.tidbits
         for tid in data.tidbits
           @tidbits.push tid
     can_edit: (user) ->

        tidbits: @tidbits
      }
    save: () ->
      robot.brain.data.factoids[@name] = @toObj()


  class FactoidHandler
    constructor: () ->
      @facts = {}
      robot.brain.on 'loaded', (data) =>
        @facts = {}

      response.push util.inspect last_factoid.last_vars, { depth: null }
    msg.reply response.join ' '


  robot.respond /(.*?) (?:is ?|are ?)(<\w+>)\s*(.*)()/i, robot.factoid.setAddressed
  robot.hear /^(.*?) (?:is ?|are ?)(<\w+>)\s*(.*)()/i, robot.factoid.set
  robot.respond /(.*?)\s+(<\w+(?:'t)?>)\s*(.*)()/i, robot.factoid.setAddressed
  robot.hear /^(.*?)\s+(<\w+(?:'t)?>)\s*(.*)()/i, robot.factoid.setAddressed
  robot.respond /(.*?)(<'s>)\s+(.*)()/i, robot.factoid.set
  robot.hear /^(.*?)(<'s>)\s+(.*)()/i, robot.factoid.setAdressed
  robot.respond /(.*?)\s+(is(?: also)?|are)\s+(.*)/i, robot.factoid.set
  robot.hear /^(.*?)\s+(is(?: also)?|are)\s+(.*)/i, robot.factoid.setAddressed

  ## FIXME, make these loaded once brain is loaded so it doesn't need to do wildcard match
  robot.hear /^(.*)\??$/, (msg) =>
    factoid_name = msg.match[1].trim()
    factoid = robot.factoid.get factoid_name
