我已经为Kassy写了这个模块,通过HummingBird API搜索动漫。模块加载正常,甚至帮助命令/help humming
返回相应的帮助消息。但我不能让它回应搜索查询
控制台只显示
An unhandled error occurred. Start as debug for details.
并继续收听下一条消息。我尝试在调试模式下运行控制台(如Kassy文档中所述),但控制台显示相同的消息。我尝试使用KPM安装模块,但结果相同。
这些是humming
目录
modules
的目录中的两个文件
humming.js
console.debug('line 10');
var request = require.safe('request');
/*
* Paths
*/
var HUMMINGBIRD_HOST = "hummingbird.me/api/v1";
var HUMMINGBIRD_SEARCH = "/search/anime/";
exports.match = function(text, commandPrefix) {
console.debug('line 23');
return text.startsWith(commandPrefix + 'humming');
};
/*
Method that provides help strings for use with this module.
*/
exports.help = function(commandPrefix) {
return [[commandPrefix + 'humming <query>','Searches Anime or Manga when you are too lazy to make a few clicks']];
};
/*
The main entry point of the module. This will be called by Kassy whenever the match function
above returns true.
*/
exports.run = function(api, event) {
var query = event.body.substr(8);
console.debug('line 40');
search(query, function(error, response){
// Callback calls the parser if no errors were registered
if(error !== null){
api.sendMessage(parse(response), event.thread_id);
} else{
console.debug(error);
}
});
};
function parse(query){
// testing
return JSON.stringify(query);
// return 'parser reached';
}
/**
* Retrieves information about an anime as a JSON object.
*
* query: string to search
* callback: takes the error, and data
*/
function search(query, callback) {
request.get({
url: "https://" + HUMMINGBIRD_HOST +
HUMMINGBIRD_SEARCH + "?query=" + query,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}, function(err, res, body) {
console.debug('line 73');
if(err) {
if(res) {
callback("Request error: " + err + ", " + res.statusCode, body);
}
else {
callback("Connection error: not connected to internet", body);
}
}
else {
callback(null, body);
}
});
}
kassy.json
{
"name": "humming",
"version": 2.0,
"startup": "humming.js"
}
您会注意到调试器日志的一些调用,但这些调用从未在调试模式下显示,因此我不确定模块是否完全没有执行或者我的调试是否有问题。这是我用来启用调试的启动命令
node debug main.js facebook test
我已尝试将模块重命名为test
,manga
,anime
等,假设系统中可能存在歧义,但没有任何变化。
我不确定我的request.get
方法的实现,因为我是Javascript的新手并且遵循this GitHub project的方法语法
答案 0 :(得分:1)
我快速查看并无法复制未处理的错误,但如果您将搜索回调中的代码块更改为
if(!error){
api.sendMessage(response, event.thread_id);
} else{
console.debug(error);
}
&#13;
这将打印输出的原始响应。
如果再次发生异常,您可以发送以下命令
/ issue&#34; title&#34; &#34;描述&#34;全强>
这会将大量配置数据转储到Kassy github上的问题。