From a45069472c7cb09a91dd731d4d585c4d5b8aa414 Mon Sep 17 00:00:00 2001 From: Artrix <39530102+Artrix9095@users.noreply.github.com> Date: Fri, 3 Sep 2021 18:56:26 -0700 Subject: [PATCH] fix alot of bugs and add erlpack back --- .gitignore | 2 +- dist/lib/Client.js | 1 - dist/lib/discord/Message.d.ts | 2 +- dist/lib/discord/Message.js | 7 +- examples/index.js | 23 +++-- examples/package-lock.json | 179 +++++++++++++++++++++++++++++++++- package-lock.json | 107 +++++++++++++++++--- package.json | 8 +- src/lib/Client.ts | 1 - src/lib/_http.ts | 2 +- src/lib/discord/Message.ts | 7 +- 11 files changed, 301 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index ab5c7ec0..64b2a5ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Secrets and logs *.secret -*.log +# *.log # Cache .eslintcache diff --git a/dist/lib/Client.js b/dist/lib/Client.js index 11221888..1ec16e78 100644 --- a/dist/lib/Client.js +++ b/dist/lib/Client.js @@ -251,7 +251,6 @@ class Client extends Emitter_1.default { ready(); }); this.event('MESSAGE_REACTION_ADD', (json) => { - console.log('json'); if (this.events.has('reaction')) { this.events.get('reaction')(new Reaction_1.default(json, this.token, this.bot)); } diff --git a/dist/lib/discord/Message.d.ts b/dist/lib/discord/Message.d.ts index acfb93a4..91087a81 100644 --- a/dist/lib/discord/Message.d.ts +++ b/dist/lib/discord/Message.d.ts @@ -9,7 +9,7 @@ import { Message as IMessage } from '../_DiscordAPI'; declare class Message { protected token: string; protected bot: User; - author_id: string; + author: User; guild_id: string; channel_id: string; embeds: Embed[]; diff --git a/dist/lib/discord/Message.js b/dist/lib/discord/Message.js index 23b498d3..1345b426 100644 --- a/dist/lib/discord/Message.js +++ b/dist/lib/discord/Message.js @@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const Embed_1 = __importDefault(require("./Embed")); +const User_1 = __importDefault(require("./User")); const _Debug_1 = __importDefault(require("../_Debug")); const _http_1 = __importDefault(require("../_http")); // class Message implements IMessage { @@ -26,7 +27,7 @@ class Message { var _a; this.token = token; this.bot = bot; - Object.assign(this, Object.assign(Object.assign({}, data), { timestamp: new Date(data === null || data === void 0 ? void 0 : data.timestamp), embeds: (_a = data === null || data === void 0 ? void 0 : data.embeds) === null || _a === void 0 ? void 0 : _a.map((v) => new Embed_1.default(v)) })); + Object.assign(this, Object.assign(Object.assign({}, data), { author: new User_1.default(data.author, this.token), timestamp: new Date(data === null || data === void 0 ? void 0 : data.timestamp), embeds: (_a = data === null || data === void 0 ? void 0 : data.embeds) === null || _a === void 0 ? void 0 : _a.map((v) => new Embed_1.default(v)) })); if (data.message_reference) { _http_1.default.GET(`/channels/${data.message_reference.channel_id}/messages/${data.message_reference.message_id}`).then((msg) => (this.message_reference = new Message(msg, token, bot))); } @@ -34,8 +35,10 @@ class Message { edit(content) { return __awaiter(this, void 0, void 0, function* () { const data = {}; - if (this.author_id.toString() !== this.bot.id.toString()) + if (this.author.id.toString() !== this.bot.id.toString()) { new _Debug_1.default(true).error('message edit', "Cannot edit a message you didn't send"); + return; + } if (typeof content === 'string') { // Just a normal message data.content = content; diff --git a/examples/index.js b/examples/index.js index 897ade71..6d44944c 100644 --- a/examples/index.js +++ b/examples/index.js @@ -41,18 +41,17 @@ client.use(function reactMiddleware(req, res, next) { // A basic 'ping' command. Responds with 'pong' along with the latency (in // milliseconds) within an embed. client.command(['ping', 'latency'], function ping(req, res) { - const timestamp = Date.parse(new Date(req.message.timestamp)); - res.send( - new Embed() - .setTitle('Pong') - .setAuthor(req.author.username, { icon: req.author.avatar }) - .addField({ - name: 'Latency', - value: `${Date.now() - timestamp}ms`, - }) - .setDescription() - .setColor(Colors.rgb(13, 186, 120)) - ); + res.send('Loading...').then(msg => { + msg.edit(new Embed() + .setTitle('Pong') + .setAuthor(req.author.username, { icon: req.author.avatar }) + .addField({ + name: 'Latency', + value: `${Date.now() - msg.timestamp}ms`, + }) + .setDescription() + .setColor(Colors.rgb(13, 186, 120))) + }) }); // More complex example command using the GitHub API client.command(['github', 'gh'], async function github(req, res) { diff --git a/examples/package-lock.json b/examples/package-lock.json index cd9cef05..3a1bf9e2 100644 --- a/examples/package-lock.json +++ b/examples/package-lock.json @@ -1,8 +1,185 @@ { "name": "examples", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "node-fetch": "^2.6.1", + "ts-node": "^9.1.1" + }, + "devDependencies": { + "@types/node-fetch": "^2.5.7" + } + }, + "node_modules/@types/node": { + "version": "14.14.20", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.20.tgz", + "integrity": "sha512-Y93R97Ouif9JEOWPIUyU+eyIdyRqQR0I8Ez1dzku4hDx34NWh4HbtIc3WNzwB1Y9ULvNGeu5B8h8bVL5cAk4/A==", + "dev": true + }, + "node_modules/@types/node-fetch": { + "version": "2.5.7", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz", + "integrity": "sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==", + "dev": true, + "dependencies": { + "@types/node": "*", + "form-data": "^3.0.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true + }, + "node_modules/buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==" + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/form-data": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", + "integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, + "node_modules/mime-db": { + "version": "1.45.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", + "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.28", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", + "integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", + "dev": true, + "dependencies": { + "mime-db": "1.45.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "node_modules/ts-node": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-9.1.1.tgz", + "integrity": "sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==", + "dependencies": { + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "typescript": ">=2.7" + } + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "engines": { + "node": ">=6" + } + } + }, "dependencies": { "@types/node": { "version": "14.14.20", diff --git a/package-lock.json b/package-lock.json index 9387fa16..e43b1f26 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.0", "license": "MIT", "dependencies": { - "undici": "^3.0.0", + "undici": "^4.5.1", "ws": "^7.4.6" }, "devDependencies": { @@ -23,8 +23,9 @@ "typedoc": "^0.20.13", "typescript": "^4.1.3" }, - "peerDependencies": { - "chalk": "^2.4.2" + "optionalDependencies": { + "chalk": "^2.4.2", + "erlpack": "*" } }, "node_modules/@babel/code-frame": { @@ -422,6 +423,7 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "devOptional": true, "dependencies": { "color-convert": "^1.9.0" }, @@ -472,6 +474,15 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "optional": true, + "dependencies": { + "file-uri-to-path": "1.0.0" + } + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -507,6 +518,7 @@ "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "devOptional": true, "dependencies": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -563,6 +575,7 @@ "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "devOptional": true, "dependencies": { "color-name": "1.1.3" } @@ -570,7 +583,8 @@ "node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "devOptional": true }, "node_modules/colorette": { "version": "1.3.0", @@ -720,6 +734,17 @@ "node": ">=8.6" } }, + "node_modules/erlpack": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/erlpack/-/erlpack-0.1.3.tgz", + "integrity": "sha512-QeG9v8CVsY/a/IoQi8zjn23aYKcziOihAxwjUl3tI/KB4R1FjTtctDAAMovgtpC16S+WiOauers2oWwIOQtKBQ==", + "hasInstallScript": true, + "optional": true, + "dependencies": { + "bindings": "^1.5.0", + "nan": "^2.14.0" + } + }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -733,6 +758,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "devOptional": true, "engines": { "node": ">=0.8.0" } @@ -1134,6 +1160,12 @@ "node": "^10.12.0 || >=12.0.0" } }, + "node_modules/file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "optional": true + }, "node_modules/fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -1372,6 +1404,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "devOptional": true, "engines": { "node": ">=4" } @@ -2168,6 +2201,12 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "node_modules/nan": { + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", + "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==", + "optional": true + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -2863,6 +2902,7 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "devOptional": true, "dependencies": { "has-flag": "^3.0.0" }, @@ -3102,9 +3142,12 @@ } }, "node_modules/undici": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/undici/-/undici-3.3.6.tgz", - "integrity": "sha512-/j3YTZ5AobMB4ZrTY72mzM54uFUX32v0R/JRW9G2vOyF1uSKYAx+WT8dMsAcRS13TOFISv094TxIyWYk+WEPsA==" + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-4.5.1.tgz", + "integrity": "sha512-1Kmphp4SMwVbSauz9xH4gxt0m3sLGs5qRHs/XYgjeO3bNSt6hspDZqMhM8+ETu9ynB5bq9e6mnwcDz+NVCQ3UQ==", + "engines": { + "node": ">=12.18" + } }, "node_modules/universalify": { "version": "2.0.0", @@ -3549,6 +3592,7 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "devOptional": true, "requires": { "color-convert": "^1.9.0" } @@ -3587,6 +3631,15 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "optional": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -3616,6 +3669,7 @@ "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "devOptional": true, "requires": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -3657,6 +3711,7 @@ "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "devOptional": true, "requires": { "color-name": "1.1.3" } @@ -3664,7 +3719,8 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "devOptional": true }, "colorette": { "version": "1.3.0", @@ -3785,6 +3841,16 @@ "ansi-colors": "^4.1.1" } }, + "erlpack": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/erlpack/-/erlpack-0.1.3.tgz", + "integrity": "sha512-QeG9v8CVsY/a/IoQi8zjn23aYKcziOihAxwjUl3tI/KB4R1FjTtctDAAMovgtpC16S+WiOauers2oWwIOQtKBQ==", + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.14.0" + } + }, "error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -3797,7 +3863,8 @@ "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "devOptional": true }, "eslint": { "version": "7.32.0", @@ -4103,6 +4170,12 @@ "flat-cache": "^3.0.4" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "optional": true + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -4280,7 +4353,8 @@ "has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "devOptional": true }, "human-signals": { "version": "1.1.1", @@ -4870,6 +4944,12 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "nan": { + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.15.0.tgz", + "integrity": "sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==", + "optional": true + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -5363,6 +5443,7 @@ "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "devOptional": true, "requires": { "has-flag": "^3.0.0" } @@ -5536,9 +5617,9 @@ "optional": true }, "undici": { - "version": "3.3.6", - "resolved": "https://registry.npmjs.org/undici/-/undici-3.3.6.tgz", - "integrity": "sha512-/j3YTZ5AobMB4ZrTY72mzM54uFUX32v0R/JRW9G2vOyF1uSKYAx+WT8dMsAcRS13TOFISv094TxIyWYk+WEPsA==" + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/undici/-/undici-4.5.1.tgz", + "integrity": "sha512-1Kmphp4SMwVbSauz9xH4gxt0m3sLGs5qRHs/XYgjeO3bNSt6hspDZqMhM8+ETu9ynB5bq9e6mnwcDz+NVCQ3UQ==" }, "universalify": { "version": "2.0.0", diff --git a/package.json b/package.json index d4d7e1a2..9f55c7d0 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "docs": "npx typedoc --options ./docs.js", "test": "npm run build && node examples/index", "browser": "tsc -p . && node browser", + "profile": "npm run build && node --prof examples/index", "build": "npx tsc -p ." }, "repository": { @@ -31,7 +32,7 @@ }, "homepage": "https://github.com/Fuwajs/Fuwa.js#readme", "dependencies": { - "undici": "^3.0.0", + "undici": "^4.5.1", "ws": "^7.4.6" }, "devDependencies": { @@ -45,8 +46,9 @@ "typedoc": "^0.20.13", "typescript": "^4.1.3" }, - "peerDependencies": { - "chalk": "^2.4.2" + "optionalDependencies": { + "chalk": "^2.4.2", + "erlpack": "*" }, "husky": { "hooks": { diff --git a/src/lib/Client.ts b/src/lib/Client.ts index e4c46eb4..a4a2c37e 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -388,7 +388,6 @@ class Client extends Emitter { if (ready) ready(); }); this.event('MESSAGE_REACTION_ADD', (json) => { - console.log('json'); if (this.events.has('reaction')) { this.events.get('reaction')( new Reaction(json, this.token, this.bot), diff --git a/src/lib/_http.ts b/src/lib/_http.ts index 43ff7ec6..ca9bdf88 100644 --- a/src/lib/_http.ts +++ b/src/lib/_http.ts @@ -33,7 +33,7 @@ export default { version?: 6 | 8 ): Promise { return new Promise(async (resolve, reject) => { - const params: Client.RequestOptions = { + const params: any = { path: '/api/v8' + path, method, headers: { diff --git a/src/lib/discord/Message.ts b/src/lib/discord/Message.ts index d0f74299..5a959b34 100644 --- a/src/lib/discord/Message.ts +++ b/src/lib/discord/Message.ts @@ -11,7 +11,7 @@ import { Message as IMessage } from '../_DiscordAPI'; import http from '../_http'; // class Message implements IMessage { class Message { - author_id: string; + author: User; guild_id: string; channel_id: string; embeds: Embed[]; @@ -22,6 +22,7 @@ class Message { constructor(data: IMessage, protected token: string, protected bot: User) { Object.assign(this, { ...data, + author: new User(data.author, this.token), timestamp: new Date(data?.timestamp), embeds: data?.embeds?.map((v) => new Embed(v)), }); @@ -36,11 +37,13 @@ class Message { async edit(content: string | Embed): Promise { const data: any = {}; - if (this.author_id.toString() !== this.bot.id.toString()) + if (this.author.id.toString() !== this.bot.id.toString()) { new Debug(true).error( 'message edit', "Cannot edit a message you didn't send" ); + return + } if (typeof content === 'string') { // Just a normal message data.content = content;