var http = require('http'),
    requestify = require('requestify');
module.exports.commands = ['quo', 'qudb', 'quodb', 'qdb'];

var bot;
var conf = null;

module.exports.init = function(b) {
  bot = b;
  bot.getConfig("qdb.json", function(err, co) {
    if(err) console.log("Error with QDB module, no conf");
    else conf = co;
  });
};

module.exports.run = function(rem, parts, reply, command, from, to, text, raw) {
  if(to[0] != '#' && to[0] != '&') return; // only allow this in channels.
  if(conf === null) return;

  var scrollbackModule = bot.modules['sirc-scrollback'];
  if(!scrollbackModule) return console.log("No scrollback, can't qdb");

  scrollbackModule.getFormattedScrollbackLinesFromRanges(to, parts, function(err, res) {
    if(err) return reply(err);
    if(res.match(/(pls|#)noquo/)) return reply("don't be a deck, betch");

    requestify.post(conf.baseUrl + '/api/quote', {
      quote: res,
      source: conf.source + to
    }).then(function(response) {
      // Success
      var id = 'unknown';
      try {
        id = JSON.parse(response.body).id;
			} catch(e){
				return reply("Could not get an id from response: " + response.body);
			}
      reply(conf.baseUrl + "/#/quote/" + id);
		}).error(function(err) {
			reply("Something went wrong: " + err);
		});
  });
};


@@ -64,67 +64,8 @@
 y');
-%0Amodule.exports.commands = %5B'quo', 'qudb', 'quodb', 'qdb'%5D;
 %0A%0Ava
@@ -273,16 +273,76 @@
 %7D);%0A%7D;%0A%0A
+module.exports.commands = %5B'quo', 'qudb', 'quodb', 'qdb'%5D;%0A%0A
 module.e
@@ -986,192 +986,46 @@
     
-// Success%0A      var id = 'unknown';%0A      try %7B%0A        id = JSON.parse(response.body).id;%0A%09%09%09%7D catch(e)%7B%0A%09%09%09%09return reply(%22Could not get an id from response: %22 + response.body);%0A%09%09%09%7D
+var id = JSON.parse(response.body).id;
 %0A   
@@ -1071,18 +1071,19 @@
 d);%0A
-%09%09%7D).error
+    %7D).fail
 (fun
@@ -1099,11 +1099,14 @@
 ) %7B%0A
-%09%09%09
+      
 repl
@@ -1144,10 +1144,12 @@
 r);%0A
-%09%09
+    
 %7D);%0A

Fix qdb module error handling