Last active
July 5, 2017 19:56
-
-
Save geerteltink/30744edc188f431e614eeff413fcd039 to your computer and use it in GitHub Desktop.
Some Hubot scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); | |
} | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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