From 11ed134251b38b55ec1eaca3b50c8d54a7f495a0 Mon Sep 17 00:00:00 2001 From: Matteo Juen <45847997+Blvckleg@users.noreply.github.com> Date: Thu, 15 Feb 2024 19:07:14 +0100 Subject: [PATCH 1/2] Update issue templates (#42) * chore(dev): release 1.0.0 * style(read-me): latest tag * chore(master): release 1.0.0 (#41) * chore(master): release 1.0.0 * style: rm changelog dupes * Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 38 ++++++++ .github/ISSUE_TEMPLATE/custom.md | 19 ++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++ CHANGELOG.md | 102 +++++++++++----------- README.md | 2 +- package-lock.json | 4 +- package.json | 2 +- 7 files changed, 131 insertions(+), 56 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..3295781 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve BingusBoingus +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..94fa63d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,19 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: discussion, question +assignees: '' + +--- + +**My Question is:* +Your Question about BingusBoingus. + +**What I've tried so far** + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..11fc491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e21c7d..def444c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,60 +2,58 @@ ## 1.0.0 (2024-02-15) - ### Features -* add config ([3e92d8f](https://github.com/Blvckleg/BingusBoingus/commit/3e92d8f1c69deee224a959c87415f07b71279593)) -* add dockerfile and docker-compose ([4ff5fa0](https://github.com/Blvckleg/BingusBoingus/commit/4ff5fa03ade5e6980441b8da4965867eca963d26)) -* add gitignore ([a361c90](https://github.com/Blvckleg/BingusBoingus/commit/a361c90f7718537949af5f9e08d5f76927b5b9d7)) -* add jest-testing ([6d517a3](https://github.com/Blvckleg/BingusBoingus/commit/6d517a3a775acfbc6421e6caaa3880e7d013711e)) -* add vsc launch ([bc7a93a](https://github.com/Blvckleg/BingusBoingus/commit/bc7a93a438cba5f407f4bfd8dfe722993242fce1)) -* bug report command ([eaa52a3](https://github.com/Blvckleg/BingusBoingus/commit/eaa52a312d508f72b52d1201e06a9ddfabd3331b)) -* cbd command ([dc7b01e](https://github.com/Blvckleg/BingusBoingus/commit/dc7b01ea7143e7f2c7e6a2292776c43cdbe375ef)) -* **cd:** docker.yml ([71c3773](https://github.com/Blvckleg/BingusBoingus/commit/71c37739d1d85b36f939cac8c9d9e13be10c66c8)) -* coinflip ([85db888](https://github.com/Blvckleg/BingusBoingus/commit/85db88885be186984cb39e97560cd854b77b3422)) -* commandHandling ([91c2065](https://github.com/Blvckleg/BingusBoingus/commit/91c2065dd07a60c2e724dd9cdd93f6e2b684174d)) -* deploy commands at startup ([c004eaf](https://github.com/Blvckleg/BingusBoingus/commit/c004eaf8983f6f98c3996f8c252a51a24f00804a)) -* deploy script ([f5efcf5](https://github.com/Blvckleg/BingusBoingus/commit/f5efcf5e35d66e3b0d302fe200b8a796e977f144)) -* deploy-commands ([da7684e](https://github.com/Blvckleg/BingusBoingus/commit/da7684ec0e19eccf3d0010c2976f1d1ca618b0b7)) -* docker commands ([2b36815](https://github.com/Blvckleg/BingusBoingus/commit/2b36815938e294ed580baf30ec86855ec0e0d7a2)) -* docker pipelines ([a647429](https://github.com/Blvckleg/BingusBoingus/commit/a6474296141991916337a4c58bc7b1c065b74929)) -* **Docker:** add test Dockerfile ([b76f32f](https://github.com/Blvckleg/BingusBoingus/commit/b76f32f78821ba866ca06ef4a7c1aad495ca4c61)) -* env sample ([cb3d98c](https://github.com/Blvckleg/BingusBoingus/commit/cb3d98ca5a9e58e038ca4c490cc74d2b3c2eb97f)) -* hello world ([1f96a9a](https://github.com/Blvckleg/BingusBoingus/commit/1f96a9a52543fdb09b978272b832238fd7eb74e8)) -* i think everything works ([0c8f65b](https://github.com/Blvckleg/BingusBoingus/commit/0c8f65bc6c9db80d6a80e196a05904890a4c9900)) -* let swag report someone ([1fa009c](https://github.com/Blvckleg/BingusBoingus/commit/1fa009c8022568de1a940b5705eba82616acd2df)) -* little bit of refactoring deployCommands ([09fc0ba](https://github.com/Blvckleg/BingusBoingus/commit/09fc0ba5d5ca117bee3933621ebd2bb3e8365b8b)) -* nestjs ([e630098](https://github.com/Blvckleg/BingusBoingus/commit/e630098993e5e43503a42277cba1f872633291c4)) -* new commands and response types ([cc1d434](https://github.com/Blvckleg/BingusBoingus/commit/cc1d43447df144f2cb72ed1b1b1bf46568ac9197)) -* prettier config ([39965fc](https://github.com/Blvckleg/BingusBoingus/commit/39965fc4b7c36aa69a4c1e2aa033ead0fa8e3066)) -* remove test cmd, add new cmd, add autoresponses ([d0bd50a](https://github.com/Blvckleg/BingusBoingus/commit/d0bd50abe1cd4eed93cf8f044f136f3e628c9cce)) -* **start-script:** run nest ([8eaa1a8](https://github.com/Blvckleg/BingusBoingus/commit/8eaa1a810be802bd1d23aba0d0f2d1871a7245fc)) -* tunnel for local testing ([2a7e0dd](https://github.com/Blvckleg/BingusBoingus/commit/2a7e0dd4448f079d53b51b4853a39a435ceba009)) -* update launch.json with env ([4c1e8b4](https://github.com/Blvckleg/BingusBoingus/commit/4c1e8b4fa070a16d49ce11942c4d9cc18d889969)) -* use config service for deployment ([76fe7a9](https://github.com/Blvckleg/BingusBoingus/commit/76fe7a9dcf3502e13215a28477fff2aed6bd01c0)) -* vsc launch scripts ([e27df9a](https://github.com/Blvckleg/BingusBoingus/commit/e27df9a456e5986c89ba487d663b80abc7605696)) -* **workflow:** testing ([524e45d](https://github.com/Blvckleg/BingusBoingus/commit/524e45d6868dd0ed4049d376c05e6ed2b6d60ff5)) - +- add config ([3e92d8f](https://github.com/Blvckleg/BingusBoingus/commit/3e92d8f1c69deee224a959c87415f07b71279593)) +- add dockerfile and docker-compose ([4ff5fa0](https://github.com/Blvckleg/BingusBoingus/commit/4ff5fa03ade5e6980441b8da4965867eca963d26)) +- add gitignore ([a361c90](https://github.com/Blvckleg/BingusBoingus/commit/a361c90f7718537949af5f9e08d5f76927b5b9d7)) +- add jest-testing ([6d517a3](https://github.com/Blvckleg/BingusBoingus/commit/6d517a3a775acfbc6421e6caaa3880e7d013711e)) +- add vsc launch ([bc7a93a](https://github.com/Blvckleg/BingusBoingus/commit/bc7a93a438cba5f407f4bfd8dfe722993242fce1)) +- bug report command ([eaa52a3](https://github.com/Blvckleg/BingusBoingus/commit/eaa52a312d508f72b52d1201e06a9ddfabd3331b)) +- cbd command ([dc7b01e](https://github.com/Blvckleg/BingusBoingus/commit/dc7b01ea7143e7f2c7e6a2292776c43cdbe375ef)) +- **cd:** docker.yml ([71c3773](https://github.com/Blvckleg/BingusBoingus/commit/71c37739d1d85b36f939cac8c9d9e13be10c66c8)) +- coinflip ([85db888](https://github.com/Blvckleg/BingusBoingus/commit/85db88885be186984cb39e97560cd854b77b3422)) +- commandHandling ([91c2065](https://github.com/Blvckleg/BingusBoingus/commit/91c2065dd07a60c2e724dd9cdd93f6e2b684174d)) +- deploy commands at startup ([c004eaf](https://github.com/Blvckleg/BingusBoingus/commit/c004eaf8983f6f98c3996f8c252a51a24f00804a)) +- deploy script ([f5efcf5](https://github.com/Blvckleg/BingusBoingus/commit/f5efcf5e35d66e3b0d302fe200b8a796e977f144)) +- deploy-commands ([da7684e](https://github.com/Blvckleg/BingusBoingus/commit/da7684ec0e19eccf3d0010c2976f1d1ca618b0b7)) +- docker commands ([2b36815](https://github.com/Blvckleg/BingusBoingus/commit/2b36815938e294ed580baf30ec86855ec0e0d7a2)) +- docker pipelines ([a647429](https://github.com/Blvckleg/BingusBoingus/commit/a6474296141991916337a4c58bc7b1c065b74929)) +- **Docker:** add test Dockerfile ([b76f32f](https://github.com/Blvckleg/BingusBoingus/commit/b76f32f78821ba866ca06ef4a7c1aad495ca4c61)) +- env sample ([cb3d98c](https://github.com/Blvckleg/BingusBoingus/commit/cb3d98ca5a9e58e038ca4c490cc74d2b3c2eb97f)) +- hello world ([1f96a9a](https://github.com/Blvckleg/BingusBoingus/commit/1f96a9a52543fdb09b978272b832238fd7eb74e8)) +- i think everything works ([0c8f65b](https://github.com/Blvckleg/BingusBoingus/commit/0c8f65bc6c9db80d6a80e196a05904890a4c9900)) +- let swag report someone ([1fa009c](https://github.com/Blvckleg/BingusBoingus/commit/1fa009c8022568de1a940b5705eba82616acd2df)) +- little bit of refactoring deployCommands ([09fc0ba](https://github.com/Blvckleg/BingusBoingus/commit/09fc0ba5d5ca117bee3933621ebd2bb3e8365b8b)) +- nestjs ([e630098](https://github.com/Blvckleg/BingusBoingus/commit/e630098993e5e43503a42277cba1f872633291c4)) +- new commands and response types ([cc1d434](https://github.com/Blvckleg/BingusBoingus/commit/cc1d43447df144f2cb72ed1b1b1bf46568ac9197)) +- prettier config ([39965fc](https://github.com/Blvckleg/BingusBoingus/commit/39965fc4b7c36aa69a4c1e2aa033ead0fa8e3066)) +- remove test cmd, add new cmd, add autoresponses ([d0bd50a](https://github.com/Blvckleg/BingusBoingus/commit/d0bd50abe1cd4eed93cf8f044f136f3e628c9cce)) +- **start-script:** run nest ([8eaa1a8](https://github.com/Blvckleg/BingusBoingus/commit/8eaa1a810be802bd1d23aba0d0f2d1871a7245fc)) +- tunnel for local testing ([2a7e0dd](https://github.com/Blvckleg/BingusBoingus/commit/2a7e0dd4448f079d53b51b4853a39a435ceba009)) +- update launch.json with env ([4c1e8b4](https://github.com/Blvckleg/BingusBoingus/commit/4c1e8b4fa070a16d49ce11942c4d9cc18d889969)) +- use config service for deployment ([76fe7a9](https://github.com/Blvckleg/BingusBoingus/commit/76fe7a9dcf3502e13215a28477fff2aed6bd01c0)) +- vsc launch scripts ([e27df9a](https://github.com/Blvckleg/BingusBoingus/commit/e27df9a456e5986c89ba487d663b80abc7605696)) +- **workflow:** testing ([524e45d](https://github.com/Blvckleg/BingusBoingus/commit/524e45d6868dd0ed4049d376c05e6ed2b6d60ff5)) ### Bug Fixes -* add multiline to long message ([7077bf2](https://github.com/Blvckleg/BingusBoingus/commit/7077bf2bd89fa6ca8e2b5f6abd3f724c82999186)) -* add prettier and update config ([284e7f7](https://github.com/Blvckleg/BingusBoingus/commit/284e7f7d01ff478e233fc9226b951482ed8e001e)) -* **CommandModule:** listen for commands ([12d7d21](https://github.com/Blvckleg/BingusBoingus/commit/12d7d219c289c08b2b20f95320efefbeabb6bfa8)) -* did some stupid shit ([3f541bd](https://github.com/Blvckleg/BingusBoingus/commit/3f541bd451c4c08fd9af23f0f9bd25ab4765844a)) -* docker build ([8088ce9](https://github.com/Blvckleg/BingusBoingus/commit/8088ce95b1735328432dff32a33f1b27364f642f)) -* docker filepath ([ab45c9d](https://github.com/Blvckleg/BingusBoingus/commit/ab45c9d46689bc8793fee974177ea94612d290d8)) -* **docker-image:** copy assets ([2533e36](https://github.com/Blvckleg/BingusBoingus/commit/2533e36139c30817877f5b00d40c433561f36f31)) -* dont push test image ([ab7df94](https://github.com/Blvckleg/BingusBoingus/commit/ab7df94af2cf5bfd942a6bc620f8e4bb51722bf5)) -* nvm found it ([3068220](https://github.com/Blvckleg/BingusBoingus/commit/306822084662757f176edb5efa329441f43ce25e)) -* pull image in docker-compose ([f33c97f](https://github.com/Blvckleg/BingusBoingus/commit/f33c97f60a28816b6ddc8afe7d7de0e11005328e)) -* readme hyperlink ([724037f](https://github.com/Blvckleg/BingusBoingus/commit/724037fe068bd57d4fd3bd2a357aaf295aa62473)) -* remove node 14 from workflow ([22fe493](https://github.com/Blvckleg/BingusBoingus/commit/22fe493eb6debe69f634d192bd52a0892c785b9c)) -* remove unused start config ([b7c75f6](https://github.com/Blvckleg/BingusBoingus/commit/b7c75f69350c77e6ffda9d5a6e43507d76c09a87)) -* remove workflow fail check ([2dcb67d](https://github.com/Blvckleg/BingusBoingus/commit/2dcb67d26f4b8ead467999b0c940fdc08617e667)) -* rm dupe, file name casing ([4e2e43b](https://github.com/Blvckleg/BingusBoingus/commit/4e2e43b835d8bb8cdd13ccc8766a996ccf18a354)) -* typo ([a8eb5d2](https://github.com/Blvckleg/BingusBoingus/commit/a8eb5d210af8cb3194f01a026b5f83ce2e298a02)) -* Update node.js.yml ([ec132ed](https://github.com/Blvckleg/BingusBoingus/commit/ec132ed84c6a6f0c205d7092d2e1465b929dd0f5)) -* update sample env ([fcb9ae9](https://github.com/Blvckleg/BingusBoingus/commit/fcb9ae9c6c325bff61b6c1c513dc08e6674da4f5)) -* use ConfigService ([e2ebdf3](https://github.com/Blvckleg/BingusBoingus/commit/e2ebdf345564179cb0938b6e42c89bd8ada2607d)) +- add multiline to long message ([7077bf2](https://github.com/Blvckleg/BingusBoingus/commit/7077bf2bd89fa6ca8e2b5f6abd3f724c82999186)) +- add prettier and update config ([284e7f7](https://github.com/Blvckleg/BingusBoingus/commit/284e7f7d01ff478e233fc9226b951482ed8e001e)) +- **CommandModule:** listen for commands ([12d7d21](https://github.com/Blvckleg/BingusBoingus/commit/12d7d219c289c08b2b20f95320efefbeabb6bfa8)) +- did some stupid shit ([3f541bd](https://github.com/Blvckleg/BingusBoingus/commit/3f541bd451c4c08fd9af23f0f9bd25ab4765844a)) +- docker build ([8088ce9](https://github.com/Blvckleg/BingusBoingus/commit/8088ce95b1735328432dff32a33f1b27364f642f)) +- docker filepath ([ab45c9d](https://github.com/Blvckleg/BingusBoingus/commit/ab45c9d46689bc8793fee974177ea94612d290d8)) +- **docker-image:** copy assets ([2533e36](https://github.com/Blvckleg/BingusBoingus/commit/2533e36139c30817877f5b00d40c433561f36f31)) +- dont push test image ([ab7df94](https://github.com/Blvckleg/BingusBoingus/commit/ab7df94af2cf5bfd942a6bc620f8e4bb51722bf5)) +- nvm found it ([3068220](https://github.com/Blvckleg/BingusBoingus/commit/306822084662757f176edb5efa329441f43ce25e)) +- pull image in docker-compose ([f33c97f](https://github.com/Blvckleg/BingusBoingus/commit/f33c97f60a28816b6ddc8afe7d7de0e11005328e)) +- readme hyperlink ([724037f](https://github.com/Blvckleg/BingusBoingus/commit/724037fe068bd57d4fd3bd2a357aaf295aa62473)) +- remove node 14 from workflow ([22fe493](https://github.com/Blvckleg/BingusBoingus/commit/22fe493eb6debe69f634d192bd52a0892c785b9c)) +- remove unused start config ([b7c75f6](https://github.com/Blvckleg/BingusBoingus/commit/b7c75f69350c77e6ffda9d5a6e43507d76c09a87)) +- remove workflow fail check ([2dcb67d](https://github.com/Blvckleg/BingusBoingus/commit/2dcb67d26f4b8ead467999b0c940fdc08617e667)) +- rm dupe, file name casing ([4e2e43b](https://github.com/Blvckleg/BingusBoingus/commit/4e2e43b835d8bb8cdd13ccc8766a996ccf18a354)) +- typo ([a8eb5d2](https://github.com/Blvckleg/BingusBoingus/commit/a8eb5d210af8cb3194f01a026b5f83ce2e298a02)) +- Update node.js.yml ([ec132ed](https://github.com/Blvckleg/BingusBoingus/commit/ec132ed84c6a6f0c205d7092d2e1465b929dd0f5)) +- update sample env ([fcb9ae9](https://github.com/Blvckleg/BingusBoingus/commit/fcb9ae9c6c325bff61b6c1c513dc08e6674da4f5)) +- use ConfigService ([e2ebdf3](https://github.com/Blvckleg/BingusBoingus/commit/e2ebdf345564179cb0938b6e42c89bd8ada2607d)) diff --git a/README.md b/README.md index 1589fcd..6034b0d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Status: In Development 🛠️ -Latest: 0.0.1 +Latest: 1.0.0 🤖 Description: diff --git a/package-lock.json b/package-lock.json index 1c83aaf..65330b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "bingusboingus", - "version": "0.0.1", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "bingusboingus", - "version": "0.0.1", + "version": "1.0.0", "license": "MIT", "dependencies": { "@nestjs/config": "^3.1.1", diff --git a/package.json b/package.json index cce75fd..7cd2fa0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bingusboingus", - "version": "0.0.1", + "version": "1.0.0", "description": "Hey look it's Bingus.... or Boingus?? OR BOTH??", "main": "src/main.ts", "scripts": { From 64b937977850ecc6f85721f4cfcff235af17899c Mon Sep 17 00:00:00 2001 From: Matteo Juen <45847997+Blvckleg@users.noreply.github.com> Date: Fri, 16 Feb 2024 20:30:30 +0100 Subject: [PATCH 2/2] Mongodb (#45) * chore: mongoose, nestjs/mongoose * feat: mongoose config and schemas * fix: schema types and validators * cd: mongo compose and init config * cd: coimpose columes * refactor(gitignore): env etc. * refactor: issue templates * feat: mongo and phrases * feat: wip - new interactive command * feat: new commands --- .env.sample | 5 + .../ISSUE_TEMPLATE/{custom.md => question.md} | 7 +- .gitignore | 3 +- docker-compose.yml | 28 +++ infra/mongo/.env.sample | 5 + infra/mongo/init.js | 5 + infra/mongo/mongo.conf | 42 ++++ package-lock.json | 216 +++++++++++++++++- package.json | 3 + src/app.module.ts | 2 + src/config/config.service.ts | 2 +- .../database/mongo/config/config.module.ts | 32 +++ .../database/mongo/config/config.service.ts | 50 ++++ .../database/mongo/config/configuration.ts | 12 + .../mongo/provider/mongo-provider.module.ts | 14 ++ src/main.ts | 2 +- src/modules/command/command.abstract.ts | 15 +- src/modules/command/command.module.ts | 6 + src/modules/command/command.service.ts | 8 +- src/modules/command/commands/get-a-quote.ts | 36 +++ .../command/commands/someone-once-said.ts | 54 +++++ .../modules/someone-once-said.module.ts | 22 ++ .../services/someone-once-said.service.ts | 53 +++++ src/schemas/auto-response.schema.ts | 50 ++++ src/schemas/command.schema.ts | 41 ++++ src/schemas/someone-once-said-entity.model.ts | 6 + src/schemas/someone-once-said.schema.ts | 25 ++ 27 files changed, 728 insertions(+), 16 deletions(-) rename .github/ISSUE_TEMPLATE/{custom.md => question.md} (73%) create mode 100644 infra/mongo/.env.sample create mode 100644 infra/mongo/init.js create mode 100644 infra/mongo/mongo.conf create mode 100644 src/config/database/mongo/config/config.module.ts create mode 100644 src/config/database/mongo/config/config.service.ts create mode 100644 src/config/database/mongo/config/configuration.ts create mode 100644 src/config/database/mongo/provider/mongo-provider.module.ts create mode 100644 src/modules/command/commands/get-a-quote.ts create mode 100644 src/modules/command/commands/someone-once-said.ts create mode 100644 src/modules/someone-once-said/modules/someone-once-said.module.ts create mode 100644 src/modules/someone-once-said/services/someone-once-said.service.ts create mode 100644 src/schemas/auto-response.schema.ts create mode 100644 src/schemas/command.schema.ts create mode 100644 src/schemas/someone-once-said-entity.model.ts create mode 100644 src/schemas/someone-once-said.schema.ts diff --git a/.env.sample b/.env.sample index 3ff6081..c40eeaa 100644 --- a/.env.sample +++ b/.env.sample @@ -5,3 +5,8 @@ CLIENT_ID = # invite link: # https://discord.com/api/oauth2/authorize?CLIENT_ID=&permissions=0&scope=bot%20applications.commands SERVER_ID = +# Mongo configuration +MONGO_URI= +MONGO_PORT= +MONGO_USERNAME= +MONGO_PASSWORD= diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/question.md similarity index 73% rename from .github/ISSUE_TEMPLATE/custom.md rename to .github/ISSUE_TEMPLATE/question.md index 94fa63d..9253b88 100644 --- a/.github/ISSUE_TEMPLATE/custom.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -1,13 +1,12 @@ --- -name: Custom issue template -about: Describe this issue template's purpose here. +name: Question +about: I have a question about the bots functionality. title: '' labels: discussion, question assignees: '' - --- -**My Question is:* +\*_My Question is:_ Your Question about BingusBoingus. **What I've tried so far** diff --git a/.gitignore b/.gitignore index f32240c..9b647c8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ node_modules/ tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo -bingusboingus.code-workspace \ No newline at end of file +bingusboingus.code-workspace +.vscode/settings.* \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7181435..bcde1ec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,3 +11,31 @@ services: ports: - 3000:3000 restart: unless-stopped + + mongo: + image: mongo:6.0.3 + hostname: mongo + volumes: + - ./infra/mongo:/db/data:rw + - ./infra/mongo/mongo.conf:/etc/mongo/mongo.conf:ro + - ./infra/mongo/init.js:/docker-entrypoint-initdb.d/init.js:ro + env_file: + - ./infra/mongo/.env + command: + - --config + - /etc/mongo/mongo.conf + ports: + - 27017:27017 + healthcheck: + test: + [ + 'CMD', + 'sh', + '-c', + 'echo ''db.runCommand("ping").ok'' | mongosh localhost:27017 --quiet', + ] + interval: 10s + timeout: 10s + retries: 5 + start_period: 40s + restart: unless-stopped diff --git a/infra/mongo/.env.sample b/infra/mongo/.env.sample new file mode 100644 index 0000000..1368deb --- /dev/null +++ b/infra/mongo/.env.sample @@ -0,0 +1,5 @@ +MONGO_INITDB_ROOT_USERNAME= +MONGO_INITDB_ROOT_PASSWORD= +MONGO_USER= +MONGO_PASSWORD= +MONGO_INITDB_DATABASE= diff --git a/infra/mongo/init.js b/infra/mongo/init.js new file mode 100644 index 0000000..79c8291 --- /dev/null +++ b/infra/mongo/init.js @@ -0,0 +1,5 @@ +db.createUser({ + user: _getEnv('MONGO_USER'), + pwd: _getEnv('MONGO_PASSWORD'), + roles: ['readWrite', 'dbAdmin'], +}); diff --git a/infra/mongo/mongo.conf b/infra/mongo/mongo.conf new file mode 100644 index 0000000..e01d764 --- /dev/null +++ b/infra/mongo/mongo.conf @@ -0,0 +1,42 @@ +# mongod.conf + +# for documentation of all options, see: +# http://docs.mongodb.org/manual/reference/configuration-options/ + +# Where and how to store data. +# storage: +# dbPath: /var/lib/mongodb +# journal: +# enabled: true +# engine: +# wiredTiger: + +# where to write logging data. +systemLog: + destination: file + logAppend: true + path: /var/log/mongodb/mongod.log + +# network interfaces +net: + port: 27017 + bindIp: 0.0.0.0 + + +# how the process runs +processManagement: + timeZoneInfo: /usr/share/zoneinfo + +#security: + +#operationProfiling: + +#replication: + +#sharding: + +## Enterprise-Only Options: + +#auditLog: + +#snmp: diff --git a/package-lock.json b/package-lock.json index 65330b1..86021f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,10 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "@nestjs/common": "^10.2.10", "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.2.6", + "@nestjs/mongoose": "^10.0.2", "@nestjs/platform-express": "^10.2.6", "@nestjs/testing": "^10.2.6", "@types/jest": "^29.5.5", @@ -20,6 +22,7 @@ "express": "^4.18.2", "jest": "^29.7.0", "joi": "^17.10.2", + "mongoose": "^8.0.1", "ngrok": "^5.0.0-beta.2", "node-fetch": "^3.3.2", "rimraf": "^5.0.1", @@ -1202,11 +1205,18 @@ "node": ">=8" } }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.1.tgz", + "integrity": "sha512-t7c5K033joZZMspnHg/gWPE4kandgc2OxE74aYOtGKfgB9VPuVJPix0H6fhmm2erj5PBJ21mqcx34lpIGtUCsQ==", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, "node_modules/@nestjs/common": { - "version": "10.2.6", - "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.2.6.tgz", - "integrity": "sha512-ma8R7n+FXsWM4XF9QXjjrsRceyRzid/xKmNKVOa/sTJntkVG8lL71BHBEfjtFvO6EJUqjs/15LbDc0iaN5nCwA==", - "peer": true, + "version": "10.2.10", + "resolved": "https://registry.npmjs.org/@nestjs/common/-/common-10.2.10.tgz", + "integrity": "sha512-fwAk931rjW8CNH2Mgwawq/7HWHH1dxkOLdcgs7U52ddLk8CtHXjejm1cbNahewlSbNhvlOl7y1STLHutE6sUqw==", "dependencies": { "iterare": "1.2.1", "tslib": "2.6.2", @@ -1296,6 +1306,18 @@ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-3.2.0.tgz", "integrity": "sha512-jczvQbCUS7XmS7o+y1aEO9OBVFeZBQ1MDSEqmO7xSoPgOPoowY/SxLpZ6Vh97/8qHZOteiCKb7gkG9gA2ZUxJA==" }, + "node_modules/@nestjs/mongoose": { + "version": "10.0.2", + "resolved": "https://registry.npmjs.org/@nestjs/mongoose/-/mongoose-10.0.2.tgz", + "integrity": "sha512-ITHh075DynjPIaKeJh6WkarS21WXYslu4nrLkNPbWaCP6JfxVAOftaA2X5tPSiiE/gNJWgs+QFWsfCFZUUenow==", + "peerDependencies": { + "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0", + "@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0", + "mongoose": "^6.0.2 || ^7.0.0 || ^8.0.0", + "reflect-metadata": "^0.1.12", + "rxjs": "^7.0.0" + } + }, "node_modules/@nestjs/platform-express": { "version": "10.2.6", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.2.6.tgz", @@ -1754,6 +1776,20 @@ "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==" }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==" + }, + "node_modules/@types/whatwg-url": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", + "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", + "dependencies": { + "@types/node": "*", + "@types/webidl-conversions": "*" + } + }, "node_modules/@types/ws": { "version": "8.5.5", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.5.tgz", @@ -2106,6 +2142,14 @@ "node-int64": "^0.4.0" } }, + "node_modules/bson": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.2.0.tgz", + "integrity": "sha512-ID1cI+7bazPDyL9wYy9GaQ8gEEohWvcUl/Yf0dIdutJxnmInEEyCsb4awy/OiBfall7zBA179Pahi3vCdFze3Q==", + "engines": { + "node": ">=16.20.1" + } + }, "node_modules/buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -4225,6 +4269,14 @@ "node": ">=6" } }, + "node_modules/kareem": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.5.1.tgz", + "integrity": "sha512-7jFxRVm+jD+rkq3kY0iZDJfsO2/t4BBPeEb2qKn2lR/9KhuksYk5hxzfRYWMPV8P/x2d0kHD306YyWLzjjH+uA==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/keyv": { "version": "4.5.3", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.3.tgz", @@ -4371,6 +4423,11 @@ "node": ">= 0.6" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==" + }, "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -4488,6 +4545,136 @@ "mkdirp": "bin/cmd.js" } }, + "node_modules/mongodb": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.2.0.tgz", + "integrity": "sha512-d7OSuGjGWDZ5usZPqfvb36laQ9CPhnWkAGHT61x5P95p/8nMVeH8asloMwW6GcYFeB0Vj4CB/1wOTDG2RA9BFA==", + "dependencies": { + "@mongodb-js/saslprep": "^1.1.0", + "bson": "^6.2.0", + "mongodb-connection-string-url": "^2.6.0" + }, + "engines": { + "node": ">=16.20.1" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", + "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", + "dependencies": { + "@types/whatwg-url": "^8.2.1", + "whatwg-url": "^11.0.0" + } + }, + "node_modules/mongodb-connection-string-url/node_modules/tr46": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", + "dependencies": { + "punycode": "^2.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/mongodb-connection-string-url/node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/mongodb-connection-string-url/node_modules/whatwg-url": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", + "dependencies": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/mongoose": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.0.1.tgz", + "integrity": "sha512-O3TJrtLCt4H1eGf2HoHGcnOcCTWloQkpmIP3hA9olybX3OX2KUjdIIq135HD5paGjZEDJYKn9fw4eH5N477zqQ==", + "dependencies": { + "bson": "^6.2.0", + "kareem": "2.5.1", + "mongodb": "6.2.0", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "16.0.1" + }, + "engines": { + "node": ">=16.20.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mongoose/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -4915,6 +5102,14 @@ "once": "^1.3.1" } }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "engines": { + "node": ">=6" + } + }, "node_modules/pure-rand": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-6.0.3.tgz", @@ -5224,6 +5419,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sift": { + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/sift/-/sift-16.0.1.tgz", + "integrity": "sha512-Wv6BjQ5zbhW7VFefWusVP33T/EM0vYikCaQ2qR8yULbsilAT8/wQaXvuQ3ptGLpoKx+lihJE3y2UTgKDyyNHZQ==" + }, "node_modules/signal-exit": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", @@ -5265,6 +5465,14 @@ "source-map": "^0.6.0" } }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", diff --git a/package.json b/package.json index 7cd2fa0..502aaa0 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,10 @@ }, "homepage": "https://github.com/Blvckleg/BingusBoingus/#readme", "dependencies": { + "@nestjs/common": "^10.2.10", "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.2.6", + "@nestjs/mongoose": "^10.0.2", "@nestjs/platform-express": "^10.2.6", "@nestjs/testing": "^10.2.6", "@types/jest": "^29.5.5", @@ -38,6 +40,7 @@ "express": "^4.18.2", "jest": "^29.7.0", "joi": "^17.10.2", + "mongoose": "^8.0.1", "ngrok": "^5.0.0-beta.2", "node-fetch": "^3.3.2", "rimraf": "^5.0.1", diff --git a/src/app.module.ts b/src/app.module.ts index 39d6c44..a206cd3 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,6 +4,7 @@ import { DiscordModule } from './modules/discord/discord.module'; import { CommandModule } from './modules/command/command.module'; import { EventModule } from './modules/event/event.module'; import { DeployModule } from './deployment/deploy.module'; +import { MongoDatabaseProviderModule } from './config/database/mongo/provider/mongo-provider.module'; @Module({ imports: [ @@ -12,6 +13,7 @@ import { DeployModule } from './deployment/deploy.module'; CommandModule, DeployModule, EventModule, + MongoDatabaseProviderModule, ], }) export class AppModule {} diff --git a/src/config/config.service.ts b/src/config/config.service.ts index 220bc13..dd1f622 100644 --- a/src/config/config.service.ts +++ b/src/config/config.service.ts @@ -9,7 +9,7 @@ import { ConfigService } from '@nestjs/config'; export class AppConfigService { constructor(private configService: ConfigService) {} - get port(): number { + get appPort(): number { return Number(this.configService.get('app.port')); } get botToken(): string { diff --git a/src/config/database/mongo/config/config.module.ts b/src/config/database/mongo/config/config.module.ts new file mode 100644 index 0000000..d529dca --- /dev/null +++ b/src/config/database/mongo/config/config.module.ts @@ -0,0 +1,32 @@ +import * as Joi from 'joi'; +import { Module } from '@nestjs/common'; +import configuration from './configuration'; +import { MongoConfigService } from './config.service'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +/** + * Import and provide app configuration related classes. + * + * @module + */ +const ENV = process.env.NODE_ENV; +@Module({ + imports: [ + ConfigModule.forRoot({ + load: [configuration], + envFilePath: !ENV ? '.env' : `.env.${ENV}`, + validationSchema: Joi.object({ + MONGO_URI: Joi.string().default('localhost'), + MONGO_PORT: Joi.number().default(27017), + MONGO_USERNAME: Joi.string(), + MONGO_PASSWORD: Joi.string(), + MONGO_DATABASE: Joi.string().default('bingus'), + MONGO_RUN_MIGRATION: Joi.boolean().default(false), + MONGO_ENTITIES: Joi.string().default('dist/**/*.entity.*{ts,js}'), + MONGO_RUN_SYNCHRONIZE: Joi.boolean().default(false), + }), + }), + ], + providers: [ConfigService, MongoConfigService], + exports: [ConfigService, MongoConfigService], +}) +export class MongoConfigModule {} diff --git a/src/config/database/mongo/config/config.service.ts b/src/config/database/mongo/config/config.service.ts new file mode 100644 index 0000000..d4b8ae7 --- /dev/null +++ b/src/config/database/mongo/config/config.service.ts @@ -0,0 +1,50 @@ +import { Injectable } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { + MongooseOptionsFactory, + MongooseModuleOptions, +} from '@nestjs/mongoose'; +/** + * Service dealing with app config based operations. + * + * @class + */ +@Injectable() +export class MongoConfigService implements MongooseOptionsFactory { + constructor(private configService: ConfigService) {} + + createMongooseOptions(): MongooseModuleOptions { + if (this.username && this.password) { + return { + uri: `mongodb://${this.username}:${this.password}@${this.uri}`, + }; + } else { + return { uri: this.uri }; + } + } + + get uri(): string { + return this.configService.get('mongo.uri'); + } + get port(): number { + return Number(this.configService.get('mongo.port')); + } + get username(): string { + return this.configService.get('mongo.username'); + } + get password(): string { + return this.configService.get('mongo.password'); + } + get database(): string { + return this.configService.get('mongo.database'); + } + get migrationsRun(): boolean { + return JSON.parse(this.configService.get('mongo.migrationsRun')); + } + get synchronizeRun(): boolean { + return JSON.parse(this.configService.get('mongo.synchronizeRun')); + } + get entities(): string { + return this.configService.get('mongo.entities'); + } +} diff --git a/src/config/database/mongo/config/configuration.ts b/src/config/database/mongo/config/configuration.ts new file mode 100644 index 0000000..fd56378 --- /dev/null +++ b/src/config/database/mongo/config/configuration.ts @@ -0,0 +1,12 @@ +import { registerAs } from '@nestjs/config'; + +export default registerAs('mongo', () => ({ + uri: process.env.MONGO_URI, + port: process.env.MONGO_PORT, + username: process.env.MONGO_USERNAME, + password: process.env.MONGO_PASSWORD, + database: process.env.MONGO_DATABASE, + migrationsRun: process.env.MONGO_RUN_MIGRATION, + synchronizeRun: process.env.MONGO_RUN_SYNCHRONIZE, + entities: process.env.MONGO_ENTITIES, +})); diff --git a/src/config/database/mongo/provider/mongo-provider.module.ts b/src/config/database/mongo/provider/mongo-provider.module.ts new file mode 100644 index 0000000..4710d53 --- /dev/null +++ b/src/config/database/mongo/provider/mongo-provider.module.ts @@ -0,0 +1,14 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule, MongooseModuleAsyncOptions } from '@nestjs/mongoose'; +import { MongoConfigModule } from '../config/config.module'; +import { MongoConfigService } from '../config/config.service'; + +@Module({ + imports: [ + MongooseModule.forRootAsync({ + imports: [MongoConfigModule], + useExisting: MongoConfigService, + } as MongooseModuleAsyncOptions), + ], +}) +export class MongoDatabaseProviderModule {} diff --git a/src/main.ts b/src/main.ts index adb44a4..1d2b9a6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,7 +17,7 @@ async function bootstrap() { await app.startAllMicroservices(); - await app.listen(appConfig.port); + await app.listen(appConfig.appPort); } bootstrap(); diff --git a/src/modules/command/command.abstract.ts b/src/modules/command/command.abstract.ts index eb10ff5..4782301 100644 --- a/src/modules/command/command.abstract.ts +++ b/src/modules/command/command.abstract.ts @@ -1,9 +1,18 @@ -import { CacheType, Interaction, SlashCommandBuilder } from 'discord.js'; +import { + CacheType, + CommandInteraction, + Interaction, + SlashCommandBuilder, +} from 'discord.js'; export abstract class ACommand { - data: SlashCommandBuilder; + data: + | SlashCommandBuilder + | Omit; - public abstract execute(arg: Interaction): Promise; + public abstract execute( + arg: Interaction | CommandInteraction, + ): Promise; protected async run(command: () => any): Promise { try { diff --git a/src/modules/command/command.module.ts b/src/modules/command/command.module.ts index d64d32d..8866f6a 100644 --- a/src/modules/command/command.module.ts +++ b/src/modules/command/command.module.ts @@ -7,6 +7,9 @@ import { ReportedCommand } from './commands/reported'; import { BugReport } from './commands/bug'; import { CoinflipCommand } from './commands/coinflip'; import { GoldCommand } from './commands/gold'; +import SomeoneOnceSaidCommand from './commands/someone-once-said'; +import { SomeoneOnceSaidModule } from '../someone-once-said/modules/someone-once-said.module'; +import GetRandomQuote from './commands/get-a-quote'; @Module({ providers: [ @@ -18,7 +21,10 @@ import { GoldCommand } from './commands/gold'; BugReport, CoinflipCommand, GoldCommand, + SomeoneOnceSaidCommand, + GetRandomQuote, ], + imports: [SomeoneOnceSaidModule], exports: [CommandService], }) export class CommandModule {} diff --git a/src/modules/command/command.service.ts b/src/modules/command/command.service.ts index 97f22c6..c8c7eeb 100644 --- a/src/modules/command/command.service.ts +++ b/src/modules/command/command.service.ts @@ -1,13 +1,13 @@ import { Injectable } from '@nestjs/common'; import { Collection } from 'discord.js'; -import { PingPongCommand } from './commands/pingpong'; import { CBDCommand } from './commands/cbd'; -import { HelloCommand } from './commands/hello'; import { ACommand } from './command.abstract'; import { ReportedCommand } from './commands/reported'; import { BugReport } from './commands/bug'; import { CoinflipCommand } from './commands/coinflip'; import { GoldCommand } from './commands/gold'; +import SomeoneOnceSaidCommand from './commands/someone-once-said'; +import GetRandomQuote from './commands/get-a-quote'; @Injectable() export class CommandService { @@ -21,6 +21,8 @@ export class CommandService { bugReportModule: BugReport, coinflipModule: CoinflipCommand, goldModule: GoldCommand, + someoneOnceSaidModule: SomeoneOnceSaidCommand, + getRandomQuoteModule: GetRandomQuote, ) { const commands: ACommand[] = [ //pingpongModule, @@ -30,6 +32,8 @@ export class CommandService { bugReportModule, coinflipModule, goldModule, + someoneOnceSaidModule, + getRandomQuoteModule, ]; commands.forEach((command) => { if (command.data.name && command.execute) { diff --git a/src/modules/command/commands/get-a-quote.ts b/src/modules/command/commands/get-a-quote.ts new file mode 100644 index 0000000..d94614d --- /dev/null +++ b/src/modules/command/commands/get-a-quote.ts @@ -0,0 +1,36 @@ +import { + CacheType, + CommandInteraction, + EmbedBuilder, + SlashCommandBuilder, +} from 'discord.js'; +import { ACommand } from '../command.abstract'; +import { SomeoneOnceSaidService } from '../../someone-once-said/services/someone-once-said.service'; +import { Inject } from '@nestjs/common'; + +export default class GetRandomQuote extends ACommand { + constructor( + @Inject(SomeoneOnceSaidService) + private readonly someoneonceSaidService: SomeoneOnceSaidService, + ) { + super(); + } + data = new SlashCommandBuilder() + .setName('randomquote') + .setDescription('get a random quote of a user'); + + async execute(arg: CommandInteraction): Promise { + const someoneOnceSaid = await this.someoneonceSaidService.getRandomQuote(); + if (!someoneOnceSaid) return; + const quoteEmbed = new EmbedBuilder() + .setTitle( + `${someoneOnceSaid.secName ?? someoneOnceSaid.username} once said 🤓`, + ) + .setDescription(someoneOnceSaid.phrase) + .setFooter({ + text: someoneOnceSaid?.secName ?? someoneOnceSaid.username, + }) + .setTimestamp(someoneOnceSaid.createdAt); + arg.reply({ embeds: [quoteEmbed] }); + } +} diff --git a/src/modules/command/commands/someone-once-said.ts b/src/modules/command/commands/someone-once-said.ts new file mode 100644 index 0000000..d753cd8 --- /dev/null +++ b/src/modules/command/commands/someone-once-said.ts @@ -0,0 +1,54 @@ +import { + CacheType, + CommandInteraction, + EmbedBuilder, + SlashCommandBuilder, +} from 'discord.js'; +import { ACommand } from '../command.abstract'; +import { SomeoneOnceSaidService } from '../../someone-once-said/services/someone-once-said.service'; +import { Inject } from '@nestjs/common'; +import { SomeoneOnceSaid } from '../../../schemas/someone-once-said.schema'; + +export default class SomeoneOnceSaidCommand extends ACommand { + constructor( + @Inject(SomeoneOnceSaidService) + private readonly someoneonceSaidService: SomeoneOnceSaidService, + ) { + super(); + } + data = new SlashCommandBuilder() + .setName('quote') + .setDescription('Make it a quote') + .addStringOption((option) => + option.setName('phrase').setDescription('What was said'), + ); + + async execute(arg: CommandInteraction): Promise { + let phrase = arg.options.get('phrase'); + if (!phrase) { + await arg.reply({ + content: 'ok but what did he say 4head ?XP', + ephemeral: true, + }); + return; + } + let phraseValue = (phrase.value as unknown as string).replaceAll( + '\\n', + '\n', + ); + const instance = new SomeoneOnceSaid({ + phrase: phraseValue, + username: arg.user.username, + secName: arg.user.displayName, + }); + const created = await this.someoneonceSaidService.create(instance); + const quoteEmbed = new EmbedBuilder() + .setTitle('Someone once said 🤓') + .setDescription(created.phrase) + .setFooter({ + text: created?.secName ?? created.username, + }) + .setTimestamp(created.createdAt); + arg.channel.send({ embeds: [quoteEmbed] }); + } +} diff --git a/src/modules/someone-once-said/modules/someone-once-said.module.ts b/src/modules/someone-once-said/modules/someone-once-said.module.ts new file mode 100644 index 0000000..a11a9b9 --- /dev/null +++ b/src/modules/someone-once-said/modules/someone-once-said.module.ts @@ -0,0 +1,22 @@ +import { Module } from '@nestjs/common'; +import { MongooseModule } from '@nestjs/mongoose'; +import { SomeoneOnceSaidService } from '../services/someone-once-said.service'; +import { + SomeoneOnceSaid, + SomeoneOnceSaidSchema, +} from '../../../schemas/someone-once-said.schema'; + +@Module({ + imports: [ + MongooseModule.forFeature([ + { + name: SomeoneOnceSaid.name, + schema: SomeoneOnceSaidSchema, + }, + ]), + ], + controllers: [], + providers: [SomeoneOnceSaidService], + exports: [SomeoneOnceSaidService], +}) +export class SomeoneOnceSaidModule {} diff --git a/src/modules/someone-once-said/services/someone-once-said.service.ts b/src/modules/someone-once-said/services/someone-once-said.service.ts new file mode 100644 index 0000000..2a6101b --- /dev/null +++ b/src/modules/someone-once-said/services/someone-once-said.service.ts @@ -0,0 +1,53 @@ +import { InjectModel } from '@nestjs/mongoose'; +import { Model, Error } from 'mongoose'; +import { SomeoneOnceSaidEntity } from '../../../schemas/someone-once-said-entity.model'; +import { SomeoneOnceSaidDocument } from '../../../schemas/someone-once-said.schema'; + +export class SomeoneOnceSaidService { + constructor( + @InjectModel('SomeoneOnceSaid') + private readonly someoneOnceSaid: Model, + ) {} + + async create( + quoteDto: SomeoneOnceSaidEntity, + ): Promise { + try { + return await this.someoneOnceSaid.create({ + phrase: quoteDto.phrase, + username: quoteDto.username, + secName: quoteDto?.secName, + createdAt: new Date(), + }); + } catch (e) { + return null; + } + } + + async deleteProductionOrderForUser(username: string) { + try { + await this.someoneOnceSaid.deleteMany({ username: username }); + } catch (e) { + return new Error('Error deleting Quotes for username: ' + username); + } + return; + } + + async getRandomQuote(): Promise { + try { + const count = await this.someoneOnceSaid.countDocuments(); + + const randomIndex = Math.floor(Math.random() * count); + + const randomQuote = await this.someoneOnceSaid + .findOne() + .skip(randomIndex) + .limit(1); + + return randomQuote; + } catch (error) { + console.error('Error fetching random quote:', error); + return null; + } + } +} diff --git a/src/schemas/auto-response.schema.ts b/src/schemas/auto-response.schema.ts new file mode 100644 index 0000000..e86c615 --- /dev/null +++ b/src/schemas/auto-response.schema.ts @@ -0,0 +1,50 @@ +import { Schema, model, Model, Document } from 'mongoose'; +import { ResponseType } from './command.schema'; + +export interface AutoResponseDocument extends Document { + regex: RegExp; + response: string; + responseType?: ResponseType; +} + +const regexValidator = { + validator: (value: any) => { + try { + // Attempt to create a RegExp object from the provided value + new RegExp(value); + return true; + } catch (error) { + return false; + } + }, + message: 'Invalid regular expression format', +}; + +export const AutoResponseSchema: Schema = new Schema( + { + regex: { + type: Schema.Types.Mixed, + required: true, + unique: true, + validate: regexValidator, + }, + response: { + type: String, + required: true, + }, + responseType: { + type: String, + enum: Object.values(ResponseType), + default: ResponseType.reply, + }, + }, + { + timestamps: true, + strict: false, + }, +); + +export const AutoResponseModel: Model = model< + AutoResponseDocument, + Model +>('AutoResponse', AutoResponseSchema); diff --git a/src/schemas/command.schema.ts b/src/schemas/command.schema.ts new file mode 100644 index 0000000..3cbbb50 --- /dev/null +++ b/src/schemas/command.schema.ts @@ -0,0 +1,41 @@ +import { Schema, model, Model, Document } from 'mongoose'; + +export interface CommandDocument extends Document { + commandName: string; + response: string; + responseType?: ResponseType; +} + +export enum ResponseType { + reply = 'replyToMessage', + channel = 'replyToChannel', + dm = 'replyInDirectMessage', +} + +export const CommandSchema: Schema = new Schema( + { + commandName: { + type: String, + required: true, + unique: true, + }, + response: { + type: String, + required: true, + }, + responseType: { + type: String, + enum: Object.values(ResponseType), + default: ResponseType.reply, + }, + }, + { + timestamps: true, + strict: false, + }, +); + +export const CommandModel: Model = model< + CommandDocument, + Model +>('Command', CommandSchema); diff --git a/src/schemas/someone-once-said-entity.model.ts b/src/schemas/someone-once-said-entity.model.ts new file mode 100644 index 0000000..0eb6d1a --- /dev/null +++ b/src/schemas/someone-once-said-entity.model.ts @@ -0,0 +1,6 @@ +export class SomeoneOnceSaidEntity { + phrase: string; + username: string; + secName?: string; + createdAt: Date; +} diff --git a/src/schemas/someone-once-said.schema.ts b/src/schemas/someone-once-said.schema.ts new file mode 100644 index 0000000..1392e66 --- /dev/null +++ b/src/schemas/someone-once-said.schema.ts @@ -0,0 +1,25 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; + +@Schema() +export class SomeoneOnceSaid { + @Prop({ required: true }) + phrase: string; + + @Prop({ required: true }) + username: string; + + @Prop({ required: false }) + secName: string; + + @Prop({ required: true }) + createdAt: Date; + + constructor(data) { + Object.assign(this, data); + } +} + +export type SomeoneOnceSaidDocument = SomeoneOnceSaid & Document; + +export const SomeoneOnceSaidSchema = + SchemaFactory.createForClass(SomeoneOnceSaid);