Skip to content

Commit

Permalink
Database migration script and update README to add documentation on t…
Browse files Browse the repository at this point in the history
…he auth.json file and database setup.
  • Loading branch information
jeremy-rifkin committed Aug 5, 2023
1 parent 560a9cd commit beac566
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 10 deletions.
74 changes: 67 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,72 @@
[![test](https://github.com/jeremy-rifkin/wheatley/actions/workflows/test.yml/badge.svg)](https://github.com/jeremy-rifkin/wheatley/actions/workflows/test.yml)
[![eslint](https://github.com/jeremy-rifkin/wheatley/actions/workflows/eslint.yml/badge.svg)](https://github.com/jeremy-rifkin/wheatley/actions/workflows/eslint.yml)

This repository contains the source code for the Wheatley bot, made for the Together C & C++ discord
server.
This repository contains the source code for the Wheatley bot, made for the Together C & C++ discord server.

This bot is primary internal moderation and administrative tools, such as tracking server
suggestions and addressing bot raids and scammers. Scams and bot raids usually are not targeted, but
the exact techniques and heuristics used to identify raids are, at least for now, omitted from the
public mirror for this repository. The mirror pulls new changes daily.
## Code organization

Copyright 2021-2022, all rights reserved.
- `indexes/` Code for processing cppreference and man7 data to create a searchable index
- `src/` Main source code for the bot
- `algorithm/` Algorithmic utilities for the bot, such as levenshtein distance
- `components/` Bot components
- `infra/` Bot infrastructure, such as database interaction
- `test/` Test cases
- `wheatley-private/` Private components, these are primarily internal moderation and administration tools such as
raid detection and handling.

The bot is very modular and most components are completely independent of other components.

## auth.json

Secrets and other bot info must be configured in the bot.json file. An example looks like:

```json
{
"id": "<bot id>",
"guild": "<guild id>",
"token": "<discord api token>",
"mongouser": "wheatley",
"mongopassword": "<mongo password>"
}
```

Mongo credentials can be omitted locally if you don't need to work on components that use mongo. `freestanding: true`
can be specified to turn on only components which don't rely on channels etc. specific to Together C & C++ to exist.

## Database

The bot uses MongoDB. It previously used a giant json file (the migration script is located in the scripts folder).
For local development you likely won't need to setup a mongo database, depending on the components you're working on.
However, if you are contributing to components that do need the database here are the installation steps for ubuntu:

https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/

```sh
sudo apt-get install gnupg curl
curl -fsSL https://pgp.mongodb.com/server-6.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
sudo ufw deny 27017
mongosh
# use admin
# db.createUser({user:'mongoadmin', pwd: '<password>', roles:['userAdminAnyDatabase']})
# db.auth('mongoadmin', '<password>') # test that authentication works
# db.createUser({user:'wheatley', pwd: '<password>', roles:[{db:'wheatley', role:'readWrite'}]})
# use wheatley
sudo vim /etc/mongod.conf
# net:
# port: 27017
# bindIp: 127.0.0.1
# security:
# authorization: enabled
sudo systemctl restart mongod
```

To connect with [compass](https://www.mongodb.com/try/download/compass) to a mongo server setup on another server:
`ssh -L 27017:127.0.0.1:27017 <server> -N`.
Loading

0 comments on commit beac566

Please sign in to comment.