This repository has been archived by the owner on Aug 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Monitors Loading && Monitors Running * Message Event ignores bot messages and runs monitors * Profanity- 1st Monitor Example * Ignores Bots, Outputs Error Stacks into console * Semver minor bump Monitors * removal of max-len from linter * oops. I mean semver patch
- Loading branch information
1 parent
4ca7374
commit b396018
Showing
6 changed files
with
102 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const fs = require("fs-extra"); | ||
const path = require("path"); | ||
|
||
module.exports = (client) => { | ||
client.commandMonitors.clear(); | ||
const counts = [0, 0]; | ||
loadCommandMonitors(client, client.coreBaseDir, counts).then((counts) => { | ||
loadCommandMonitors(client, client.clientBaseDir, counts).then((counts) => { | ||
const [p, o] = counts; | ||
client.funcs.log(`Loaded ${p} command monitors, with ${o} optional.`); | ||
}); | ||
}); | ||
}; | ||
|
||
const loadCommandMonitors = (client, baseDir, counts) => { | ||
return new Promise((resolve, reject) => { | ||
const dir = path.resolve(`${baseDir}./monitors/`); | ||
fs.ensureDir(dir, (err) => { | ||
if (err) console.error(err); | ||
fs.readdir(dir, (err, files) => { | ||
if (err) console.error(err); | ||
let [p, o] = counts; | ||
try { | ||
files = files.filter((f) => { return f.slice(-3) === ".js"; }); | ||
files.forEach((f) => { | ||
const file = f.split("."); | ||
let props; | ||
if (file[1] !== "opt") { | ||
props = require(`${dir}/${f}`); | ||
client.commandMonitors.set(file[0], props); | ||
p++; | ||
} else if (client.config.commandMonitors.includes(file[0])) { | ||
props = require(`${dir}/${f}`); | ||
client.commandMonitors.set(file[0], props); | ||
o++; | ||
} | ||
}); | ||
} catch (e) { | ||
if (e.code === "MODULE_NOT_FOUND") { | ||
const module = /'[^']+'/g.exec(e.toString()); | ||
client.funcs.installNPM(module[0].slice(1, -1)) | ||
.then(() => { | ||
client.funcs.loadCommandMonitors(client); | ||
}) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(); | ||
}); | ||
} else { | ||
console.error(e); | ||
} | ||
reject(); | ||
} | ||
resolve([p, o]); | ||
}); | ||
}); | ||
}); | ||
}; |
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,16 @@ | ||
module.exports = (client, msg) => { | ||
return new Promise((resolve, reject) => { | ||
const mps = [true]; | ||
client.commandMonitors.forEach((mProc) => { | ||
if (mProc.conf.enabled) { | ||
mps.push(mProc.run(client, msg)); | ||
} | ||
}); | ||
Promise.all(mps) | ||
.then((value) => { | ||
resolve(value); | ||
}, (reason) => { | ||
reject(reason); | ||
}); | ||
}); | ||
}; |
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,19 @@ | ||
const profanityFinder = require("profanity-finder"); | ||
|
||
const findProfanity = profanityFinder.findprofanity; | ||
|
||
exports.conf = { | ||
enabled: false, | ||
}; | ||
|
||
exports.run = (client, msg) => { | ||
return new Promise((resolve, reject) => { | ||
const bool = findProfanity(msg.content); | ||
if (bool) { | ||
msg.delete(); | ||
reject("You're not allowed to use profanity in your messages!"); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}; |
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