Skip to content

Commit 03caf98

Browse files
authored
Merge pull request #55 from Mimickal/v2-docs
2 parents 8a8300a + 59b437f commit 03caf98

6 files changed

Lines changed: 115 additions & 55 deletions

File tree

README.md

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -132,59 +132,10 @@ up react roles for `@everyone` like you would for any other role. It's silly, it
132132
won't do anything, but you *could* do it...
133133

134134
## Hosting your own instance
135-
This bot is built on [discord.js](https://discord.js.org/#/) v13, so you'll need
136-
Node.js 16.6.0 (or newer) installed. You will also need your own Discord bot
137-
account.
138-
139-
If you're upgrading from an older Discord.js v12 version of the bot, the Node.js
140-
16.6.0 requirement might be problematic. you might consider using something like
141-
https://github.com/nvm-sh/nvm to make the transition easier.
142-
143-
The `resources` directory has a service file that can be used with Linux distros
144-
with systemd. If you're installing this on some other operating system, you're
145-
on your own.
146-
147-
### Running as a service
148-
The provided service file expects to find the bot code at
149-
`/srv/discord/ReactionRoleBot/`, and will want to create the sqlite database at
150-
`/srv/discord/rolebot.sqlite`. The easiest way to do this is to create a
151-
`/srv/discord` directory, and `chown` it so it belongs to the user running the
152-
bot.
153-
154-
The following will prepare the bot to run. Run this from `/srv/discord`:
155-
```
156-
git clone https://github.com/Mimickal/ReactionRoleBot.git
157-
cd ReactionRoleBot
158-
npm install
159-
NODE_ENV=prod npm run knex migrate:latest
160-
```
161-
162-
Create a file `/etc/discord/ReactionRoleBot/config.json` and paste in the
163-
following (obviously fill in the blanks with your bot's info):
164-
```json
165-
{
166-
"token": "<your token here>",
167-
"app_id": "<your bot application ID here>"
168-
}
169-
```
170-
171-
Install `reactionrolebot.service` into `/etc/systemd/system/`.
172-
173-
Now you should be able to run `systemctl restart reactionrolebot.service` to
174-
start your bot.
175-
176-
### Running locally (in dev-mode)
177-
Run this wherever you want:
178-
```
179-
git clone https://github.com/Mimickal/ReactionRoleBot.git
180-
cd ReactionRoleBot
181-
npm install
182-
npm run knex migrate:latest
183-
```
184-
185-
Create a file containing your bot token in plain text.
186-
187-
Run this to start the bot: `node main.js path/to/your/config`
135+
[See the guide here](docs/hosting.md).
136+
137+
If you are upgrading from version 1.x, [see the migration guide](
138+
docs/migrate.md).
188139

189140
## License
190141
Copyright 2020 [Mimickal](https://github.com/Mimickal)

docs/hosting.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Hosting your own instance
2+
3+
This bot is built on [discord.js](https://discord.js.org/#/) v13, so you'll need
4+
Node.js 16.6.0 (or newer) installed. You will also need your own Discord bot
5+
account. If your platform does not have Node.js 16.6.0, consider using something
6+
like https://github.com/nvm-sh/nvm.
7+
8+
This guide assumes you're hosting on a Linux distro with `systemd`. The bot will
9+
work on other platforms, but you're on your own figuring that out.
10+
11+
## Running as a user (in dev-mode)
12+
Quick and easy. Also (mostly) platform-independent!
13+
14+
Create a file `config.json` and paste in the following (obviously fill in the
15+
blanks with your bot's info):
16+
```json
17+
{
18+
"token": "<your token here>",
19+
"app_id": "<your bot application ID here>"
20+
}
21+
```
22+
23+
Install dependencies, register Discord slash commands, and set up the database
24+
for your bot:
25+
```
26+
git clone https://github.com/Mimickal/ReactionRoleBot.git
27+
cd ReactionRoleBot
28+
npm ci
29+
npm run register path/to/your/config.json
30+
npm run knex migrate:latest
31+
```
32+
33+
Start the bot:
34+
```
35+
npm start path/to/your/config.json
36+
```
37+
38+
## Running as a service
39+
A little more effort to set up, but better for long-term use.
40+
41+
The provided service file expects to find the bot code at
42+
`/srv/discord/ReactionRoleBot/`, and will want to create the sqlite database at
43+
`/srv/discord/rolebot.sqlite`. The easiest way to do this is to create a
44+
`/srv/discord` directory, and `chown` it so it belongs to the user running the
45+
bot.
46+
47+
Create a file `/etc/discord/ReactionRoleBot/config.json` and paste in the
48+
following (obviously fill in the blanks with your bot's info):
49+
```json
50+
{
51+
"token": "<your token here>",
52+
"app_id": "<your bot application ID here>"
53+
}
54+
```
55+
56+
The following will prepare the bot to run by installing dependencies,
57+
registering slash commands for your Discord bot account, and setting up the
58+
bot's database. Run this from `/srv/discord`:
59+
```
60+
git clone https://github.com/Mimickal/ReactionRoleBot.git
61+
cd ReactionRoleBot
62+
npm ci
63+
npm run register /etc/discord/ReactionRoleBot/config.json
64+
NODE_ENV=prod npm run knex migrate:latest
65+
```
66+
67+
Add your user to `reactionrolebot.service`, then install it into
68+
`/etc/systemd/system/` (just copy the file into that directory). This service
69+
file depends on the above directories, so if you want to change them, you'll
70+
also need to edit those fields. If you are using `nvm`, you may need to tweak
71+
the service file a bit (see comments in provided service file).
72+
73+
Now you should be able to run `systemctl restart reactionrolebot.service` to
74+
start your bot.

docs/migrate.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Migrating your instance to 2.x
2+
3+
This guide is for people who were running their own 1.x instance of the bot.
4+
5+
This bot now runs Discord.js v13, which requires Node.js 16.6.0. On some
6+
platforms (older distros, cloud hosting, etc...) this may be problematic.
7+
Something like https://github.com/nvm-sh/nvm can make the transition easier.
8+
9+
1. Get the updated bot code (either `git pull origin master` if you cloned with
10+
git (which you should) or download `master` as a zip).
11+
1. Make a copy of your old database
12+
- **Running as a service**: probably `/srv/discord/rolebot.sqlite3`
13+
- **Running in dev-mode**: `dev.sqlite3`
14+
1. Replace bot token file with a `config.json` file that looks like this:
15+
```json
16+
{
17+
"token": "<your token here>",
18+
"app_id": "<your bot application ID here>"
19+
}
20+
```
21+
- **Running as a service**: Replace `/etc/discord/ReactionRoleBot/token`
22+
with `/etc/discord/ReactionRoleBot/config.json`
23+
- **Running in dev-mode**: Some local token file
24+
1. Install updated dependencies: `npm ci`
25+
1. Register slash commands: `npm run register path/to/your/config.json`
26+
1. Update your database: `npm run knex migrate:latest`
27+
1. Start the bot
28+
- **Running as a service**: update `reactionrolebot.service` ([see reference
29+
implementation](../resources/reactionrolebot.service)). Restart service
30+
`systemctl restart reactionrolebot.service`.
31+
- **Running in dev-mode**: `npm start path/to/your/config.json`

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"winston": "^3.3.3"
1515
},
1616
"scripts": {
17+
"start": "node .",
1718
"dev": "node . dev-config.json",
1819
"knex": "npx knex --knexfile src/knexfile.js",
1920
"register": "node src/register.js",

resources/post-receive

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NODE_ENV="prod"
1111
mkdir -p $TEMP
1212
/usr/bin/env git --work-tree=$TEMP --git-dir=$REPO checkout -f
1313
cd $TEMP
14-
/usr/bin/env npm install
14+
/usr/bin/env npm ci
1515
NODE_ENV=$NODE_ENV /usr/bin/env npm run knex migrate:latest
1616

1717
# Now install the code

resources/reactionrolebot.service

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Restart=on-failure
1111
RestartSec=10
1212
User=<user>
1313
Environment="NODE_ENV=prod"
14-
ExecStart=/usr/bin/env nodejs /srv/discord/ReactionRoleBot/main.js
14+
ExecStart=/usr/bin/env npm start --prefix /srv/discord/ReactionRoleBot/
15+
# If using nvm, you may need to do something like this instead:
16+
#Environment="NODE_ENV=prod" "NODE_VERSION=<version>"
17+
#ExecStart=<path to nvm-exec> npm start --prefix /srv/discord/ReactionRoleBot
1518

1619
[Install]
1720
WantedBy=multi-user.target

0 commit comments

Comments
 (0)