diff --git a/package-lock.json b/package-lock.json index a21e836..6d159d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,7 @@ "eslint": "8.9.0", "eslint-config-prettier": "8.3.0", "eslint-plugin-prettier": "4.0.0", + "gen-esm-wrapper": "^1.1.3", "prettier": "2.5.1" } }, @@ -2197,6 +2198,16 @@ "node": ">=8" } }, + "node_modules/assert": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-1.5.0.tgz", + "integrity": "sha512-EDsgawzwoun2CZkCgtxJbv392v4nbk9XDD06zI+kQYoBM/3RBWLlEyJARDOmhAAosBjWACEkKL6S+lIZtcAubA==", + "dev": true, + "dependencies": { + "object-assign": "^4.1.1", + "util": "0.10.3" + } + }, "node_modules/babel-plugin-dynamic-import-node": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", @@ -2935,6 +2946,18 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "node_modules/gen-esm-wrapper": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/gen-esm-wrapper/-/gen-esm-wrapper-1.1.3.tgz", + "integrity": "sha512-LNHZ+QpaCW/0VhABIbXn45V+P8kFvjjwuue9hbV23eOjuFVz6c0FE3z1XpLX9pSjLW7UmtCkXo5F9vhZWVs8oQ==", + "dev": true, + "dependencies": { + "is-valid-identifier": "^2.0.2" + }, + "bin": { + "gen-esm-wrapper": "gen-esm-wrapper.js" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -3163,6 +3186,15 @@ "node": ">=0.12.0" } }, + "node_modules/is-valid-identifier": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/is-valid-identifier/-/is-valid-identifier-2.0.2.tgz", + "integrity": "sha512-mpS5EGqXOwzXtKAg6I44jIAqeBfntFLxpAth1rrKbxtKyI6LPktyDYpHBI+tHlduhhX/SF26mFXmxQu995QVqg==", + "dev": true, + "dependencies": { + "assert": "^1.4.1" + } + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -3353,6 +3385,15 @@ "node": ">=0.10.0" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", @@ -3945,6 +3986,21 @@ "punycode": "^2.1.0" } }, + "node_modules/util": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", + "dev": true, + "dependencies": { + "inherits": "2.0.1" + } + }, + "node_modules/util/node_modules/inherits": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", + "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=", + "dev": true + }, "node_modules/v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", @@ -5502,6 +5558,16 @@ "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true }, + "assert": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-1.5.0.tgz", + "integrity": "sha512-EDsgawzwoun2CZkCgtxJbv392v4nbk9XDD06zI+kQYoBM/3RBWLlEyJARDOmhAAosBjWACEkKL6S+lIZtcAubA==", + "dev": true, + "requires": { + "object-assign": "^4.1.1", + "util": "0.10.3" + } + }, "babel-plugin-dynamic-import-node": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz", @@ -6069,6 +6135,15 @@ "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "dev": true }, + "gen-esm-wrapper": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/gen-esm-wrapper/-/gen-esm-wrapper-1.1.3.tgz", + "integrity": "sha512-LNHZ+QpaCW/0VhABIbXn45V+P8kFvjjwuue9hbV23eOjuFVz6c0FE3z1XpLX9pSjLW7UmtCkXo5F9vhZWVs8oQ==", + "dev": true, + "requires": { + "is-valid-identifier": "^2.0.2" + } + }, "gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -6231,6 +6306,15 @@ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true }, + "is-valid-identifier": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/is-valid-identifier/-/is-valid-identifier-2.0.2.tgz", + "integrity": "sha512-mpS5EGqXOwzXtKAg6I44jIAqeBfntFLxpAth1rrKbxtKyI6LPktyDYpHBI+tHlduhhX/SF26mFXmxQu995QVqg==", + "dev": true, + "requires": { + "assert": "^1.4.1" + } + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -6384,6 +6468,12 @@ "dev": true, "optional": true }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, "object-keys": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", @@ -6793,6 +6883,23 @@ "punycode": "^2.1.0" } }, + "util": { + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", + "dev": true, + "requires": { + "inherits": "2.0.1" + }, + "dependencies": { + "inherits": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz", + "integrity": "sha1-sX0I0ya0Qj5Wjv9xn5GwscvfafE=", + "dev": true + } + } + }, "v8-compile-cache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", diff --git a/package.json b/package.json index ed66f00..fc81502 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "eslint": "8.9.0", "eslint-config-prettier": "8.3.0", "eslint-plugin-prettier": "4.0.0", + "gen-esm-wrapper": "^1.1.3", "prettier": "2.5.1" } } diff --git a/packages/plugin-blacklist/package.json b/packages/plugin-blacklist/package.json index 9be1b07..f23b70f 100644 --- a/packages/plugin-blacklist/package.json +++ b/packages/plugin-blacklist/package.json @@ -4,10 +4,17 @@ "description": "Easy to use blacklist system", "main": "dist/index.js", "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "bash ../../scripts/build.bash", "build:babel": "npx babel --extensions .ts ./src -d ./dist --minified --copy-files --config-file ../../babel.config.js", + "build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs", "build:types": "tsc --emitDeclarationOnly", "lint": "npx eslint . --fix -c ../../.eslintrc.json" }, diff --git a/packages/plugin-cooldowns/package.json b/packages/plugin-cooldowns/package.json index 838458a..f01fe4d 100644 --- a/packages/plugin-cooldowns/package.json +++ b/packages/plugin-cooldowns/package.json @@ -1,6 +1,6 @@ { "name": "@gcommands/plugin-cooldowns", - "version": "1.0.3", + "version": "1.0.4", "description": "Set cooldown for your command", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -8,9 +8,16 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "bash ../../scripts/build.bash", "build:babel": "npx babel --extensions .ts ./src -d ./dist --minified --copy-files --config-file ../../babel.config.js", + "build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs", "build:types": "tsc --emitDeclarationOnly", "lint": "npx eslint . --fix -c ../../.eslintrc.json" }, + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, "keywords": [ "gcommands", "plugin", diff --git a/packages/plugin-cooldowns/src/utils/CooldownManager.ts b/packages/plugin-cooldowns/src/utils/CooldownManager.ts index 72f574d..239d3e5 100644 --- a/packages/plugin-cooldowns/src/utils/CooldownManager.ts +++ b/packages/plugin-cooldowns/src/utils/CooldownManager.ts @@ -29,12 +29,12 @@ export class CooldownManager { if (this.cache.get(userId)) return this.cache.get(userId); let result = 0; - if (db.type === 'mongodb') { - result = (await db.get('plugin-cooldowns', { userId }))?.cooldown; - } else if (db.type === 'prismaio') { - result = (await db.get('plugin-cooldowns', { userId }))?.cooldown; + if (db?.type === 'mongodb') { + result = (await db?.get('plugin-cooldowns', { userId }))?.cooldown; + } else if (db?.type === 'prismaio') { + result = (await db?.get('plugin-cooldowns', { userId }))?.cooldown; } else { - result = (await db.get(`plugin-cooldowns-${userId}}`)); + result = (await db?.get(`plugin-cooldowns-${userId}}`)); } this.cache.set(userId, result); @@ -47,12 +47,12 @@ export class CooldownManager { this.cache.set(userId, cldwn); - if (db.type === 'mongodb') { - return await db.insert('plugin-cooldowns', { userId, cooldown: cldwn, expires: new Date(cldwn) }); - } else if (db.type === 'prismaio') { - return await db.insert('plugin-cooldowns', { userId, cooldown: cldwn }); + if (db?.type === 'mongodb') { + return await db?.insert('plugin-cooldowns', { userId, cooldown: cldwn, expires: new Date(cldwn) }); + } else if (db?.type === 'prismaio') { + return await db?.insert('plugin-cooldowns', { userId, cooldown: cldwn }); } else { - return await db.insert(`plugin-cooldowns-${userId}}`, cldwn); + return await db?.insert(`plugin-cooldowns-${userId}}`, cldwn); } } } diff --git a/packages/plugin-language/package.json b/packages/plugin-language/package.json index 02f2ebd..d812646 100644 --- a/packages/plugin-language/package.json +++ b/packages/plugin-language/package.json @@ -1,6 +1,6 @@ { "name": "@gcommands/plugin-language", - "version": "1.0.3", + "version": "1.0.4", "description": "Extend default discord.js events for GCommands", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -8,9 +8,16 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "bash ../../scripts/build.bash", "build:babel": "npx babel --extensions .ts ./src -d ./dist --minified --copy-files --config-file ../../babel.config.js", + "build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs", "build:types": "tsc --emitDeclarationOnly", "lint": "npx eslint . --fix -c ../../.eslintrc.json" }, + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, "keywords": [ "gcommands", "plugin", diff --git a/packages/plugin-moreevents/package.json b/packages/plugin-moreevents/package.json index a2a0af2..32967d9 100644 --- a/packages/plugin-moreevents/package.json +++ b/packages/plugin-moreevents/package.json @@ -1,6 +1,6 @@ { "name": "@gcommands/plugin-moreevents", - "version": "1.0.2", + "version": "1.0.3", "description": "Extend default discord.js events for GCommands", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -8,9 +8,16 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "bash ../../scripts/build.bash", "build:babel": "npx babel --extensions .ts ./src -d ./dist --minified --copy-files --config-file ../../babel.config.js", + "build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs", "build:types": "tsc --emitDeclarationOnly", "lint": "npx eslint . --fix -c ../../.eslintrc.json" }, + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, "keywords": [ "gcommands", "plugin", diff --git a/packages/plugin-premium/package.json b/packages/plugin-premium/package.json index 5f01f83..d137802 100644 --- a/packages/plugin-premium/package.json +++ b/packages/plugin-premium/package.json @@ -8,9 +8,16 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "bash ../../scripts/build.bash", "build:babel": "npx babel --extensions .ts ./src -d ./dist --minified --copy-files --config-file ../../babel.config.js", + "build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs", "build:types": "tsc --emitDeclarationOnly", "lint": "npx eslint . --fix -c ../../.eslintrc.json" }, + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, "keywords": [ "gcommands", "plugin", diff --git a/packages/plugin-votes/package.json b/packages/plugin-votes/package.json index 57662b3..84d9311 100644 --- a/packages/plugin-votes/package.json +++ b/packages/plugin-votes/package.json @@ -1,6 +1,6 @@ { "name": "@gcommands/plugin-votes", - "version": "1.0.2", + "version": "1.0.3", "description": "Check if user has vote", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -8,9 +8,16 @@ "test": "echo \"Error: no test specified\" && exit 1", "build": "bash ../../scripts/build.bash", "build:babel": "npx babel --extensions .ts ./src -d ./dist --copy-files --config-file ../../babel.config.js", + "build:esm": "gen-esm-wrapper dist/index.js dist/index.mjs", "build:types": "tsc --emitDeclarationOnly", "lint": "npx eslint . --fix -c ../../.eslintrc.json" }, + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.js" + } + }, "keywords": [ "gcommands", "plugin", diff --git a/packages/plugin-votes/src/utils/isVoted.ts b/packages/plugin-votes/src/utils/isVoted.ts index 026ac3f..86fd43c 100644 --- a/packages/plugin-votes/src/utils/isVoted.ts +++ b/packages/plugin-votes/src/utils/isVoted.ts @@ -27,11 +27,11 @@ export class isVoted { }).catch(e => e); if (parseInt(res.data['voted']) > 1) { - this.cache.set(userId, true); + this.cache?.set(userId, true); return true; } else { - this.cache.set(userId, false); + this.cache?.set(userId, false); return false; } @@ -39,22 +39,22 @@ export class isVoted { } async getFromCache(userId): Promise { - if (this.cache.type === 'mongodb') { - return (await this.cache.get('plugin-votes', { userId })).voted; - } else if (this.cache.type === 'prismaio') { - return (await this.cache.get('plugin-votes', { userId })).voted; + if (this.cache?.type === 'mongodb') { + return (await this.cache?.get('plugin-votes', { userId })).voted; + } else if (this.cache?.type === 'prismaio') { + return (await this.cache?.get('plugin-votes', { userId })).voted; } else { - return (await this.cache.get(`plugin-votes-${userId}`)); + return (await this.cache?.get(`plugin-votes-${userId}`)); } } async setToDatabase(userId, voted) { - if (this.cache.type === 'mongodb') { - return await this.cache.insert('plugin-votes', { userId, voted, expires: new Date(Date.now() + 43200000) }); - } else if (this.cache.type === 'prismaio') { - return await this.cache.insert('plugin-votes', { userId, voted }); + if (this.cache?.type === 'mongodb') { + return await this.cache?.insert('plugin-votes', { userId, voted, expires: new Date(Date.now() + 43200000) }); + } else if (this.cache?.type === 'prismaio') { + return await this.cache?.insert('plugin-votes', { userId, voted }); } else { - return await this.cache.insert(`plugin-votes-${userId}`, voted); + return await this.cache?.insert(`plugin-votes-${userId}`, voted); } } } \ No newline at end of file diff --git a/scripts/build.bash b/scripts/build.bash index 428852d..5d88cd6 100644 --- a/scripts/build.bash +++ b/scripts/build.bash @@ -1,2 +1,3 @@ npm run build:babel -npm run build:types \ No newline at end of file +npm run build:types +npm run build:esm \ No newline at end of file