From cc81accd9510adbd5005855e0d76fe3501a5756f Mon Sep 17 00:00:00 2001 From: NotNite Date: Fri, 26 Aug 2022 20:34:55 -0400 Subject: [PATCH] init --- .eslintrc.json | 15 + .gitignore | 6 + .prettierignore | 6 + .prettierrc | 6 + LICENSE | 21 + config.example.json | 5 + package.json | 25 ++ pnpm-lock.yaml | 361 ++++++++++++++++++ .../20220827002410_init/migration.sql | 8 + prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 20 + src/commands/command.ts | 15 + src/commands/index.ts | 11 + src/commands/ping.ts | 12 + src/commands/remind.ts | 103 +++++ src/index.ts | 62 +++ src/things/bot.ts | 9 + src/things/config.ts | 11 + src/things/db.ts | 5 + src/things/logger.ts | 26 ++ tsconfig.json | 103 +++++ 21 files changed, 833 insertions(+) create mode 100644 .eslintrc.json create mode 100644 .gitignore create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 LICENSE create mode 100644 config.example.json create mode 100644 package.json create mode 100644 pnpm-lock.yaml create mode 100644 prisma/migrations/20220827002410_init/migration.sql create mode 100644 prisma/migrations/migration_lock.toml create mode 100644 prisma/schema.prisma create mode 100644 src/commands/command.ts create mode 100644 src/commands/index.ts create mode 100644 src/commands/ping.ts create mode 100644 src/commands/remind.ts create mode 100644 src/index.ts create mode 100644 src/things/bot.ts create mode 100644 src/things/config.ts create mode 100644 src/things/db.ts create mode 100644 src/things/logger.ts create mode 100644 tsconfig.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..8426f6c --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "env": { + "browser": true, + "commonjs": true, + "es2021": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 2020 + }, + "rules": { + "no-undef": "off", + "no-console": "off" + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3237f36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/dist + +config.json +violet.log +database.db diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..e03ae76 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,6 @@ +README.md +node_modules/ +dist/ +package.json +package-lock.json +pnpm-lock.yaml diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..daff9d2 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "printWidth": 80, + "trailingComma": "none", + "tabWidth": 2, + "singleQuote": false +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b90810e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 NotNite + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/config.example.json b/config.example.json new file mode 100644 index 0000000..955d438 --- /dev/null +++ b/config.example.json @@ -0,0 +1,5 @@ +{ + "token": "your bot token", + "testGuilds": ["your guild ID"], + "logChannel": "your channel ID" +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..9bc38c5 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "violet", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "NotNite", + "license": "MIT", + "devDependencies": { + "@types/bunyan": "^1.8.8", + "@types/node": "^18.7.10", + "prisma": "^4.2.1", + "typescript": "^4.7.4" + }, + "dependencies": { + "@prisma/client": "^4.2.1", + "eris": "^0.17.1", + "parse-duration": "^1.0.2", + "pino": "^8.4.2", + "pino-pretty": "^9.1.0" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..fa5dfbe --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,361 @@ +lockfileVersion: 5.4 + +specifiers: + '@prisma/client': ^4.2.1 + '@types/bunyan': ^1.8.8 + '@types/node': ^18.7.10 + eris: ^0.17.1 + parse-duration: ^1.0.2 + pino: ^8.4.2 + pino-pretty: ^9.1.0 + prisma: ^4.2.1 + typescript: ^4.7.4 + +dependencies: + '@prisma/client': 4.2.1_prisma@4.2.1 + eris: 0.17.1 + parse-duration: 1.0.2 + pino: 8.4.2 + pino-pretty: 9.1.0 + +devDependencies: + '@types/bunyan': 1.8.8 + '@types/node': 18.7.10 + prisma: 4.2.1 + typescript: 4.7.4 + +packages: + + /@prisma/client/4.2.1_prisma@4.2.1: + resolution: {integrity: sha512-PZBkY60+k5oix+e6IUfl3ub8TbRLNsPLdfWrdy2eh80WcHTaT+/UfvXf/B7gXedH7FRtbPFHZXk1hZenJiJZFQ==} + engines: {node: '>=14.17'} + requiresBuild: true + peerDependencies: + prisma: '*' + peerDependenciesMeta: + prisma: + optional: true + dependencies: + '@prisma/engines-version': 4.2.0-33.2920a97877e12e055c1333079b8d19cee7f33826 + prisma: 4.2.1 + dev: false + + /@prisma/engines-version/4.2.0-33.2920a97877e12e055c1333079b8d19cee7f33826: + resolution: {integrity: sha512-tktkqdiwqE4QhmE088boPt+FwPj1Jub/zk+5F6sEfcRHzO5yz9jyMD5HFVtiwxZPLx/8Xg9ElnuTi8E5lWVQFQ==} + dev: false + + /@prisma/engines/4.2.1: + resolution: {integrity: sha512-0KqBwREUOjBiHwITsQzw2DWfLHjntvbqzGRawj4sBMnIiL5CXwyDUKeHOwXzKMtNr1rEjxEsypM14g0CzLRK3g==} + requiresBuild: true + + /@types/bunyan/1.8.8: + resolution: {integrity: sha512-Cblq+Yydg3u+sGiz2mjHjC5MPmdjY+No4qvHrF+BUhblsmSfMvsHLbOG62tPbonsqBj6sbWv1LHcsoe5Jw+/Ow==} + dependencies: + '@types/node': 18.7.10 + dev: true + + /@types/node/18.7.10: + resolution: {integrity: sha512-SST7B//wF7xlGoLo1IEVB0cQ4e7BgXlDk5IaPgb5s0DlYLjb4if07h8+0zbQIvahfPNXs6e7zyT0EH1MqaS+5g==} + dev: true + + /abort-controller/3.0.0: + resolution: {integrity: sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==} + engines: {node: '>=6.5'} + dependencies: + event-target-shim: 5.0.1 + dev: false + + /atomic-sleep/1.0.0: + resolution: {integrity: sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==} + engines: {node: '>=8.0.0'} + dev: false + + /balanced-match/1.0.2: + resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} + dev: false + + /brace-expansion/2.0.1: + resolution: {integrity: sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==} + dependencies: + balanced-match: 1.0.2 + dev: false + + /colorette/2.0.19: + resolution: {integrity: sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ==} + dev: false + + /dateformat/4.6.3: + resolution: {integrity: sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==} + dev: false + + /end-of-stream/1.4.4: + resolution: {integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==} + dependencies: + once: 1.4.0 + dev: false + + /eris/0.17.1: + resolution: {integrity: sha512-PexpHusPxViuzcsSM0GQEAgZRJbziFfeeLifc8+ZrvS88UusPieQlUD7pRm28E7m7rN+p+Rt6bf9jGLwD725Zg==} + engines: {node: '>=10.4.0'} + dependencies: + ws: 8.8.1 + optionalDependencies: + opusscript: 0.0.8 + tweetnacl: 1.0.3 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + dev: false + + /event-target-shim/5.0.1: + resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} + engines: {node: '>=6'} + dev: false + + /fast-copy/2.1.3: + resolution: {integrity: sha512-LDzYKNTHhD+XOp8wGMuCkY4eTxFZOOycmpwLBiuF3r3OjOmZnURRD8t2dUAbmKuXGbo/MGggwbSjcBdp8QT0+g==} + dev: false + + /fast-redact/3.1.2: + resolution: {integrity: sha512-+0em+Iya9fKGfEQGcd62Yv6onjBmmhV1uh86XVfOU8VwAe6kaFdQCWI9s0/Nnugx5Vd9tdbZ7e6gE2tR9dzXdw==} + engines: {node: '>=6'} + dev: false + + /fast-safe-stringify/2.1.1: + resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} + dev: false + + /fs.realpath/1.0.0: + resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} + dev: false + + /glob/8.0.3: + resolution: {integrity: sha512-ull455NHSHI/Y1FqGaaYFaLGkNMMJbavMrEGFXG/PGrg6y7sutWHUHrz6gy6WEBH6akM1M414dWKCNs+IhKdiQ==} + engines: {node: '>=12'} + dependencies: + fs.realpath: 1.0.0 + inflight: 1.0.6 + inherits: 2.0.4 + minimatch: 5.1.0 + once: 1.4.0 + dev: false + + /help-me/4.0.1: + resolution: {integrity: sha512-PLv01Z+OhEPKj2QPYB4kjoCUkopYNPUK3EROlaPIf5bib752fZ+VCvGDAoA+FXo/OwCyLEA4D2e0mX8+Zhcplw==} + dependencies: + glob: 8.0.3 + readable-stream: 3.6.0 + dev: false + + /inflight/1.0.6: + resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + dependencies: + once: 1.4.0 + wrappy: 1.0.2 + dev: false + + /inherits/2.0.4: + resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} + dev: false + + /joycon/3.1.1: + resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} + engines: {node: '>=10'} + dev: false + + /minimatch/5.1.0: + resolution: {integrity: sha512-9TPBGGak4nHfGZsPBohm9AWg6NoT7QTCehS3BIJABslyZbzxfV78QM2Y6+i741OPZIafFAaiiEMh5OyIrJPgtg==} + engines: {node: '>=10'} + dependencies: + brace-expansion: 2.0.1 + dev: false + + /minimist/1.2.6: + resolution: {integrity: sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==} + dev: false + + /on-exit-leak-free/2.1.0: + resolution: {integrity: sha512-VuCaZZAjReZ3vUwgOB8LxAosIurDiAW0s13rI1YwmaP++jvcxP77AWoQvenZebpCA2m8WC1/EosPYPMjnRAp/w==} + dev: false + + /once/1.4.0: + resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} + dependencies: + wrappy: 1.0.2 + dev: false + + /opusscript/0.0.8: + resolution: {integrity: sha512-VSTi1aWFuCkRCVq+tx/BQ5q9fMnQ9pVZ3JU4UHKqTkf0ED3fKEPdr+gKAAl3IA2hj9rrP6iyq3hlcJq3HELtNQ==} + requiresBuild: true + dev: false + optional: true + + /parse-duration/1.0.2: + resolution: {integrity: sha512-Dg27N6mfok+ow1a2rj/nRjtCfaKrHUZV2SJpEn/s8GaVUSlf4GGRCRP1c13Hj+wfPKVMrFDqLMLITkYKgKxyyg==} + dev: false + + /pino-abstract-transport/1.0.0: + resolution: {integrity: sha512-c7vo5OpW4wIS42hUVcT5REsL8ZljsUfBjqV/e2sFxmFEFZiq1XLUp5EYLtuDH6PEHq9W1egWqRbnLUP5FuZmOA==} + dependencies: + readable-stream: 4.1.0 + split2: 4.1.0 + dev: false + + /pino-pretty/9.1.0: + resolution: {integrity: sha512-IM6NY9LLo/dVgY7/prJhCh4rAJukafdt0ibxeNOWc2fxKMyTk90SOB9Ao2HfbtShT9QPeP0ePpJktksMhSQMYA==} + hasBin: true + dependencies: + colorette: 2.0.19 + dateformat: 4.6.3 + fast-copy: 2.1.3 + fast-safe-stringify: 2.1.1 + help-me: 4.0.1 + joycon: 3.1.1 + minimist: 1.2.6 + on-exit-leak-free: 2.1.0 + pino-abstract-transport: 1.0.0 + pump: 3.0.0 + readable-stream: 4.1.0 + secure-json-parse: 2.5.0 + sonic-boom: 3.2.0 + strip-json-comments: 3.1.1 + dev: false + + /pino-std-serializers/6.0.0: + resolution: {integrity: sha512-mMMOwSKrmyl+Y12Ri2xhH1lbzQxwwpuru9VjyJpgFIH4asSj88F2csdMwN6+M5g1Ll4rmsYghHLQJw81tgZ7LQ==} + dev: false + + /pino/8.4.2: + resolution: {integrity: sha512-PlXDeGhJZfAuVay+wtlS02s5j8uisQveZExYdAm9MwwxUQSz9R7Q78XtjM2tTa4sa5KJmygimZjZxXXuHgV6ew==} + hasBin: true + dependencies: + atomic-sleep: 1.0.0 + fast-redact: 3.1.2 + on-exit-leak-free: 2.1.0 + pino-abstract-transport: 1.0.0 + pino-std-serializers: 6.0.0 + process-warning: 2.0.0 + quick-format-unescaped: 4.0.4 + real-require: 0.2.0 + safe-stable-stringify: 2.3.1 + sonic-boom: 3.2.0 + thread-stream: 2.1.0 + dev: false + + /prisma/4.2.1: + resolution: {integrity: sha512-HuYqnTDgH8atjPGtYmY0Ql9XrrJnfW7daG1PtAJRW0E6gJxc50lY3vrIDn0yjMR3TvRlypjTcspQX8DT+xD4Sg==} + engines: {node: '>=14.17'} + hasBin: true + requiresBuild: true + dependencies: + '@prisma/engines': 4.2.1 + + /process-warning/2.0.0: + resolution: {integrity: sha512-+MmoAXoUX+VTHAlwns0h+kFUWFs/3FZy+ZuchkgjyOu3oioLAo2LB5aCfKPh2+P9O18i3m43tUEv3YqttSy0Ww==} + dev: false + + /pump/3.0.0: + resolution: {integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==} + dependencies: + end-of-stream: 1.4.4 + once: 1.4.0 + dev: false + + /quick-format-unescaped/4.0.4: + resolution: {integrity: sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg==} + dev: false + + /readable-stream/3.6.0: + resolution: {integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==} + engines: {node: '>= 6'} + dependencies: + inherits: 2.0.4 + string_decoder: 1.3.0 + util-deprecate: 1.0.2 + dev: false + + /readable-stream/4.1.0: + resolution: {integrity: sha512-sVisi3+P2lJ2t0BPbpK629j8wRW06yKGJUcaLAGXPAUhyUxVJm7VsCTit1PFgT4JHUDMrGNR+ZjSKpzGaRF3zw==} + engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} + dependencies: + abort-controller: 3.0.0 + dev: false + + /real-require/0.2.0: + resolution: {integrity: sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg==} + engines: {node: '>= 12.13.0'} + dev: false + + /safe-buffer/5.2.1: + resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} + dev: false + + /safe-stable-stringify/2.3.1: + resolution: {integrity: sha512-kYBSfT+troD9cDA85VDnHZ1rpHC50O0g1e6WlGHVCz/g+JS+9WKLj+XwFYyR8UbrZN8ll9HUpDAAddY58MGisg==} + engines: {node: '>=10'} + dev: false + + /secure-json-parse/2.5.0: + resolution: {integrity: sha512-ZQruFgZnIWH+WyO9t5rWt4ZEGqCKPwhiw+YbzTwpmT9elgLrLcfuyUiSnwwjUiVy9r4VM3urtbNF1xmEh9IL2w==} + dev: false + + /sonic-boom/3.2.0: + resolution: {integrity: sha512-SbbZ+Kqj/XIunvIAgUZRlqd6CGQYq71tRRbXR92Za8J/R3Yh4Av+TWENiSiEgnlwckYLyP0YZQWVfyNC0dzLaA==} + dependencies: + atomic-sleep: 1.0.0 + dev: false + + /split2/4.1.0: + resolution: {integrity: sha512-VBiJxFkxiXRlUIeyMQi8s4hgvKCSjtknJv/LVYbrgALPwf5zSKmEwV9Lst25AkvMDnvxODugjdl6KZgwKM1WYQ==} + engines: {node: '>= 10.x'} + dev: false + + /string_decoder/1.3.0: + resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} + dependencies: + safe-buffer: 5.2.1 + dev: false + + /strip-json-comments/3.1.1: + resolution: {integrity: sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==} + engines: {node: '>=8'} + dev: false + + /thread-stream/2.1.0: + resolution: {integrity: sha512-5+Pf2Ya31CsZyIPYYkhINzdTZ3guL+jHq7D8lkBybgGcSQIKDbid3NJku3SpCKeE/gACWAccDA/rH2B6doC5aA==} + dependencies: + real-require: 0.2.0 + dev: false + + /tweetnacl/1.0.3: + resolution: {integrity: sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==} + requiresBuild: true + dev: false + optional: true + + /typescript/4.7.4: + resolution: {integrity: sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==} + engines: {node: '>=4.2.0'} + hasBin: true + dev: true + + /util-deprecate/1.0.2: + resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + dev: false + + /wrappy/1.0.2: + resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==} + dev: false + + /ws/8.8.1: + resolution: {integrity: sha512-bGy2JzvzkPowEJV++hF07hAD6niYSr0JzBNo/J29WsB57A2r7Wlc1UFcTR9IzrPvuNVO4B8LGqF8qcpsVOhJCA==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ^5.0.2 + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + dev: false diff --git a/prisma/migrations/20220827002410_init/migration.sql b/prisma/migrations/20220827002410_init/migration.sql new file mode 100644 index 0000000..a742f9e --- /dev/null +++ b/prisma/migrations/20220827002410_init/migration.sql @@ -0,0 +1,8 @@ +-- CreateTable +CREATE TABLE "Reminder" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "user" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL, + "sendAt" DATETIME NOT NULL, + "message" TEXT +); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5e5c47 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..4759fae --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,20 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "sqlite" + url = "file:./database.db" +} + +model Reminder { + id Int @id @default(autoincrement()) + user String + + createdAt DateTime + sendAt DateTime + message String? +} diff --git a/src/commands/command.ts b/src/commands/command.ts new file mode 100644 index 0000000..28d8536 --- /dev/null +++ b/src/commands/command.ts @@ -0,0 +1,15 @@ +import { ApplicationCommandOptions, CommandInteraction } from "eris"; + +type Command = { + name: string; + description: string; + aliases?: string[]; + draft: boolean; + + options?: ApplicationCommandOptions[]; + type?: 1; + + command: (interaction: CommandInteraction) => void; +}; + +export default Command; diff --git a/src/commands/index.ts b/src/commands/index.ts new file mode 100644 index 0000000..5f49dff --- /dev/null +++ b/src/commands/index.ts @@ -0,0 +1,11 @@ +import Command from "./command"; + +import ping from "./ping"; +import remind from "./remind"; + +const commands: { [key: string]: Command } = { + ping, + remind +}; + +export default commands; diff --git a/src/commands/ping.ts b/src/commands/ping.ts new file mode 100644 index 0000000..6b42e50 --- /dev/null +++ b/src/commands/ping.ts @@ -0,0 +1,12 @@ +import Command from "./command"; + +const ping: Command = { + name: "ping", + description: "Ping the bot.", + draft: true, + command: async (interaction) => { + await interaction.createMessage("Pong!"); + } +}; + +export default ping; diff --git a/src/commands/remind.ts b/src/commands/remind.ts new file mode 100644 index 0000000..7f480e7 --- /dev/null +++ b/src/commands/remind.ts @@ -0,0 +1,103 @@ +import Command from "./command"; + +import db from "../things/db"; +import bot from "../things/bot"; + +import { Constants } from "eris"; +import parse from "parse-duration"; +import logger from "../things/logger"; + +const remind: Command = { + name: "remind", + description: "Reminds you to do something.", + draft: true, + options: [ + { + name: "when", + description: "When to remind you.", + required: true, + type: Constants.ApplicationCommandOptionTypes.STRING + }, + { + name: "what", + description: "What to remind you about.", + type: Constants.ApplicationCommandOptionTypes.STRING + } + ], + command: async (interaction) => { + const whenOption = interaction.data.options?.find((x) => x.name === "when"); + const whatOption = interaction.data.options?.find((x) => x.name === "what"); + + let what = null; + if (whatOption?.type === Constants.ApplicationCommandOptionTypes.STRING) + what = whatOption.value; + + // fucking ts + if (whenOption?.type != Constants.ApplicationCommandOptionTypes.STRING) + return; + + const when = parse(whenOption.value); + if (when === null) { + await interaction.createMessage( + "I didn't understand that time. Try something like `3h` or `2 days`." + ); + return; + } + + const sendAt = new Date(Date.now() + when); + + await db.reminder.create({ + data: { + user: (interaction.member || interaction.user)!.id, + createdAt: new Date(), + sendAt, + message: what + } + }); + + await interaction.createMessage( + `Reminder set .` + ); + } +}; + +async function checkDB() { + const reminders = await db.reminder.findMany({ + where: { + sendAt: { + lte: new Date() + } + } + }); + + for (const reminder of reminders) { + try { + let user = await bot.users.find((x) => x.id === reminder.user); + if (!user) user = await bot.getRESTUser(reminder.user); + if (!user) throw new Error("User not found"); + + const dmChannel = await user.getDMChannel(); + + await dmChannel.createMessage( + `You asked me to remind you about ${ + reminder.message ?? "something" + } .` + ); + } catch (err) { + logger.error( + { err, id: reminder.user }, + "Couldn't send reminder to user" + ); + } + + await db.reminder.delete({ + where: { + id: reminder.id + } + }); + } +} + +setInterval(checkDB, 1000 * 5); + +export default remind; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..82fadf3 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,62 @@ +import config from "./things/config"; +import logger from "./things/logger"; + +import bot from "./things/bot"; +import commands from "./commands/index"; +import Eris, { Constants } from "eris"; + +bot.on("ready", () => { + for (const command of Object.values(commands)) { + if (command.draft) { + logger.info(`Loading draft command ${command.name}`); + + for (const guild of config.testGuilds) { + logger.info(`Loading draft command ${command.name} for guild ${guild}`); + + bot.createGuildCommand(guild, { + name: command.name, + description: command.description, + type: Constants.ApplicationCommandTypes.CHAT_INPUT, + options: command.options + }); + } + } else { + logger.info(`Loading command ${command.name}`); + + bot.createCommand({ + name: command.name, + description: command.description, + type: Constants.ApplicationCommandTypes.CHAT_INPUT + }); + } + } + + logger.info(`All commands registered. Hello!`); +}); + +bot.on("interactionCreate", async (interaction) => { + logger.debug(`Handling interaction ${interaction.id}`); + + if (interaction instanceof Eris.CommandInteraction) { + const commandName = interaction.data.name; + const command = commands[commandName]; + if (command) { + try { + await command.command(interaction); + } catch (err) { + logger.error( + { err }, + `Error running command ${commandName} for interaction ${interaction.id}` + ); + } + } else { + logger.warn(`Unhandled command ${commandName}?`); + } + } +}); + +bot.on("error", (e) => { + logger.error("Error in bot", e); +}); + +bot.connect(); diff --git a/src/things/bot.ts b/src/things/bot.ts new file mode 100644 index 0000000..05aeab9 --- /dev/null +++ b/src/things/bot.ts @@ -0,0 +1,9 @@ +import Eris from "eris"; +import config from "./config"; + +const bot = new Eris.Client("Bot " + config.token, { + restMode: true, + intents: Eris.Constants.Intents.allNonPrivileged +}); + +export default bot; diff --git a/src/things/config.ts b/src/things/config.ts new file mode 100644 index 0000000..0e1cbe0 --- /dev/null +++ b/src/things/config.ts @@ -0,0 +1,11 @@ +import fs from "fs"; + +export type Config = { + token: string; + testGuilds: string[]; + logChannel: string; +}; + +const config: Config = JSON.parse(fs.readFileSync("./config.json", "utf8")); + +export default config; diff --git a/src/things/db.ts b/src/things/db.ts new file mode 100644 index 0000000..b5bf6ce --- /dev/null +++ b/src/things/db.ts @@ -0,0 +1,5 @@ +import { PrismaClient } from "@prisma/client"; + +const prisma = new PrismaClient(); + +export default prisma; diff --git a/src/things/logger.ts b/src/things/logger.ts new file mode 100644 index 0000000..fb68e51 --- /dev/null +++ b/src/things/logger.ts @@ -0,0 +1,26 @@ +import pino, { MultiStreamRes } from "pino"; +import pretty from "pino-pretty"; + +const streams = [ + { + stream: pretty({ + colorize: true + }) + }, + { + stream: pino.destination({ + dest: "violet.log", + append: true, + sync: true + }) + } +]; + +const logger = pino( + { + level: "debug" + }, + pino.multistream(streams) +); + +export default logger; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..6cc93d5 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,103 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + + /* Emit */ + // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist/", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +}