Skip to content

Commit

Permalink
Merge branch 'bso' of https://github.com/nwjgit/oldschoolbot into com…
Browse files Browse the repository at this point in the history
…pCapeSimItems
  • Loading branch information
nwjgit committed Aug 22, 2024
2 parents e22ab3d + af16585 commit 043dfc2
Show file tree
Hide file tree
Showing 974 changed files with 21,602 additions and 19,028 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.env
icon_cache
logs
dist
node_modules
coverage
.yarn
.tests
20 changes: 13 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# You need to change these:
CLIENT_ID=PUT_YOUR_CLIENT_ID_HERE
BOT_TOKEN=PUT_YOUR_TOKEN_HERE

# You may need to change these:
ROBOCHIMP_DATABASE_URL=postgresql://postgres:postgres@localhost:5436/robochimp_test
DATABASE_URL=postgresql://postgres:postgres@localhost:5435/osb_test

# Optional
#REDIS_PORT=6379
#TESTING_SERVER_ID=123456789012345678

# Dont change these:
TZ="UTC"
ROBOCHIMP_DATABASE_URL=postgresql://postgres:postgres@localhost:5436/robochimp_integration_test
DATABASE_URL=postgresql://postgres:postgres@localhost:5435/osb_integration_test?connection_limit=20&pool_timeout=120
PATREON_CAMPAIGN_ID=1234
PATREON_TOKEN=asdfasdfasdf
PATREON_WEBHOOK_SECRET=asdfasdfasdf
HTTP_PORT=7373
CLIENT_ID=111398433321891634
11 changes: 4 additions & 7 deletions .env.test
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
TZ="UTC"
ROBOCHIMP_DATABASE_URL=postgresql://postgres:postgres@localhost:5436/robochimp_integration_test?connection_limit=1000
DATABASE_URL=postgresql://postgres:postgres@localhost:5435/osb_integration_test?pool_timeout=120&connection_limit=1000
PATREON_CAMPAIGN_ID=1234
PATREON_TOKEN=asdfasdfasdf
PATREON_WEBHOOK_SECRET=asdfasdfasdf
HTTP_PORT=7373
CLIENT_ID=111398433321891634
# PRISMA_CLIENT_ENGINE_TYPE=binary
BOT_TOKEN=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
TEST=true
CI=true
YARN_ENABLE_HARDENED_MODE=0
7 changes: 0 additions & 7 deletions .eslintignore

This file was deleted.

22 changes: 0 additions & 22 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BSO:
- base-branch: "bso"
39 changes: 8 additions & 31 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,15 @@ on:

jobs:
test:
name: Node v${{ matrix.node_version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
node_version: [18.12.0, 20]
os: [ubuntu-latest]

steps:
- name: Install System Packages
run: sudo apt-get install -y build-essential libpq-dev

- name: Checkout Project
uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
cache: yarn
- name: Restore CI Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles(matrix.os == 'windows-latest' && '**\yarn.lock' || '**/yarn.lock') }}
- name: Install Dependencies
run: yarn --frozen-lockfile
- name: Copy Configuration
run: |
pushd src &&
cp config.example.ts config.ts &&
popd
- name: Copy env
run: cp .env.test .env
- name: Test
run: yarn test:integration
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Run Integration Tests
run: docker compose up --build --abort-on-container-exit --remove-orphans && docker compose down --volumes --remove-orphans
15 changes: 15 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Pull Request Labeler"
on:
pull_request_target:
types: [opened, synchronize, reopened]

jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
34 changes: 12 additions & 22 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,36 @@ jobs:
test:
name: Node v${{ matrix.node_version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
timeout-minutes: 5
strategy:
matrix:
node_version: [18.12.0, 20]
node_version: [20.15.0]
os: [ubuntu-latest]

steps:
- name: Checkout Project
uses: actions/checkout@v3
uses: actions/checkout@v4
- run: corepack enable && corepack install
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
cache: yarn
- name: Restore CI Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles(matrix.os == 'windows-latest' && '**\yarn.lock' || '**/yarn.lock') }}
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies
run: yarn --frozen-lockfile
run: yarn --immutable
- name: Copy Configuration
run: |
pushd src &&
cp config.example.ts config.ts &&
popd
- name: Copy env
run: cp .env.test .env
- name: Generate Prisma Client
popd && cp .env.test .env
- name: Generate Prisma Clients
run: yarn gen
- name: Run ESLint on changed files
uses: tj-actions/eslint-changed-files@v21
with:
skip_annotations: true
config_path: ".eslintrc.json"
ignore_path: ".eslintignore"
file_extensions: |
**/*.ts
**/*.tsx
- name: Build
run: yarn build
run: yarn build:tsc
- name: Test
run: yarn test:unit
run: yarn test:ci:unit
17 changes: 15 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Klasa
*.log
bot/bwd/provider/json/
src/bwd/provider/json/
/config/private.js
/config/private.json
private.json
Expand Down Expand Up @@ -32,3 +30,18 @@ node_modules/
.eslintcache

/coverage
*.cpuprofile

cache.json

tests/**/*.tsbuildinfo

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
overallItemsNotCheckedFor.txt
*.diff
6 changes: 5 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
dist
dist
coverage
node_modules
logs
licenses
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nodeLinker: node-modules
telemetryInterval: 999999999999
enableTelemetry: false
checksumBehavior: "update"
enableHardenedMode: false
58 changes: 14 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,9 @@ To suggest a new feature, [click here](https://github.com/oldschoolgg/oldschoolb

## Contributing

Anyone is free to create PR's with improvements and additions to Old School Bot.

Please lint your code with the projects' [ESLint](https://eslint.org/) config.

Contributors are listed in this file, and given a Contributor role in the support server. If you have more questions, there are lots of helpful Contributors in the `#developers` channel on the Discord server.

### Setting up the bot to run locally for contributing

To run the bot, you need the following things first: Git, [NodeJS v18+](https://nodejs.org/en/), [Postgres](https://www.postgresql.org/download/), [Python](https://www.python.org/) and a discord bot account.

#### **Setting up a Discord Bot**

1. Head to [Discord Developers](https://discord.com/developers) and create an application.
2. Once created, click into your Application.
3. Copy and store the Application ID, you'll need this later on.
4. Create a Bot on the Bot tab. Copy and store the token for your bot, you'll need this later on.
5. Ensure your bot has `Privileged Gateway Intents > Server Members Intent` enabled.
6. Invite your bot to your server via this URL. Be sure to input your `Application ID` into the URL. `https://discord.com/api/oauth2/authorize?client_id=<INSERT APPLICATION ID HERE>&permissions=2198754295617&scope=applications.commands%20bot`

#### **Setting up your environment**

1. Clone the repository: `git clone https://github.com/oldschoolgg/oldschoolbot.git`
2. Change into the new directory: `cd oldschoolbot`
3. Install the yarn dependency: `npm install --global yarn`
4. Make a config file from the example: `cp src/config.example.ts src/config.ts`
5. Edit this new `config.ts` file:
1. Input your bot token you retrieved earlier into `botToken`
2. Input your Application ID you retrieved earlier into `BotID`
3. Copy your Discord ID into both `OWNER_IDS` and `ADMIN_IDS`. You can get your Discord ID by opening Settings, selecting My Account, selecting the three dots next to your user name and selecting Copy ID. You may need to enable Developer Mode in Advanced Settings to be given this option.
4. Enter the Server ID where you want to Administer your bot from in `SupportServer`. You can get this by right clicking the logo of the server and selecting Copy ID.
5. Enter the Server ID into `DEV_SERVER_ID`
6. Make a .env file copy from the example `cp .env.example .env`
7. Update this new `.env` file:
1. Input your username, password, and schema names into `DATABASE_URL` and `ROBOCHIMP_DATABASE_URL` using the format `postgresql://USER:PASSWORD@HOST:PORT/DATABASE`
2. Input your Application ID you retrieved earlier into `CLIENT_ID`
8. Run `yarn` then `yarn install`
9. Run `npx prisma generate` to generate the Prisma client files and load the DSN from #6.
10. Run `npx prisma db push` to create the tables on the database referenced in .env
11. Run `npx prisma generate --schema=./prisma/robochimp.prisma` to generate the Prisma client files and load the DSN from #6 for the `robochimp` database.
12. Run `npx prisma db push --schema=./prisma/robochimp.prisma` to create the tables on the database referenced in .env for the `robochimp` database.
13. Run `yarn build` - then run `yarn start`. In the future, you can type only `yarn start` to start the bot.

If you have errors or issues, you can ask us for help in the #developer channel in the [discord server](https://discord.gg/ob).
Anyone is free to create PR's with improvements and additions to Old School Bot. If you have questions, ask in the `#developers` channel on our Discord server.

[Read this file for help setting up a bot](SETUP.md)

#### **Shared Testing Server**

Expand All @@ -90,6 +50,16 @@ You can also ask Magna to invite your Bot with your invite link above if you so
- [[Andre](https://github.com/ard35)]
- [[TastyPumPum](https://github.com/TastyPumPum)]

## Self Hosting
### Self Hosting

Self hosting is not supported.

## Notes

### Profiling tests

- node --cpu-prof --cpu-prof-dir=./profiling ./node_modules/vitest/vitest.mjs run --coverage --config vitest.unit.config.mts parseStringBank

## Module graph

- yarn build && npx madge --image graph2.svg ./dist/index.js
57 changes: 57 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Setting up for contributing/running the bot

This assumes you are using VSCode as your IDE. If you have errors or issues, you can ask us for help in the #developer channel in the [discord server](https://discord.gg/ob).

## **Setup**

### Discord Bot Account

1. Create a discord bot account, and have the application ID and bot token saved.
2. Ensure your bot has `Privileged Gateway Intents > Server Members Intent` enabled.

### Environment

1. Install [NvM](https://github.com/coreybutler/nvm-windows/), then use it to install NodeJS v20.15.0 OR install the nodejs version directly.
2. Install [Postgres 16](https://www.postgresql.org/download/) and PGAdmin4 for interacting with postgres (optional, but helpful)
3. Install Yarn using: `npm i -g yarn`
4. Clone the repo: `git clone https://github.com/oldschoolgg/oldschoolbot.git`
5. Run the following commands in the root of the repo: `corepack enable`, `yarn`, `npx prisma db push` and `npx prisma db push --schema ./prisma/robochimp.prisma`

### Configuration

1. Copy the ".env.example" file and rename the copy to ".env", put your bot token and bot id (client id) in it.
2. Create 2 databases called "osb_test" and "robochimp_test"
3. Change `DATABASE_URL` and `ROBOCHIMP_DATABASE_URL` in your .env with the format `postgresql://USER:PASSWORD@HOST:PORT/DATABASE_NAME`.
4. Make a config file from the example: `cp src/config.example.ts src/config.ts`
5. Edit this new `config.ts` file:
- Copy your Discord ID into both `OWNER_IDS` and `ADMIN_IDS`.
- Enter the Server ID where you want to Administer your bot from in `SupportServer`
- Enter the Server ID into `DEV_SERVER_ID`

### Running the bot

1. Run `yarn start`

#### VSCode settings (Optional)

1. In VSCode, press CTRL+SHIFT+P, search "Open User Settings JSON"
2. Add this to the file:

```json
// Format/fix code automatically
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.codeActionsOnSave": {
"quickfix.biome": "explicit",
},
// Disable telemetry
"telemetry.telemetryLevel": "off",
// Always use \n for EOF
"files.eol": "\n",
```

# Troubleshooting

- Check your NodeJS/NPM/Yarn/Postgres versions.
- Uninstall prettier/eslint vscode plugins.
- Delete these folders: node_modules, dist
Loading

0 comments on commit 043dfc2

Please sign in to comment.