Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos and formatting in 5. Bot, Meet Redis.md #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions 5. Bot, Meet Redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Okay so, let's say you want an administrative panel (or a rest api) for your bot. What's the best way to access all that information? Having express embedded in my app? No. Don't be silly! Seperate them! That way, your bot can focus on being a bot, and your web project doesn't interfere with any operations.

### What are we going to make?
We're going to use that simple ping-pong bot, and add something called ``discord.js-redis`` to it. We don't want to install a redis server on our operating system, but we would like to keep the data in place. So that way we can transfer it to our hosting platform (not heroku) after we think it's good!
We're going to use that simple ping-pong bot, and add something called `discord.js-redis` to it. We don't want to install a redis server on our operating system, but we would like to keep the data in place. So that way we can transfer it to our hosting platform (not heroku) after we think it's good!

### Re-creating the bot and Dockerfile
First things first, you'll need to install and create the bot again so let's do that now. Let's setup the project, you can modify everything like the ``package.json`` later.
First things first, you'll need to install and create the bot again so let's do that now. Let's setup the project, you can modify everything like the `package.json` later.

```
$ npm init --yes
Expand All @@ -17,7 +17,7 @@ First things first, you'll need to install and create the bot again so let's do

<hr />

Before we hit the bot, I want to discuss something. We created the ``Dockerfile`` in Part 3, that used an image call 'node' from [Docker Hub](https://hub.docker.com/), this time around we're going to go with the ``alpine`` image. The reason is it is smaller and gives you more control of what you want (image manipulation libraries, ffmpeg, etc) in your container, so let's do that now.
Before we hit the bot, I want to discuss something. We created the `Dockerfile` in Part 3, that used an image call `node` from [Docker Hub](https://hub.docker.com/), this time around we're going to go with the `alpine` image. The reason is it is smaller and gives you more control of what you want (image manipulation libraries, ffmpeg, etc.) in your container, so let's do that now.

```Dockerfile
FROM alpine:latest
Expand All @@ -42,7 +42,7 @@ Before we hit the bot, I want to discuss something. We created the ``Dockerfile`

<hr />

The main reason we went this route is for more control as I said, now we will begin modifying and creating a brand new bot with a settings file we touched earlier (``settings.json``)
The main reason we went this route is for more control as I said; now we will begin modifying and creating a brand new bot with a settings file we touched earlier (`settings.json`)

```json
{
Expand All @@ -55,7 +55,7 @@ The main reason we went this route is for more control as I said, now we will be

Now that that's over, let's work on the bot a bit from the example in Part 2. I'll explain what's happening within the code itself as it's easier that way.

In the file ``bot.js``, we're going to go ahead and do this:
In the file `bot.js`, we're going to go ahead and do this:

```js
/**
Expand All @@ -75,8 +75,8 @@ In the file ``bot.js``, we're going to go ahead and do this:

/**
Redis client using discord.js-redis.
When using the constructor for discord.js-redis you can specific options for
node-redis as well (such as amount of databases, host, port, password, etc)
When using the constructor for discord.js-redis you can specify options for
node-redis as well (such as amount of databases, host, port, password, etc.)
*/
const redis = new RedisClient(client, {});

Expand All @@ -103,10 +103,11 @@ In the file ``bot.js``, we're going to go ahead and do this:
client.login(token);
```

Okay so, I know that using ``.startsWith(prefix + command)`` isn't the best, but just go with it for now. :p
Okay so, I know that using `.startsWith(prefix + command)` isn't the best, but just go with it for now. :p

<hr />
Okay, so now that we have that in order, we still need to create the ``docker-compose`` file. I'll explain each step here like I did with the ``Dockerfile`` in Part 3.

Okay, so now that we have that in order, we still need to create the `docker-compose` file. I'll explain each step here like I did with the `Dockerfile` in Part 3.

First, open it (duh.). Once inside you'll notice that it's not JSON or XML, it's YAML. YAML is a basic whitespace markup language (so be mindful of your tabs and spaces). I use version 3, but you might need to use version 2 depending on how you installed docker-compose.

Expand All @@ -128,11 +129,11 @@ Okay, so, what exactly is going on here? We're seperating everything into servic

> ``build: .`` -> This will build our Dockerfile from scratch

> ``restart: always`` -> If something say breaks on the container-level, or something fails, it will restart, always under any circumstance (other options: "no", on-failure, unless-stopped)
> ``restart: always`` -> If something say breaks on the container-level, or something fails, it will restart, always under any circumstance (other options: `no`, `on-failure`, `unless-stopped`)

> ``depends_on:`` -> What our bot will depend and link with, in our case redis.

But Nomsy, we didn't setup redis yet, what's up with that?
But Nomsy, we didn't set up redis yet, what's up with that?
Okay yeah, we haven't. So let's do that now taking the ``docker-compose.yml`` file we have just created:

```yml
Expand All @@ -147,7 +148,7 @@ Okay yeah, we haven't. So let's do that now taking the ``docker-compose.yml`` fi
image: redis:3.0-alpine
```

Yup, that's it. You can setup and use environmental variables and even where storage goes as well. You can see more here: [Compose-file Manual](https://docs.docker.com/compose/compose-file/)
Yup, that's it. You can set up and use environmental variables and even where storage goes as well. You can see more here: [Compose-file Manual](https://docs.docker.com/compose/compose-file/)

### Build, run.
Now that we have done all of this work to sandbox our bot with it's own database, let's give it a shot!
Expand All @@ -161,6 +162,6 @@ You'll notice that you'll be instantly teleported into an installer, then the in

That's it! I'll provide more information and add more to the guide at a later date. If you need me I'm on various servers around the net, just ping me (Nomsy).

> AUTHORS NOTE: Will add environmental variable setups instead of a configuration file as it's easier to maintain and change and it _just works_. Will also add PostgreSQL and a rest server setup using this setup in a later tutorial. Will also add modifying and viewing to the redis db to the bot in the future. STAY TUNED!
> AUTHORS NOTE: Will add environmental variable setup instead of a configuration file as it's easier to maintain and change and it _just works_. Will also add PostgreSQL and a rest server setup using this setup in a later tutorial. Will also add modifying and viewing the redis db in the future. STAY TUNED!

Thanks for reading! See ya soon!