         if err then return cb "Couldn't update metadata for team #{team}: #{err}"
         log.info "Set metadata key #{key} for team #{team} with existing table"
         return cb null
+
+updateBotMetadata = (bot, team, cb) ->
+  db = getDatabase team
+  if not db? then return cb "Couldn't get database for team #{team}"
+
+  bot.mbMeta ?= {}
+  db.all "SELECT key, value FROM metadata", (err, rows) ->
+    if err then return cb "Couldn't get metadata for team #{team}: #{err}"
+    for {key, value} in rows
+      bot.mbMeta[key] = value
+    return cb null
+
 
 # BOTS --------------------------------------------------------------------------
 

        (cb) -> db.run "CREATE TABLE metadata (key TEXT PRIMARY KEY, value TEXT)", cb
        (cb) -> db.run "CREATE TABLE factoids (key TEXT PRIMARY KEY, value TEXT, last_edit TEXT)", cb
        (cb) -> db.run "INSERT INTO metadata VALUES($key, $value)", {$key: key, $value: value}, cb
      ], (err) ->
        if err then return cb "Couldn't initialize metadata for team #{team}: #{err}"
        log.info "Set metadata key #{key} for team #{team} with new table"

      #log.error "Failed to reply: #{err}"
#for i in ['message_received', 'mention', 'direct_message', 'direct_mention', 'ambient']
  #controller.on i, handler(i)

controller.on 'direct_mention', (bot, msg) ->
  return if msg.user is bot.identity?.id
