Skip to content

Commit c6c919b

Browse files
committed
Add enabling, disabling and logging options
1 parent 2bde1fa commit c6c919b

File tree

7 files changed

+152
-12
lines changed

7 files changed

+152
-12
lines changed

.gitignore

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
.env*.local
75+
76+
# parcel-bundler cache (https://parceljs.org/)
77+
.cache
78+
.parcel-cache
79+
80+
# Next.js build output
81+
.next
82+
83+
# Nuxt.js build / generate output
84+
.nuxt
85+
dist
86+
87+
# Gatsby files
88+
.cache/
89+
# Comment in the public line in if your project uses Gatsby and not Next.js
90+
# https://nextjs.org/blog/next-9-1#public-directory-support
91+
# public
92+
93+
# vuepress build output
94+
.vuepress/dist
95+
96+
# Serverless directories
97+
.serverless/
98+
99+
# FuseBox cache
100+
.fusebox/
101+
102+
# DynamoDB Local files
103+
.dynamodb/
104+
105+
# TernJS port file
106+
.tern-port
107+
108+
# Stores VSCode versions used for testing VSCode extensions
109+
.vscode-test
110+
111+
# VSCode settings
112+
.vscode/
113+
114+
# Performance profiles
115+
.vscode-profiles/
116+
117+
#ESlint
118+
.eslintrc.js
119+
120+
# git rm -r --cached .
121+
# End of https://www.toptal.com/developers/gitignore/api/node

additions/Message/guild.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const { addPrototype } = require("../../helper/prototype");
22

33
/**
4-
* @param {import("eris")} Eris
4+
* @param {import("eris")} Eris
55
*/
66
module.exports.init = (Eris) => {
77
addPrototype(Eris, "Message", function guild() {
88
return this.channel.guild || this._client.get(this.guildID);
99
}, true);
10-
}
10+
};

additions/User/tag.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { addPrototype } = require("erisify/helper/prototype");
2+
3+
/**
4+
* @param {import("eris")} Eris
5+
*/
6+
module.exports.init = (Eris) => {
7+
addPrototype(Eris, "User", function guild() {
8+
return `${this.username}#${this.discriminator}`;
9+
}, true);
10+
};

helper/prototype.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module.exports = {
22
/**
3-
* @param {import("eris")} Eris
4-
* @param {String} Class
5-
* @param {Function} func
6-
* @param {Boolean} isGetter
3+
* @param {import("eris")} Eris
4+
* @param {String} Class
5+
* @param {Function} func
6+
* @param {Boolean} isGetter
77
*/
88
addPrototype: function (Eris, Class, func, isGetter = false) {
99
if (Eris[Class].prototype[func.name] !== undefined) return console.warn(`${func.name} already exists in ${Class}, you can't overwrite it`);
1010

11-
Object.defineProperty(Eris[Class].prototype, fn.name, isGetter ? { get: func } : { value: fn });
11+
Object.defineProperty(Eris[Class].prototype, func.name, isGetter ? { get: func } : { value: func });
1212
},
1313
};

index.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const additionsPath = path.join(__dirname, ".", "additions");
44

55
/**
66
* @param {import("eris")} Eris
7-
* @param {Array} [enabled="all"]
8-
* @param {Array} [disabled="none"]
7+
* @param {Object} options
8+
* @param {Array} [options.enabled="all"] An array of enabled additions, enabling prioritizes over disabling (ex. "Message.guild")
9+
* @param {Array} [options.disabled="none"] An array of disabled additions (ex. "Message.guild")
10+
* @param {Boolean} [options.logging=false] Enabled logging of adding additions
911
*/
1012
module.exports = async (Eris, options = {}) => {
1113
const additionsFolders = fs.readdirSync(additionsPath);
@@ -15,10 +17,15 @@ module.exports = async (Eris, options = {}) => {
1517

1618
const additions = fs.readdirSync(filePath).filter(file => file.endsWith(".js"));
1719
for (const addition of additions) {
18-
const plugin = require(addition);
20+
if (!options.enabled?.includes(addition) && options.disabled?.includes(addition)) {
21+
if (options.logging) console.log(`${filePath}.${addition} has been disabled`);
22+
continue;
23+
}
24+
25+
const plugin = require(`${filePath}/${addition}`);
1926

2027
plugin.init(Eris);
21-
console.log(`init on ${addition}`)
28+
if (options.logging) console.log(`${filePath}.${addition} has been initialized`);
2229
}
2330
}
2431
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "erisify",
3-
"version": "1.0.0",
3+
"version": "0.1.0",
44
"description": "A few small additions to Eris to make life easier",
55
"main": "index.js",
66
"scripts": {

readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# erisify
2+
dank package which i made just because i am lazy

0 commit comments

Comments
 (0)