     if not (domain && domain.match(/^(?:[A-Za-z0-9\-\.]+\.)?phate\.(?:io|cc|us|tw|org)$/i)?)
       safe_referer = strip_hyper_links(strip_irc_colors(referer))
       throw "REFERRAL_DENIED: #{safe_referer}"
+
+  loadBlacklist: =>
+    self = this
+    self.db.collection(self.dbConfigName).find(
+      name: 'blacklist'
+    ).sort(id: 1).toArray (err, items) ->
+      throw err if err
+      return if items.length == 0
+      self.blacklist = JSON.parse(items[0].text)
+      DEBUG('Load %d blacklist items from database.', Object.keys(self.blacklist).length)
+
+  saveBlacklist: =>
+    self = this
+    criteria =
+      name: 'blacklist'
+    data =
+      name: 'blacklist'
+      text: JSON.stringify(self.blacklist)
+    options =
+      upsert: true
+    self.db.collection(self.dbConfigName).update criteria, data, options, (err, count, status) ->
+      throw err if err
+      DEBUG('Save blacklist to database. Returned %s', status)
 
   blacklistCheck: (ip) =>
     self = this


    self.dbUser = process.env.OPENSHIFT_MONGODB_DB_USERNAME
    self.dbPass = process.env.OPENSHIFT_MONGODB_DB_PASSWORD
    self.dbName = 'nodedanmaku'
    self.emitter = new emitter()

  setupVariables: =>

        when 'ban'
          target = param1
          duration = parseInt(param2) || null
          danmaku.ban(target, nick, 'IRC Command', duration)
          return
        when 'unban'
          target = param1
          danmaku.unban(target, nick)
          return
        when 'say'
          message = if param2 then "#{param1} #{param2}" else param1
          danmaku.say message, '127.0.0.1',
            color: '0,255,0,0.9'
          return
        when 'mute'
          danmaku.mute = true
