Skip to content

Instantly share code, notes, and snippets.

@geerteltink
Last active July 5, 2017 19:56
Show Gist options
  • Save geerteltink/30744edc188f431e614eeff413fcd039 to your computer and use it in GitHub Desktop.
Save geerteltink/30744edc188f431e614eeff413fcd039 to your computer and use it in GitHub Desktop.
Some Hubot scripts
'use strict';
// Description:
// Catch all unhandled messages directed to me.
//
// Notes:
// If nothing else catches a message, it's mine!
module.exports = (robot) => {
robot.catchAll((msg) => {
const regexp = new RegExp('^(@?' + robot.alias + ':?|' + robot.name + ')', 'i');
const matches = msg.message.text.match(regexp);
if (matches !== null && matches.length > 1) {
msg.reply(`I am unable to comply.`);
msg.finish();
}
});
};
'use strict';
// Description:
// Default error handler.
//
// Notes:
// If nothing else catches the error, it's mine!
/**
*
* @param robot
* @returns {*}
*/
module.exports = (robot) => {
robot.error((err, res) => {
// If there is a response, reply
if (res !== null) {
res.reply(`Oops, and that's an error: ${err.message}`);
}
let errorMessage = `ERROR:\n`;
if (err.stack !== null) {
errorMessage += err.stack;
} else {
errorMessage += err.toString();
}
// Log system error
robot.logger.error(errorMessage);
// Prepare adapter message
errorMessage = errorMessage.split('\n').map((line) => {
return ' ' + line;
}).join('\n');
// Send system error
//robot.adapter.client.send({room: 'server-log'}, errorMessage);
robot.messageRoom('server-log', errorMessage);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment