Kassy 的 Facebook 模块不会 运行 即使遵循所有说明
Facebook module for Kassy won't run even though all instructions are being followed
我为 Kassy 编写了这个模块,用于通过 HummingBird API 搜索动漫。该模块加载正常,甚至帮助命令 /help humming
returns 适当的帮助消息。但我无法让它响应搜索查询
控制台只显示
An unhandled error occurred. Start as debug for details.
并继续收听下一条消息。我已经在调试模式下尝试 运行 控制台(如 Kassy 文档中所述),但控制台显示相同的消息。我尝试使用 KPM 安装模块,但结果相同。
这些是 modules
目录
中名为 humming
的目录中的两个文件
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
中的方法语法
我快速查看了一下,无法复制未处理的错误,但是如果您将搜索回调中的代码块更改为
if(!error){
api.sendMessage(response, event.thread_id);
} else{
console.debug(error);
}
这会将原始响应打印到输出。
如果再次出现异常可以发送以下命令
/期"title""description"满
这会将大量配置数据转储到 Kassy 上的一个问题 github。
我为 Kassy 编写了这个模块,用于通过 HummingBird API 搜索动漫。该模块加载正常,甚至帮助命令 /help humming
returns 适当的帮助消息。但我无法让它响应搜索查询
控制台只显示
An unhandled error occurred. Start as debug for details.
并继续收听下一条消息。我已经在调试模式下尝试 运行 控制台(如 Kassy 文档中所述),但控制台显示相同的消息。我尝试使用 KPM 安装模块,但结果相同。
这些是 modules
目录
humming
的目录中的两个文件
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
我快速查看了一下,无法复制未处理的错误,但是如果您将搜索回调中的代码块更改为
if(!error){
api.sendMessage(response, event.thread_id);
} else{
console.debug(error);
}
这会将原始响应打印到输出。
如果再次出现异常可以发送以下命令
/期"title""description"满
这会将大量配置数据转储到 Kassy 上的一个问题 github。