New modules:
* Commands, that lists available commands * Reload, that allows Janet to reload the module list (therefore loading new modules) via a pm
This commit is contained in:
1 parent
a2638c4624
commit
deb70524cd
4 files changed
+94
-14
No files matched your search
@@ -0,0 +1,35 @@
|
||||
const fs = require('fs')
|
||||
|
||||
const JanetModule = require('./janetmodule')
|
||||
|
||||
class Commands extends JanetModule {
|
||||
constructor(client) {
|
||||
super({
|
||||
name: 'Commands',
|
||||
command: 'what commands are available?',
|
||||
showInHelp: true,
|
||||
methods: ['message'],
|
||||
}, client)
|
||||
}
|
||||
|
||||
respond(event, data) {
|
||||
fs.readdir('modules', (err, files) => {
|
||||
let commands = [];
|
||||
|
||||
for (let file of files) {
|
||||
let title = file.substr(0, file.length - 3)
|
||||
if (title !== 'janetmodule') {
|
||||
let module = require('../modules/' + title)(this.client)
|
||||
if (module.showInHelp) {
|
||||
commands.push(module.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.client.say(commands.join(', '))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = (client) => {
|
||||
return new Commands(client)
|
||||
}
|
||||
@@ -15,7 +15,7 @@ class JanetModule {
|
||||
'command',
|
||||
'methods'
|
||||
]
|
||||
|
||||
|
||||
for(let key of keys) {
|
||||
if(!(key in opts)) {
|
||||
throw new TypeError("Key " + key + " is missing from Module options")
|
||||
@@ -30,7 +30,7 @@ class JanetModule {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Response to the input, triggered by the command
|
||||
* @return A string response
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
const JanetModule = require('./janetmodule')
|
||||
|
||||
class Reload extends JanetModule {
|
||||
|
||||
constructor(client) {
|
||||
super({
|
||||
name: 'Reload',
|
||||
showInHelp: false,
|
||||
command: 'reload',
|
||||
methods: ['pm']
|
||||
}, client)
|
||||
}
|
||||
|
||||
respond(event, data) {
|
||||
this.client.say("Just checking to see if I've got any new modules...")
|
||||
this.client.clearModules();
|
||||
this.client.loadModules();
|
||||
this.client.say("I'm back now")
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = (client) => {
|
||||
return new Reload(client)
|
||||
}
|
||||
Reference in new issue
Block a user