Module system, initial creation of Janet

This commit is contained in:
Lewis Dale committed 2017-02-03 16:28:18 +00:00
1 parent aedcdfff7c
commit 4c55837193
5 files changed
+147

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
const Module = require('./module')
class Greet extends Module {
constructor() {
super({
name: 'Greet',
showInHelp: false,
command: 'Hello',
methods: ['join']
})
this.test = {}
}
respond(input) {
return "Hello, " + input
}
}
module.exports = new Greet()
+38
View File
@@ -0,0 +1,38 @@
class Module {
/**
* Construct a new Modules instance
* @param opts: An object containing module information
* @param opts.name: The name of the module
* @param opts.showInHelp: Boolean to determine if a module should be a listed command
* @param opts.command: The command that triggers the action
* @param opts.methods: A list of contact methods where the command is available
*/
constructor(opts = {}) {
let keys = [
'name',
'showInHelp',
'command',
'methods'
]
for(let key of keys) {
if(!(key in opts)) {
throw new TypeError("Key " + key + " is missing from Module options")
}
this[key] = opts[key]
}
}
/**
* Response to the input, triggered by the command
* @return A string response
*/
respond(input) {
throw new TypeError("Function respond has not been implemented. Please override Module.respond()")
}
}
module.exports = Module