-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3df5fa0
commit 135ebb9
Showing
7 changed files
with
237 additions
and
0 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,23 @@ | ||
# MoDiBo Plugins | ||
|
||
## File Structure | ||
|
||
Plugins should be placed here, each in their own directory. In that directory should be a `main.js` file with the required blueprint components. | ||
|
||
``` | ||
plugins/ | ||
- testPlugin/ | ||
-- main.js | ||
-- supportingFile.js | ||
-- data.json | ||
- testPlugin2/ | ||
-- main.js | ||
``` | ||
|
||
## To Enable a Plugin Installed Here... | ||
|
||
`//TODO` | ||
|
||
## Other `//TODO` | ||
|
||
- Finalize the wording of this document. Limited information about developing plugins should be placed here; the bulk of that should be in the actual documentation somewhere, either in the wiki or website. |
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,67 @@ | ||
const glob = require("glob"); | ||
const utils = require("./utils.js"); | ||
const PLUGIN_FILES = "../plugins/*/main.js"; | ||
|
||
/** | ||
* Load plugin modules | ||
* @param {Discord.Client} bot The instantiated Discord Bot object, for use in calling module onLoad | ||
*/ | ||
function load(bot) { | ||
//TODO Integrate with Config to only load enabled plugins | ||
|
||
utils.logger.log("debug", "Loading Plugins..."); | ||
|
||
glob.sync(PLUGIN_FILES).forEach((file) => { | ||
let dash = file.split("/"); | ||
if (dash.length !== 4) { | ||
return; | ||
} | ||
|
||
let dot = dash[3].split("."); | ||
if (dot.length !== 2) { | ||
return; | ||
} | ||
|
||
let module = require(file); | ||
let key = module.SLUG; | ||
let loaded = false; | ||
|
||
if (module.processCommand) { | ||
utils.plugins.command[key] = module; | ||
loaded = true; | ||
utils.logger.log("debug", `Loaded "${module.NAME}" as a Command Plugin`); | ||
utils.plugins.command[key].processCommand(); | ||
} | ||
|
||
if (module.processMessage) { | ||
utils.plugins.message[key] = module; | ||
loaded = true; | ||
utils.logger.log("debug", `Loaded "${module.NAME}" as a Message Plugin`); | ||
utils.plugins.message[key].processMessage(); | ||
} | ||
|
||
if (module.startCron) { | ||
utils.plugins.cron[key] = module; | ||
loaded = true; | ||
utils.logger.log("debug", `Loaded "${module.NAME}" as a Cron Plugin`); | ||
} | ||
|
||
if (loaded && module.onLoad) { | ||
utils.logger.log("debug", `Running "${module.NAME}" onLoad function...`); | ||
module.onLoad(bot); | ||
} | ||
}); | ||
|
||
utils.logger.log("debug", "All Plugins Loaded"); | ||
for (const [pluginType, list] of Object.entries(utils.plugins)) { | ||
const pluginNames = Object.values(list).map((p) => `"${p.NAME}"`); | ||
utils.logger.log( | ||
"debug", | ||
`${pluginType} plugins: ${pluginNames.join(", ")}` | ||
); | ||
} | ||
} | ||
|
||
module.exports = { | ||
load, | ||
}; |
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