     log.info "Set factoid key #{key} for team #{team}"
     return cb null
 
+getKarma = (team, key, cb) ->
+  db = getDatabase team
+  if not db? then return cb "Couldn't get database for team #{team}"
+
+  db.get "SELECT value FROM karma WHERE key = $key", {$key: key}, (err, row) ->
+    if err then return cb "Couldn't get karma for team #{team}: #{err}"
+    return cb null, row?.value or null
+
+setKarma = (team, key, value, cb) ->
+  db = getDatabase team
+  if not db? then return cb "Couldn't get database for team #{team}"
+
+  db.run "INSERT OR REPLACE INTO karma VALUES($key, $value)", {$key: key, $value: value}, (err) ->
+    if err then return cb "Couldn't update karma for team #{team}: #{err}"
+    log.info "Set factoid key #{key} for team #{team}"
+    return cb null
+
 
 # BOTS ---------------------------------------------------------------------#{{{1
 

        update key, value

      else if current and isAppending
        value = "#{current} or #{value}"
        update key, value

      else if current == value

      else
        update key, value

    return

  # Karma query
  else if (/^karma\s+for\s+/i).test(msg)
    key = msg.replace(/^karma\s+for\s+/i, '').replace(/\?+$/, '')
    getKarma team, key, (err, current) ->
      current or= 0
      if err
        log.error err
        if isVerbose then reply "There was an error getting the karma. Please try again."
      else
        reply "Karma for #{key} is #{current}"
      return
    return

  # Karma increment/decrement
  else if /\+\+(\s#.+)?$/.test(msg)
    if isDirect then return reply "You cannot secretly change the karma for something!"
    key = msg.split(/\+\+/)[0]
    getKarma team, key, (err, current) ->
      if err then return log.error(err)
      value = Number(current or 0)
      value++
      setKarma team, key, value, (err) ->
        if err
          log.error err
          if isVerbose then reply "There was an error changing the karma. Please try again."
        return
      return
    return

  # Karma decrement
  else if /\-\-(\s#.+)?$/.test(msg)
    if isDirect then return reply "You cannot secretly change the karma for something!"
    key = msg.split(/\-\-/)[0]
    getKarma team, key, (err, current) ->
      if err then return log.error(err)
      value = Number(current or 0)
      value--
      setKarma team, key, value, (err) ->
        if err
          log.error err
          if isVerbose then reply "There was an error changing the karma. Please try again."
        return
      return
    return

  # Getting regular factoids, last chance {{{3
