This repository has been archived by the owner on Nov 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(re) added optional built-in help generator close #6
- Loading branch information
Showing
10 changed files
with
363 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const FILENAME = 'command-list.txt'; | ||
const COMMAND_DESCRIPTION = 'Show this message'; | ||
|
||
/** | ||
* @param {Array<Listener>} listeners | ||
* @return {string} | ||
*/ | ||
function generateHelp(listeners) { | ||
let helpText = ''; | ||
|
||
listeners.forEach(listener => { | ||
const listenerType = listener.value instanceof RegExp ? `${listener.type} (regex)` : listener.type; | ||
const listenerValue = listener.type === 'reaction_added' ? listener.value.toString().replace('\\', '') : listener.value.toString(); | ||
helpText += `type: ${listenerType}\n`; | ||
helpText += `command: ${listenerValue}\n`; | ||
helpText += `description: ${listener.description === '' ? '-' : listener.description}\n\n`; | ||
}); | ||
|
||
return helpText.trim(); | ||
} | ||
|
||
let helpListener; | ||
|
||
export default function helpGenerator(opts) { | ||
return function plugin(robot) { | ||
if (opts.enable) { | ||
helpListener = robot.listen(/help/, (req, res) => { | ||
const helpText = generateHelp(robot.getAllListeners()); | ||
return res.upload(FILENAME, helpText).send(); | ||
}) | ||
.desc(COMMAND_DESCRIPTION) | ||
.acl(robot.acls.dynamicMention); | ||
} else if (helpListener) { | ||
robot.removeListener(helpListener.id); | ||
} | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import helpGenerator from './help-generator'; | ||
|
||
export default { | ||
helpGenerator | ||
}; |
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
Oops, something went wrong.