From cf3bdcc29052fa1f85f2a9d3727928ccad300172 Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:18:28 +1100 Subject: [PATCH] Refactor calculator.ts --- .pnp.cjs | 225 +++++++++++++++++++++++++++---------- package.json | 7 +- src/commands/calculator.ts | 17 ++- yarn.lock | 194 +++++++++++++++++++++++--------- 4 files changed, 327 insertions(+), 116 deletions(-) diff --git a/.pnp.cjs b/.pnp.cjs index 613317b..aac9007 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -26,18 +26,19 @@ const RAW_RUNTIME_STATE = [null, {\ "packageLocation": "./",\ "packageDependencies": [\ - ["@napi-rs/canvas", "npm:0.1.49"],\ + ["@napi-rs/canvas", "npm:0.1.50"],\ ["@octokit/rest", "npm:20.0.2"],\ ["@toast/tokenservice-client", "npm:1.0.12::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.12%2Ftokenservice-client-1.0.12.tgz"],\ ["@types/ms", "npm:0.7.34"],\ - ["@types/node", "npm:20.11.20"],\ + ["@types/node", "npm:20.11.21"],\ ["@types/node-cron", "npm:3.0.11"],\ - ["@types/pg", "npm:8.11.1"],\ + ["@types/pg", "npm:8.11.2"],\ ["@types/sequelize", "npm:4.28.20"],\ ["ansi-colors", "npm:4.1.3"],\ ["dayjs", "npm:1.11.10"],\ ["discord.js", "npm:14.14.1"],\ ["fast-xml-parser", "npm:4.3.5"],\ + ["mathjs", "npm:12.4.0"],\ ["ms", "npm:2.1.3"],\ ["node-cron", "npm:3.0.3"],\ ["pg", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:8.11.3"],\ @@ -52,6 +53,16 @@ const RAW_RUNTIME_STATE = "linkType": "SOFT"\ }]\ ]],\ + ["@babel/runtime", [\ + ["npm:7.23.9", {\ + "packageLocation": "./.yarn/cache/@babel-runtime-npm-7.23.9-3b96e23cc2-9a520fe1bf.zip/node_modules/@babel/runtime/",\ + "packageDependencies": [\ + ["@babel/runtime", "npm:7.23.9"],\ + ["regenerator-runtime", "npm:0.14.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["@discordjs/builders", [\ ["npm:1.7.0", {\ "packageLocation": "./.yarn/cache/@discordjs-builders-npm-1.7.0-8875363a52-1152d8989e.zip/node_modules/@discordjs/builders/",\ @@ -168,100 +179,100 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["@napi-rs/canvas", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/cache/@napi-rs-canvas-npm-0.1.49-5033cd9984-78a7e229a0.zip/node_modules/@napi-rs/canvas/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/cache/@napi-rs-canvas-npm-0.1.50-6d57a400a9-c9ed3ecdaa.zip/node_modules/@napi-rs/canvas/",\ "packageDependencies": [\ - ["@napi-rs/canvas", "npm:0.1.49"],\ - ["@napi-rs/canvas-android-arm64", "npm:0.1.49"],\ - ["@napi-rs/canvas-darwin-arm64", "npm:0.1.49"],\ - ["@napi-rs/canvas-darwin-x64", "npm:0.1.49"],\ - ["@napi-rs/canvas-linux-arm-gnueabihf", "npm:0.1.49"],\ - ["@napi-rs/canvas-linux-arm64-gnu", "npm:0.1.49"],\ - ["@napi-rs/canvas-linux-arm64-musl", "npm:0.1.49"],\ - ["@napi-rs/canvas-linux-x64-gnu", "npm:0.1.49"],\ - ["@napi-rs/canvas-linux-x64-musl", "npm:0.1.49"],\ - ["@napi-rs/canvas-win32-x64-msvc", "npm:0.1.49"]\ + ["@napi-rs/canvas", "npm:0.1.50"],\ + ["@napi-rs/canvas-android-arm64", "npm:0.1.50"],\ + ["@napi-rs/canvas-darwin-arm64", "npm:0.1.50"],\ + ["@napi-rs/canvas-darwin-x64", "npm:0.1.50"],\ + ["@napi-rs/canvas-linux-arm-gnueabihf", "npm:0.1.50"],\ + ["@napi-rs/canvas-linux-arm64-gnu", "npm:0.1.50"],\ + ["@napi-rs/canvas-linux-arm64-musl", "npm:0.1.50"],\ + ["@napi-rs/canvas-linux-x64-gnu", "npm:0.1.50"],\ + ["@napi-rs/canvas-linux-x64-musl", "npm:0.1.50"],\ + ["@napi-rs/canvas-win32-x64-msvc", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-android-arm64", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-android-arm64-npm-0.1.49-f6ac0932e5/node_modules/@napi-rs/canvas-android-arm64/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-android-arm64-npm-0.1.50-11d6135d75/node_modules/@napi-rs/canvas-android-arm64/",\ "packageDependencies": [\ - ["@napi-rs/canvas-android-arm64", "npm:0.1.49"]\ + ["@napi-rs/canvas-android-arm64", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-darwin-arm64", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-darwin-arm64-npm-0.1.49-870a2d8366/node_modules/@napi-rs/canvas-darwin-arm64/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-darwin-arm64-npm-0.1.50-6b2d108329/node_modules/@napi-rs/canvas-darwin-arm64/",\ "packageDependencies": [\ - ["@napi-rs/canvas-darwin-arm64", "npm:0.1.49"]\ + ["@napi-rs/canvas-darwin-arm64", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-darwin-x64", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-darwin-x64-npm-0.1.49-8cca987002/node_modules/@napi-rs/canvas-darwin-x64/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-darwin-x64-npm-0.1.50-b670722e63/node_modules/@napi-rs/canvas-darwin-x64/",\ "packageDependencies": [\ - ["@napi-rs/canvas-darwin-x64", "npm:0.1.49"]\ + ["@napi-rs/canvas-darwin-x64", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-linux-arm-gnueabihf", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-arm-gnueabihf-npm-0.1.49-6435ff3882/node_modules/@napi-rs/canvas-linux-arm-gnueabihf/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-arm-gnueabihf-npm-0.1.50-74ef8d8007/node_modules/@napi-rs/canvas-linux-arm-gnueabihf/",\ "packageDependencies": [\ - ["@napi-rs/canvas-linux-arm-gnueabihf", "npm:0.1.49"]\ + ["@napi-rs/canvas-linux-arm-gnueabihf", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-linux-arm64-gnu", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-arm64-gnu-npm-0.1.49-4e56c60c25/node_modules/@napi-rs/canvas-linux-arm64-gnu/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-arm64-gnu-npm-0.1.50-c8c1e133bc/node_modules/@napi-rs/canvas-linux-arm64-gnu/",\ "packageDependencies": [\ - ["@napi-rs/canvas-linux-arm64-gnu", "npm:0.1.49"]\ + ["@napi-rs/canvas-linux-arm64-gnu", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-linux-arm64-musl", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-arm64-musl-npm-0.1.49-165f000427/node_modules/@napi-rs/canvas-linux-arm64-musl/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-arm64-musl-npm-0.1.50-c675999c51/node_modules/@napi-rs/canvas-linux-arm64-musl/",\ "packageDependencies": [\ - ["@napi-rs/canvas-linux-arm64-musl", "npm:0.1.49"]\ + ["@napi-rs/canvas-linux-arm64-musl", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-linux-x64-gnu", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-x64-gnu-npm-0.1.49-2a16f20d9a/node_modules/@napi-rs/canvas-linux-x64-gnu/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-x64-gnu-npm-0.1.50-a8ca0545bd/node_modules/@napi-rs/canvas-linux-x64-gnu/",\ "packageDependencies": [\ - ["@napi-rs/canvas-linux-x64-gnu", "npm:0.1.49"]\ + ["@napi-rs/canvas-linux-x64-gnu", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-linux-x64-musl", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-x64-musl-npm-0.1.49-9155bc1080/node_modules/@napi-rs/canvas-linux-x64-musl/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-linux-x64-musl-npm-0.1.50-65f7471d30/node_modules/@napi-rs/canvas-linux-x64-musl/",\ "packageDependencies": [\ - ["@napi-rs/canvas-linux-x64-musl", "npm:0.1.49"]\ + ["@napi-rs/canvas-linux-x64-musl", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ ]],\ ["@napi-rs/canvas-win32-x64-msvc", [\ - ["npm:0.1.49", {\ - "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-win32-x64-msvc-npm-0.1.49-39187e36a2/node_modules/@napi-rs/canvas-win32-x64-msvc/",\ + ["npm:0.1.50", {\ + "packageLocation": "./.yarn/unplugged/@napi-rs-canvas-win32-x64-msvc-npm-0.1.50-52fd2a856e/node_modules/@napi-rs/canvas-win32-x64-msvc/",\ "packageDependencies": [\ - ["@napi-rs/canvas-win32-x64-msvc", "npm:0.1.49"]\ + ["@napi-rs/canvas-win32-x64-msvc", "npm:0.1.50"]\ ],\ "linkType": "HARD"\ }]\ @@ -621,7 +632,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@types-continuation-local-storage-npm-3.2.7-763e4dc12b-1f272b53bc.zip/node_modules/@types/continuation-local-storage/",\ "packageDependencies": [\ ["@types/continuation-local-storage", "npm:3.2.7"],\ - ["@types/node", "npm:20.11.20"]\ + ["@types/node", "npm:20.11.21"]\ ],\ "linkType": "HARD"\ }]\ @@ -655,10 +666,10 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["@types/node", [\ - ["npm:20.11.20", {\ - "packageLocation": "./.yarn/cache/@types-node-npm-20.11.20-0036cdf1c0-ff449bdc94.zip/node_modules/@types/node/",\ + ["npm:20.11.21", {\ + "packageLocation": "./.yarn/cache/@types-node-npm-20.11.21-0adac022b0-a31ecc6a3c.zip/node_modules/@types/node/",\ "packageDependencies": [\ - ["@types/node", "npm:20.11.20"],\ + ["@types/node", "npm:20.11.21"],\ ["undici-types", "npm:5.26.5"]\ ],\ "linkType": "HARD"\ @@ -674,11 +685,11 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["@types/pg", [\ - ["npm:8.11.1", {\ - "packageLocation": "./.yarn/cache/@types-pg-npm-8.11.1-5d06a4b9df-2fdcb0dc33.zip/node_modules/@types/pg/",\ + ["npm:8.11.2", {\ + "packageLocation": "./.yarn/cache/@types-pg-npm-8.11.2-bdf321bea4-7c05cf63be.zip/node_modules/@types/pg/",\ "packageDependencies": [\ - ["@types/pg", "npm:8.11.1"],\ - ["@types/node", "npm:20.11.20"],\ + ["@types/pg", "npm:8.11.2"],\ + ["@types/node", "npm:20.11.21"],\ ["pg-protocol", "npm:1.6.0"],\ ["pg-types", "npm:4.0.2"]\ ],\ @@ -712,7 +723,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@types-ws-npm-8.5.10-a877a38f71-9b414dc5e0.zip/node_modules/@types/ws/",\ "packageDependencies": [\ ["@types/ws", "npm:8.5.10"],\ - ["@types/node", "npm:20.11.20"]\ + ["@types/node", "npm:20.11.21"]\ ],\ "linkType": "HARD"\ }],\ @@ -720,7 +731,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@types-ws-npm-8.5.9-91d1b2ab07-7cf66383b8.zip/node_modules/@types/ws/",\ "packageDependencies": [\ ["@types/ws", "npm:8.5.9"],\ - ["@types/node", "npm:20.11.20"]\ + ["@types/node", "npm:20.11.21"]\ ],\ "linkType": "HARD"\ }]\ @@ -770,23 +781,33 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["complex.js", [\ + ["npm:2.1.1", {\ + "packageLocation": "./.yarn/cache/complex.js-npm-2.1.1-2beaccef20-1905d5204d.zip/node_modules/complex.js/",\ + "packageDependencies": [\ + ["complex.js", "npm:2.1.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["daggerbot-ts", [\ ["workspace:.", {\ "packageLocation": "./",\ "packageDependencies": [\ ["daggerbot-ts", "workspace:."],\ - ["@napi-rs/canvas", "npm:0.1.49"],\ + ["@napi-rs/canvas", "npm:0.1.50"],\ ["@octokit/rest", "npm:20.0.2"],\ ["@toast/tokenservice-client", "npm:1.0.12::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.12%2Ftokenservice-client-1.0.12.tgz"],\ ["@types/ms", "npm:0.7.34"],\ - ["@types/node", "npm:20.11.20"],\ + ["@types/node", "npm:20.11.21"],\ ["@types/node-cron", "npm:3.0.11"],\ - ["@types/pg", "npm:8.11.1"],\ + ["@types/pg", "npm:8.11.2"],\ ["@types/sequelize", "npm:4.28.20"],\ ["ansi-colors", "npm:4.1.3"],\ ["dayjs", "npm:1.11.10"],\ ["discord.js", "npm:14.14.1"],\ ["fast-xml-parser", "npm:4.3.5"],\ + ["mathjs", "npm:12.4.0"],\ ["ms", "npm:2.1.3"],\ ["node-cron", "npm:3.0.3"],\ ["pg", "virtual:20c353e2d6536e37339997f03975c6a660f4d296e664d291bd43620c6162cca8eb5ef90b0998dc9db75ff6862e5da587d0530bae26805f5fadc8f17aaa4ff794#npm:8.11.3"],\ @@ -833,6 +854,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["decimal.js", [\ + ["npm:10.4.3", {\ + "packageLocation": "./.yarn/cache/decimal.js-npm-10.4.3-e7d483387c-de663a7bc4.zip/node_modules/decimal.js/",\ + "packageDependencies": [\ + ["decimal.js", "npm:10.4.3"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["deprecation", [\ ["npm:2.3.1", {\ "packageLocation": "./.yarn/cache/deprecation-npm-2.3.1-e19c92d6e7-f56a05e182.zip/node_modules/deprecation/",\ @@ -883,6 +913,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["escape-latex", [\ + ["npm:1.2.0", {\ + "packageLocation": "./.yarn/cache/escape-latex-npm-1.2.0-1481ca81a7-73a787319f.zip/node_modules/escape-latex/",\ + "packageDependencies": [\ + ["escape-latex", "npm:1.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["fast-deep-equal", [\ ["npm:3.1.3", {\ "packageLocation": "./.yarn/cache/fast-deep-equal-npm-3.1.3-790edcfcf5-e21a9d8d84.zip/node_modules/fast-deep-equal/",\ @@ -902,6 +941,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["fraction.js", [\ + ["npm:4.3.4", {\ + "packageLocation": "./.yarn/cache/fraction.js-npm-4.3.4-ce148a1f45-3a1e6b2680.zip/node_modules/fraction.js/",\ + "packageDependencies": [\ + ["fraction.js", "npm:4.3.4"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["generic-pool", [\ ["npm:3.9.0", {\ "packageLocation": "./.yarn/cache/generic-pool-npm-3.9.0-21fff1a77f-3c632d30a6.zip/node_modules/generic-pool/",\ @@ -920,6 +968,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["javascript-natural-sort", [\ + ["npm:0.7.1", {\ + "packageLocation": "./.yarn/cache/javascript-natural-sort-npm-0.7.1-9018625996-7bf6eab678.zip/node_modules/javascript-natural-sort/",\ + "packageDependencies": [\ + ["javascript-natural-sort", "npm:0.7.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["lodash", [\ ["npm:4.17.21", {\ "packageLocation": "./.yarn/cache/lodash-npm-4.17.21-6382451519-c08619c038.zip/node_modules/lodash/",\ @@ -957,6 +1014,24 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["mathjs", [\ + ["npm:12.4.0", {\ + "packageLocation": "./.yarn/cache/mathjs-npm-12.4.0-4e73cebf2f-ee168a7e4b.zip/node_modules/mathjs/",\ + "packageDependencies": [\ + ["mathjs", "npm:12.4.0"],\ + ["@babel/runtime", "npm:7.23.9"],\ + ["complex.js", "npm:2.1.1"],\ + ["decimal.js", "npm:10.4.3"],\ + ["escape-latex", "npm:1.2.0"],\ + ["fraction.js", "npm:4.3.4"],\ + ["javascript-natural-sort", "npm:0.7.1"],\ + ["seedrandom", "npm:3.0.5"],\ + ["tiny-emitter", "npm:2.1.0"],\ + ["typed-function", "npm:4.1.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["moment", [\ ["npm:2.30.1", {\ "packageLocation": "./.yarn/cache/moment-npm-2.30.1-1c51a5c631-ae42d876d4.zip/node_modules/moment/",\ @@ -1265,6 +1340,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["regenerator-runtime", [\ + ["npm:0.14.1", {\ + "packageLocation": "./.yarn/cache/regenerator-runtime-npm-0.14.1-a6c97c609a-5db3161abb.zip/node_modules/regenerator-runtime/",\ + "packageDependencies": [\ + ["regenerator-runtime", "npm:0.14.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["retry-as-promised", [\ ["npm:7.0.4", {\ "packageLocation": "./.yarn/cache/retry-as-promised-npm-7.0.4-d2e9247001-cd9fd20e99.zip/node_modules/retry-as-promised/",\ @@ -1274,6 +1358,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["seedrandom", [\ + ["npm:3.0.5", {\ + "packageLocation": "./.yarn/cache/seedrandom-npm-3.0.5-6946e8f8db-acad5e516c.zip/node_modules/seedrandom/",\ + "packageDependencies": [\ + ["seedrandom", "npm:3.0.5"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["semver", [\ ["npm:7.6.0", {\ "packageLocation": "./.yarn/cache/semver-npm-7.6.0-f4630729f6-1b41018df2.zip/node_modules/semver/",\ @@ -1301,7 +1394,7 @@ const RAW_RUNTIME_STATE = ["@types/mariadb", null],\ ["@types/mysql2", null],\ ["@types/oracledb", null],\ - ["@types/pg", "npm:8.11.1"],\ + ["@types/pg", "npm:8.11.2"],\ ["@types/pg-hstore", null],\ ["@types/snowflake-sdk", null],\ ["@types/sqlite3", null],\ @@ -1402,6 +1495,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["tiny-emitter", [\ + ["npm:2.1.0", {\ + "packageLocation": "./.yarn/cache/tiny-emitter-npm-2.1.0-2a4d94f487-75633f4de4.zip/node_modules/tiny-emitter/",\ + "packageDependencies": [\ + ["tiny-emitter", "npm:2.1.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["toposort-class", [\ ["npm:1.0.1", {\ "packageLocation": "./.yarn/cache/toposort-class-npm-1.0.1-aefabde69e-166cb89ecb.zip/node_modules/toposort-class/",\ @@ -1429,6 +1531,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["typed-function", [\ + ["npm:4.1.1", {\ + "packageLocation": "./.yarn/cache/typed-function-npm-4.1.1-d09696d7f2-0ef538d5f0.zip/node_modules/typed-function/",\ + "packageDependencies": [\ + ["typed-function", "npm:4.1.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["typescript", [\ ["patch:typescript@npm%3A5.3.3#optional!builtin::version=5.3.3&hash=e012d7", {\ "packageLocation": "./.yarn/cache/typescript-patch-4778c7998b-c93786fcc9.zip/node_modules/typescript/",\ @@ -1506,7 +1617,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/wkx-npm-0.5.0-fca5152cd8-b8975e33f9.zip/node_modules/wkx/",\ "packageDependencies": [\ ["wkx", "npm:0.5.0"],\ - ["@types/node", "npm:20.11.20"]\ + ["@types/node", "npm:20.11.21"]\ ],\ "linkType": "HARD"\ }]\ diff --git a/package.json b/package.json index 4d664fb..4c70de2 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,14 @@ "engineStrict": true, "packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb", "dependencies": { - "@napi-rs/canvas": "0.1.49", + "@napi-rs/canvas": "0.1.50", "@octokit/rest": "20.0.2", "@toast/tokenservice-client": "1.0.12", "ansi-colors": "4.1.3", "dayjs": "1.11.10", "discord.js": "14.14.1", "fast-xml-parser": "4.3.5", + "mathjs": "12.4.0", "ms": "2.1.3", "node-cron": "3.0.3", "pg": "8.11.3", @@ -51,9 +52,9 @@ }, "devDependencies": { "@types/ms": "0.7.34", - "@types/node": "20.11.20", + "@types/node": "20.11.21", "@types/node-cron": "3.0.11", - "@types/pg": "8.11.1", + "@types/pg": "8.11.2", "@types/sequelize": "4.28.20", "typescript": "5.3.3" } diff --git a/src/commands/calculator.ts b/src/commands/calculator.ts index fb290d8..547825b 100644 --- a/src/commands/calculator.ts +++ b/src/commands/calculator.ts @@ -2,18 +2,22 @@ import Discord from 'discord.js'; import TClient from '../client.js'; import MessageTool from '../helpers/MessageTool.js'; import Formatters from '../helpers/Formatters.js'; +import * as math from 'mathjs';// I hate this, but it doesn't provide a default export though :cimpCopium: export default class Calculator { static run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){ const now = Date.now(); const exp = interaction.options.getString('expression', true).replace(/[^-()\d/*+.]/g, ''); try { - const result = eval(exp); + let result:math.EvalFunction; switch (exp) { case '1+1': - return interaction.reply('2, quick maths.'); + return interaction.reply('Wh-why are you doing this? I mean... **1+1** is **2**, but... *why?*'); case '2+2': - return interaction.reply('2+2 is 4, minus 1 that\'s 3, quick maths.'); + return interaction.reply('https://c.tenor.com/5-bc8MtSWCYAAAAC/tenor.gif'); + case '2+2-1': + case '1-2+2': + return interaction.reply('https://tenor.com/bhI9r.gif'); case '0/0': return interaction.reply(MessageTool.concatMessage( 'Imagine that you have zero cookies and you split them evenly among zero friends.', @@ -21,8 +25,11 @@ export default class Calculator { 'And Cookie Monster is sad that there are no cookies, and you are sad that you have no friends.', '-- Siri, 2015' )); - }; - interaction.reply({embeds:[new client.embed().setColor(client.config.embedColor).addFields({name: 'Expression', value: `\`\`\`js\n${exp}\n\`\`\``},{name: 'Answer', value: `\`\`\`js\n${result}\n\`\`\``}).setFooter({text: `Time taken: ${Formatters.timeFormat(Date.now() - now, 3)}`})]}) + default: + result = math.evaluate(exp); + break; + } + if (typeof result !== 'undefined') interaction.reply({embeds:[new client.embed().setColor(client.config.embedColor).addFields({name: 'Expression', value: `\`\`\`js\n${exp}\n\`\`\``},{name: 'Answer', value: `\`\`\`js\n${result}\n\`\`\``}).setFooter({text: `Time taken: ${Formatters.timeFormat(Date.now() - now, 3)}`})]}) } catch { interaction.reply('The given expression is invalid.'); } diff --git a/yarn.lock b/yarn.lock index fa0a9ea..d165101 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,6 +5,15 @@ __metadata: version: 8 cacheKey: 10 +"@babel/runtime@npm:^7.23.9": + version: 7.23.9 + resolution: "@babel/runtime@npm:7.23.9" + dependencies: + regenerator-runtime: "npm:^0.14.0" + checksum: 10/9a520fe1bf72249f7dd60ff726434251858de15cccfca7aa831bd19d0d3fb17702e116ead82724659b8da3844977e5e13de2bae01eb8a798f2823a669f122be6 + languageName: node + linkType: hard + "@discordjs/builders@npm:^1.7.0": version: 1.7.0 resolution: "@discordjs/builders@npm:1.7.0" @@ -107,82 +116,82 @@ __metadata: languageName: node linkType: hard -"@napi-rs/canvas-android-arm64@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-android-arm64@npm:0.1.49" +"@napi-rs/canvas-android-arm64@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-android-arm64@npm:0.1.50" conditions: os=android & cpu=arm64 languageName: node linkType: hard -"@napi-rs/canvas-darwin-arm64@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-darwin-arm64@npm:0.1.49" +"@napi-rs/canvas-darwin-arm64@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-darwin-arm64@npm:0.1.50" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@napi-rs/canvas-darwin-x64@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-darwin-x64@npm:0.1.49" +"@napi-rs/canvas-darwin-x64@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-darwin-x64@npm:0.1.50" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.49" +"@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-linux-arm-gnueabihf@npm:0.1.50" conditions: os=linux & cpu=arm languageName: node linkType: hard -"@napi-rs/canvas-linux-arm64-gnu@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-linux-arm64-gnu@npm:0.1.49" +"@napi-rs/canvas-linux-arm64-gnu@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-linux-arm64-gnu@npm:0.1.50" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@napi-rs/canvas-linux-arm64-musl@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-linux-arm64-musl@npm:0.1.49" +"@napi-rs/canvas-linux-arm64-musl@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-linux-arm64-musl@npm:0.1.50" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@napi-rs/canvas-linux-x64-gnu@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-linux-x64-gnu@npm:0.1.49" +"@napi-rs/canvas-linux-x64-gnu@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-linux-x64-gnu@npm:0.1.50" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@napi-rs/canvas-linux-x64-musl@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-linux-x64-musl@npm:0.1.49" +"@napi-rs/canvas-linux-x64-musl@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-linux-x64-musl@npm:0.1.50" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@napi-rs/canvas-win32-x64-msvc@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas-win32-x64-msvc@npm:0.1.49" +"@napi-rs/canvas-win32-x64-msvc@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas-win32-x64-msvc@npm:0.1.50" conditions: os=win32 & cpu=x64 languageName: node linkType: hard -"@napi-rs/canvas@npm:0.1.49": - version: 0.1.49 - resolution: "@napi-rs/canvas@npm:0.1.49" +"@napi-rs/canvas@npm:0.1.50": + version: 0.1.50 + resolution: "@napi-rs/canvas@npm:0.1.50" dependencies: - "@napi-rs/canvas-android-arm64": "npm:0.1.49" - "@napi-rs/canvas-darwin-arm64": "npm:0.1.49" - "@napi-rs/canvas-darwin-x64": "npm:0.1.49" - "@napi-rs/canvas-linux-arm-gnueabihf": "npm:0.1.49" - "@napi-rs/canvas-linux-arm64-gnu": "npm:0.1.49" - "@napi-rs/canvas-linux-arm64-musl": "npm:0.1.49" - "@napi-rs/canvas-linux-x64-gnu": "npm:0.1.49" - "@napi-rs/canvas-linux-x64-musl": "npm:0.1.49" - "@napi-rs/canvas-win32-x64-msvc": "npm:0.1.49" + "@napi-rs/canvas-android-arm64": "npm:0.1.50" + "@napi-rs/canvas-darwin-arm64": "npm:0.1.50" + "@napi-rs/canvas-darwin-x64": "npm:0.1.50" + "@napi-rs/canvas-linux-arm-gnueabihf": "npm:0.1.50" + "@napi-rs/canvas-linux-arm64-gnu": "npm:0.1.50" + "@napi-rs/canvas-linux-arm64-musl": "npm:0.1.50" + "@napi-rs/canvas-linux-x64-gnu": "npm:0.1.50" + "@napi-rs/canvas-linux-x64-musl": "npm:0.1.50" + "@napi-rs/canvas-win32-x64-msvc": "npm:0.1.50" dependenciesMeta: "@napi-rs/canvas-android-arm64": optional: true @@ -202,7 +211,7 @@ __metadata: optional: true "@napi-rs/canvas-win32-x64-msvc": optional: true - checksum: 10/78a7e229a0a15d337200b5a9f19da2904c4c6b11971328f5e9b29f94b3d90041a46e01a4d8058b420e0ee593f6f24bbed957dab71ff1618d75edfaff65e6b61c + checksum: 10/c9ed3ecdaa54c82b4a98bbd7a5297b80083e779ab28a929b2a795ef58b436850a40b569b36f93b709d8ae811573680b775688179d8e7d7d6fbd181420c6945ca languageName: node linkType: hard @@ -473,23 +482,23 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:20.11.20": - version: 20.11.20 - resolution: "@types/node@npm:20.11.20" +"@types/node@npm:*, @types/node@npm:20.11.21": + version: 20.11.21 + resolution: "@types/node@npm:20.11.21" dependencies: undici-types: "npm:~5.26.4" - checksum: 10/ff449bdc94810dadb54e0f77dd587c6505ef79ffa5a208c16eb29b223365b188f4c935a3abaf0906a01d05257c3da1f72465594a841d35bcf7b6deac7a6938fb + checksum: 10/a31ecc6a3c615bca310ffe7dea23613153ff9e1e175c09d14198402b2cef9b1bb1bf3912aff6ffc6cb01b99a025ec6dd6474c797bfb0aaf83daf4edaea063760 languageName: node linkType: hard -"@types/pg@npm:8.11.1": - version: 8.11.1 - resolution: "@types/pg@npm:8.11.1" +"@types/pg@npm:8.11.2": + version: 8.11.2 + resolution: "@types/pg@npm:8.11.2" dependencies: "@types/node": "npm:*" pg-protocol: "npm:*" pg-types: "npm:^4.0.1" - checksum: 10/2fdcb0dc331c4f4e334061c30a14187a6d835a049be9e9a2d84d55935025c45be7f5f40fd6b854c19fcf72d17e854481b11a461d7679005d9813bf29c56ba380 + checksum: 10/7c05cf63beffc0f8d817d080cdd98d199a2bd732b779b9aadddcb8659f861f7aafb3bc071636b9eaa65b36cfe998ee66e21aa1485e583b190918fe2f856a6c53 languageName: node linkType: hard @@ -565,22 +574,30 @@ __metadata: languageName: node linkType: hard +"complex.js@npm:^2.1.1": + version: 2.1.1 + resolution: "complex.js@npm:2.1.1" + checksum: 10/1905d5204dd8a4d6f591182aca2045986f1ff3c5373e455ccd10c6ee2905bf1d3811a313d38c68f8a8507523202f91e25177387e3adc386c1b5b5ec2f13a6dbb + languageName: node + linkType: hard + "daggerbot-ts@workspace:.": version: 0.0.0-use.local resolution: "daggerbot-ts@workspace:." dependencies: - "@napi-rs/canvas": "npm:0.1.49" + "@napi-rs/canvas": "npm:0.1.50" "@octokit/rest": "npm:20.0.2" "@toast/tokenservice-client": "npm:1.0.12" "@types/ms": "npm:0.7.34" - "@types/node": "npm:20.11.20" + "@types/node": "npm:20.11.21" "@types/node-cron": "npm:3.0.11" - "@types/pg": "npm:8.11.1" + "@types/pg": "npm:8.11.2" "@types/sequelize": "npm:4.28.20" ansi-colors: "npm:4.1.3" dayjs: "npm:1.11.10" discord.js: "npm:14.14.1" fast-xml-parser: "npm:4.3.5" + mathjs: "npm:12.4.0" ms: "npm:2.1.3" node-cron: "npm:3.0.3" pg: "npm:8.11.3" @@ -613,6 +630,13 @@ __metadata: languageName: node linkType: hard +"decimal.js@npm:^10.4.3": + version: 10.4.3 + resolution: "decimal.js@npm:10.4.3" + checksum: 10/de663a7bc4d368e3877db95fcd5c87b965569b58d16cdc4258c063d231ca7118748738df17cd638f7e9dd0be8e34cec08d7234b20f1f2a756a52fc5a38b188d0 + languageName: node + linkType: hard + "deprecation@npm:^2.0.0": version: 2.3.1 resolution: "deprecation@npm:2.3.1" @@ -656,6 +680,13 @@ __metadata: languageName: node linkType: hard +"escape-latex@npm:^1.2.0": + version: 1.2.0 + resolution: "escape-latex@npm:1.2.0" + checksum: 10/73a787319f0965ecb8244bb38bf3a3cba872f0b9a5d3da8821140e9f39fe977045dc953a62b1a2bed4d12bfccbe75a7d8ec786412bf00739eaa2f627d0a8e0d6 + languageName: node + linkType: hard + "fast-deep-equal@npm:3.1.3, fast-deep-equal@npm:^3.1.3": version: 3.1.3 resolution: "fast-deep-equal@npm:3.1.3" @@ -674,6 +705,13 @@ __metadata: languageName: node linkType: hard +"fraction.js@npm:4.3.4": + version: 4.3.4 + resolution: "fraction.js@npm:4.3.4" + checksum: 10/3a1e6b268038ffdea625fab6a8d155d7ab644d35d0c99bc59084bfd29fbc714f3a38381b0627751ddb5f188bcde0b3f48c27e80eeb2ecd440825a7d2cd2bf9f1 + languageName: node + linkType: hard + "generic-pool@npm:3.9.0": version: 3.9.0 resolution: "generic-pool@npm:3.9.0" @@ -688,6 +726,13 @@ __metadata: languageName: node linkType: hard +"javascript-natural-sort@npm:^0.7.1": + version: 0.7.1 + resolution: "javascript-natural-sort@npm:0.7.1" + checksum: 10/7bf6eab67871865d347f09a95aa770f9206c1ab0226bcda6fdd9edec340bf41111a7f82abac30556aa16a21cfa3b2b1ca4a362c8b73dd5ce15220e5d31f49d79 + languageName: node + linkType: hard + "lodash.snakecase@npm:4.1.1": version: 4.1.1 resolution: "lodash.snakecase@npm:4.1.1" @@ -718,6 +763,25 @@ __metadata: languageName: node linkType: hard +"mathjs@npm:12.4.0": + version: 12.4.0 + resolution: "mathjs@npm:12.4.0" + dependencies: + "@babel/runtime": "npm:^7.23.9" + complex.js: "npm:^2.1.1" + decimal.js: "npm:^10.4.3" + escape-latex: "npm:^1.2.0" + fraction.js: "npm:4.3.4" + javascript-natural-sort: "npm:^0.7.1" + seedrandom: "npm:^3.0.5" + tiny-emitter: "npm:^2.1.0" + typed-function: "npm:^4.1.1" + bin: + mathjs: bin/cli.js + checksum: 10/ee168a7e4be0bebe9fbd69292462f162d6aae973500e00dbf00f44392ccf80f4de86883819576df2434e9b3e4d6c222a14613e2c0450db8316c373f130bee2b6 + languageName: node + linkType: hard + "moment-timezone@npm:^0.5.43": version: 0.5.45 resolution: "moment-timezone@npm:0.5.45" @@ -975,6 +1039,13 @@ __metadata: languageName: node linkType: hard +"regenerator-runtime@npm:^0.14.0": + version: 0.14.1 + resolution: "regenerator-runtime@npm:0.14.1" + checksum: 10/5db3161abb311eef8c45bcf6565f4f378f785900ed3945acf740a9888c792f75b98ecb77f0775f3bf95502ff423529d23e94f41d80c8256e8fa05ed4b07cf471 + languageName: node + linkType: hard + "retry-as-promised@npm:^7.0.4": version: 7.0.4 resolution: "retry-as-promised@npm:7.0.4" @@ -982,6 +1053,13 @@ __metadata: languageName: node linkType: hard +"seedrandom@npm:^3.0.5": + version: 3.0.5 + resolution: "seedrandom@npm:3.0.5" + checksum: 10/acad5e516c04289f61c2fb9848f449b95f58362b75406b79ec51e101ec885293fc57e3675d2f39f49716336559d7190f7273415d185fead8cd27b171ebf7d8fb + languageName: node + linkType: hard + "semver@npm:^7.5.4": version: 7.6.0 resolution: "semver@npm:7.6.0" @@ -1078,6 +1156,13 @@ __metadata: languageName: node linkType: hard +"tiny-emitter@npm:^2.1.0": + version: 2.1.0 + resolution: "tiny-emitter@npm:2.1.0" + checksum: 10/75633f4de4f47f43af56aff6162f25b87be7efc6f669fda256658f3c3f4a216f23dc0d13200c6fafaaf1b0c7142f0201352fb06aec0b77f68aea96be898f4516 + languageName: node + linkType: hard + "toposort-class@npm:^1.0.1": version: 1.0.1 resolution: "toposort-class@npm:1.0.1" @@ -1099,6 +1184,13 @@ __metadata: languageName: node linkType: hard +"typed-function@npm:^4.1.1": + version: 4.1.1 + resolution: "typed-function@npm:4.1.1" + checksum: 10/0ef538d5f02e5c40659cccc14b5f2727f0e4181f11d91bb7897327c33cc2893de7e92343b6b32e1bb15e44a215a1e92e27ab2aa1353b100a9a2697abf2989a0c + languageName: node + linkType: hard + "typescript@npm:5.3.3": version: 5.3.3 resolution: "typescript@npm:5.3.3"